Skip to content

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

Description

@aliemjay

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

Activity

  1. added
    A-associated-itemsArea: Associated items (types, constants & functions)
    A-implied-boundsArea: Implied bounds / inferred outlives-bounds
    C-bugCategory: This is a bug.
    T-typesRelevant to the types team, which will review and decide on the PR/issue.
    on Dec 9, 2022
  2. aliemjay commented on Dec 9, 2022

    @aliemjay
    ContributorAuthor

    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;
    }
  3. aliemjay commented on Mar 19, 2023

    @aliemjay
    ContributorAuthor

    another test case:

    trait Trait {
        type Assoc;
        fn test(_: ());
    }
    
    impl<'a, T> Trait for &'a T {
        type Assoc = ();
        fn test(_: Self::Assoc) {}
    }
  4. fmease commented on Dec 29, 2024

    @fmease
    Member

    CC related (?): #89236 (but: inherent impl, not trait impl; wf'ck'ing (?) array repeat exprs, not compare_impl_item).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-implied-boundsArea: Implied bounds / inferred outlives-boundsC-bugCategory: This is a bug.T-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions