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

Existence of trait alias breaks name resolution of associated consts #72415

Closed
matthew-mcallister opened this issue May 21, 2020 · 1 comment · Fixed by #72556
Closed

Existence of trait alias breaks name resolution of associated consts #72415

matthew-mcallister opened this issue May 21, 2020 · 1 comment · Fixed by #72556
Labels
A-associated-items Area: Associated items (types, constants & functions) C-bug Category: This is a bug. F-trait_alias `#![feature(trait_alias)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthew-mcallister
Copy link
Contributor

matthew-mcallister commented May 21, 2020

On 1.45.0-nightly (a74d1862d 2020-05-14), this trait definition/impl works fine:

trait Bounded { const MAX: Self; }

impl Bounded for u32 {
    const MAX: Self = u32::MAX;
}

Here, u32::MAX resolves unambiguously to the associated const on u32.

If I merely define a trait alias that uses Bounded:

#![feature(trait_alias)]

trait Bounded { const MAX: Self; }

impl Bounded for u32 {
    const MAX: Self = u32::MAX;
}

trait Num = Bounded + Copy;

I get this error:

error[E0034]: multiple applicable items in scope
 --> src/lib.rs:6:28
  |
6 |     const MAX: Self = u32::MAX;
  |                       -----^^^
  |                       |    |
  |                       |    multiple `MAX` found
  |                       help: disambiguate the associated constant for candidate #1: `Bounded::MAX`
  |
note: candidate #1 is defined in an impl of the trait `Bounded` for the type `u32`
 --> src/lib.rs:6:5
  |
6 |     const MAX: Self = u32::MAX;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: candidate #2 is defined in an impl for the type `u32`
@matthew-mcallister matthew-mcallister added the C-bug Category: This is a bug. label May 21, 2020
@jonas-schievink jonas-schievink added A-associated-items Area: Associated items (types, constants & functions) F-trait_alias `#![feature(trait_alias)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 21, 2020
@matthew-mcallister
Copy link
Contributor Author

Looks related to #60021.

matthew-mcallister added a commit to matthew-mcallister/rust that referenced this issue May 25, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Jun 13, 2020
…rent-impl, r=estebank

Fix trait alias inherent impl resolution

Fixes rust-lang#60021 and fixes rust-lang#72415.

Obviously, the fix was very easy, but getting started with the testing and debugging rust compiler was an interesting experience. Now I can cross it off my bucket list!
RalfJung added a commit to RalfJung/rust that referenced this issue Jun 15, 2020
…rent-impl, r=estebank

Fix trait alias inherent impl resolution

Fixes rust-lang#60021 and fixes rust-lang#72415.

Obviously, the fix was very easy, but getting started with the testing and debugging rust compiler was an interesting experience. Now I can cross it off my bucket list!
@bors bors closed this as completed in 3d41252 Jun 15, 2020
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) C-bug Category: This is a bug. F-trait_alias `#![feature(trait_alias)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler 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