Skip to content

Bad error message using associated type #45447

Closed
@leonardo-m

Description

@leonardo-m

I think this code shows a bad error message:

trait Foo { const FOO: Self; }
impl Foo for u32 { const FOO: Self = 1; }
fn bar<T: Foo>(n: T) {
    const BASE: T = T::FOO;
}
fn main() {}

rustc 1.22.0-nightly (4279e2b 2017-10-21) gives:

error[E0401]: can't use type parameters from outer function; try using a local type parameter instead
 --> ...\test.rs:4:17
  |
4 |     const BASE: T = T::FOO;
  |                 ^ use of type variable from outer function

error[E0401]: can't use type parameters from outer function; try using a local type parameter instead
 --> ...\test.rs:4:21
  |
4 |     const BASE: T = T::FOO;
  |                     ^^^^^^ use of type variable from outer function

error: aborting due to 2 previous errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.WG-diagnosticsWorking group: Diagnostics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions