Skip to content

Incorrectly printed generic in pattern matching error suggestion #30302

Closed
@brson

Description

@brson

Code:

enum Stack<T> {
    Nil,
    Cons(T, Box<Stack<T>>)
}

fn isEmpty<T>(s: Stack<T>) -> bool {
    match s {
        Nil => true,
        _   => false,
    }    
}

Error:

src/lib.rs:10:9: 10:12 warning: pattern binding Nil is named the same as one of the variants of the type Stack<T> [E0170]
src/lib.rs:10 Nil => true,
^~~
src/lib.rs:10:9: 10:12 help: run rustc --explain E0170 to see a detailed explanation
src/lib.rs:10:9: 10:12 help: if you meant to match on a variant, consider making the path in the pattern qualified: Stack<T>::Nil
src/lib.rs:11:9: 11:10 error: unreachable pattern [E0001]
src/lib.rs:11 _ => false,

This suggests pattern matching on Stack<T>::Nil, but that is not the correct syntax. It should be Stack::Nil or Stack::Nil::<T>.

Original thread

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions