Skip to content

wfcheck incorrectly assumes unnormalized types to be wf #100910

@lcnr

Description

@lcnr
Contributor
struct Foo<T>(T);

trait GoodBye {
    type Forget;
}
impl<T> GoodBye for T {
    type Forget = ();
}

trait NeedsWf<'a, 'b> {
    type Assoc;
}

impl<'a, 'b> NeedsWf<'a, 'b> for Foo<<&'a &'b () as GoodBye>::Forget> {
    type Assoc = &'a &'b ();
}

fn main() {}

this compiles with #100676 because we now assume unnormalized types in the impl header to be well formed when computing implied bounds. We don't check that when using the impl so we should be able to transmute lifetimes with this, though I haven't tried that yet.

Going to fix that myself once I am back home in 2 weeks. cc @rust-lang/types

Activity

added
I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
C-bugCategory: This is a bug.
T-typesRelevant to the types team, which will review and decide on the PR/issue.
on Aug 23, 2022
self-assigned this
on Aug 23, 2022
added
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
and removed
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Aug 23, 2022
lcnr

lcnr commented on Aug 23, 2022

@lcnr
ContributorAuthor
pnkfelix

pnkfelix commented on Aug 24, 2022

@pnkfelix
Member

(FYI I also nominated PR #100676 for discussion at T-compiler meeting, essentially because of this associated issue; I hadn't seen that this was tagged as P-critical at that time. I'm leaving it nominated for now, just to ensure doubly that we discuss the matter.)

lcnr

lcnr commented on Aug 25, 2022

@lcnr
ContributorAuthor

this is an existing issue on stable if we prevent the projection from normalizing in the impl while normalizing it when using the impl:

struct Foo<T>(T);

trait GoodBye {
    type Forget;
}
impl<T> GoodBye for T {
    type Forget = ();
}

trait NeedsWf<'a, 'b> {
    type Assoc;
}

impl<'a, 'b> NeedsWf<'a, 'b> for Foo<<&'a &'b () as GoodBye>::Forget>
where
    &'a &'b (): GoodBye, // this line prevents us from normalizing in the param env.
{
    type Assoc = &'a &'b ();
}

fn needs_wf<'a, 'b, T: NeedsWf<'a, 'b>>() {}

fn foo<'a: 'a, 'b: 'b>(_: &'b String) {
    needs_wf::<'a, 'b, Foo<()>>();
}

fn main() {
    let x = String::from("hello");
    foo::<'static, '_>(&x);
}

that's the same issue as #98543, which has been only fixed for function signatures

edit: that's #100051

added a commit that references this issue on Aug 27, 2022
3b3f3b7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-criticalCritical priorityT-typesRelevant to the types team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @pnkfelix@lcnr

    Issue actions

      wfcheck incorrectly assumes unnormalized types to be wf · Issue #100910 · rust-lang/rust