Skip to content

inherent method selection uses subtyping even when using paths #126227

Closed

Description

@lcnr
struct B<T>(T);

impl B<fn(&'static ())> {
    fn method(self) {
        println!("hey");
    }
}

fn foo(x: B<for<'a> fn(&'a ())>) {
    x.method(); // ok, method call
    B::<for<'a> fn(&'a ())>::method(x); // ok, explicit path
}

fn main() {
   
}

I would like us to change method selection for associated items to use equality. It feels very wrong to completely ignore the user type annotation here:

struct B<T>(T);

impl B<fn(&'static ())> {
    fn method(self) {
        println!("hey");
    }
}

fn foo(y: B<fn(&'static ())>) {
    // looks like it requires a hr fn pointer,
    // but we never check that.
    B::<for<'a> fn(&'a ())>::method(y);
}

fn main() {}

cc #126128 @compiler-errors @oli-obk

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jun 10, 2024
  2. added
    A-resolveArea: Name/path resolution done by `rustc_resolve` specifically
    T-typesRelevant to the types team, which will review and decide on the PR/issue.
    and removed
    A-resolveArea: Name/path resolution done by `rustc_resolve` specifically
    on Jun 10, 2024
  3. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jul 4, 2024
  4. added a commit that references this issue on Aug 14, 2024
    774bd5b
  5. added a commit that references this issue on Sep 17, 2024
    1f1beb6
  6. added a commit that references this issue on Sep 17, 2024
    e9e13a6
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

    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