Skip to content

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

Closed
@matthew-mcallister

Description

@matthew-mcallister

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`

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)C-bugCategory: This is a bug.F-trait_alias`#![feature(trait_alias)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions