Skip to content

Bad suggestion for _ in associated const #82158

Closed
@estebank

Description

@estebank

As noted in #81914, given the following:

fn main() {}
struct MyStruct;

trait Test {
}

impl Test for MyStruct {
    const TEST: fn() -> _ = 42; 
}

we emit

error[E0438]: const `TEST` is not a member of trait `Test`
  --> main_test.rs:10:5
   |
10 |     const TEST: fn() -> _ = 42; 
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a member of trait `Test`

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
  --> main_test.rs:10:25
   |
10 |     const TEST: fn() -> _ = 42; 
   |                         ^
   |                         |
   |                         not allowed in type signatures
   |                         help: use type parameters instead: `T`

Follow up to #81885.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.D-papercutDiagnostics: An error or lint that needs small tweaks.P-lowLow priorityT-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