Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Trait alias makes method call ambigous #60021

Closed

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<_>`

Activity

  1. added
    A-trait-system
    C-bug
    T-compiler
    on Apr 16, 2019
  2. jonas-schievink commented on Apr 16, 2019

    @jonas-schievink
    Contributor
  3. Centril commented on Apr 16, 2019

    @Centril
    Contributor

    cc @seanmonstar, @alexreg, and @petrochenkov -- Is trait SomeAlias = SomeTrait; importing the trait with higher priority than inherent items?

  4. petrochenkov commented on Apr 16, 2019

    @petrochenkov
    Contributor

    Is trait SomeAlias = SomeTrait; importing the trait with higher priority than inherent items?

    It shouldn't do that, looks like a bug.
    A method introduced into scope via trait alias (import) should behave identically to methods introduced with a trait (import), that means lower priority than inherent items.

  5. added a commit that references this issue on May 25, 2020
    98eb29c
  6. added a commit that references this issue on Jun 13, 2020
    398a645
  7. added 2 commits that reference this issue on Jun 15, 2020
    b220894
    3d41252
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-trait-systemC-bugT-compiler

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions