Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implied bounds from impl header are not used when comparing trait and impl methods #105495

Open
aliemjay opened this issue Dec 9, 2022 · 2 comments
Labels
A-associated-items Area: Associated items (types, constants & functions) A-implied-bounds Area: Implied bounds / inferred outlives-bounds C-bug Category: This is a bug. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@aliemjay
Copy link
Member

aliemjay commented Dec 9, 2022

This doesn't compile:

trait Trait {
    fn get();
}
impl<'a, 'b> Trait for &'a &'b () { // There is an implied bound 'b: 'a
    fn get() where 'b: 'a, {}
    //~^ ERROR impl has stricter requirements than trait
}

Although it should for the same reason it compiles with the following change:

- impl<'a, 'b> Trait for &'a &'b () {
+ impl<'a, 'b> Trait for &'a &'b () where 'b: 'a, {

There should be no difference in behavior between implied and explicit bounds on impl header.

This is because we're not adding sufficient implied bounds in compare_predicate_entailment() here:

let mut wf_tys = FxIndexSet::default();

@rustbot label T-types A-implied-bounds A-associated-items C-bug

@rustbot rustbot added A-associated-items Area: Associated items (types, constants & functions) A-implied-bounds Area: Implied bounds / inferred outlives-bounds C-bug Category: This is a bug. T-types Relevant to the types team, which will review and decide on the PR/issue. labels Dec 9, 2022
@aliemjay
Copy link
Member Author

aliemjay commented Dec 9, 2022

This should be fixed for associated types as well:

trait Trait {
    type Ty;
}
impl<'a, 'b> Trait for &'a &'b () {
    type Ty = () where 'b: 'a;
}

@aliemjay
Copy link
Member Author

another test case:

trait Trait {
    type Assoc;
    fn test(_: ());
}

impl<'a, T> Trait for &'a T {
    type Assoc = ();
    fn test(_: Self::Assoc) {}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-implied-bounds Area: Implied bounds / inferred outlives-bounds C-bug Category: This is a bug. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants