Skip to content

Trait alias makes method call ambigous #60021

Closed
@athre0z

Description

@athre0z

When a trait alias to a trait with a method with the same name as a method on a struct is in scope, rustc is suddenly unable to disambiguate the trait method from the struct method.

Playground link

#![feature(trait_alias)]

trait SomeTrait {
    fn map(&self) {}
}

impl<T> SomeTrait for Option<T> {}

trait SomeAlias = SomeTrait; // comment this out and everything works

fn main() {
    let x = Some(123);
    Option::map(x, |z| z);  // Error: multiple `map` found

    let x = Some(123);
    x.map(|z| z);  // Fine, no error.
}
error[E0034]: multiple applicable items in scope
  --> src/main.rs:13:5
   |
13 |     Option::map(x, |z| z);  // Error: multiple `map` found
   |     ^^^^^^^^^^^ multiple `map` found
   |
note: candidate #1 is defined in an impl of the trait `SomeTrait` for the type `std::option::Option<_>`
  --> src/main.rs:4:5
   |
4  |     fn map(&self) {}
   |     ^^^^^^^^^^^^^
   = note: candidate #2 is defined in an impl for the type `std::option::Option<_>`

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemC-bugCategory: This is a bug.T-compilerRelevant to the compiler 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