Skip to content

Poor error message for variant value being used as type. #17546

Closed
@Ryman

Description

@Ryman

Couldn't find another issue for this.

use self::MyEnum::*;

enum MyEnum {
    Result,
    NoResult
}

fn new() -> Result<MyEnum, String> {
    unimplemented!()
}

fn main() {
    let _ = new();
}

The error message for this is poor and should suggest qualifying the type, or at least clearly saying that a value from MyEnum cannot be used as a type, and the span should then help the user understand (it is currently fine):

<anon>:6:13: 6:35 error: found value name used as a type: DefVariant(syntax::ast::DefId{krate: 0u32, node: 4u32}, syntax::ast::DefId{krate: 0u32, node: 5u32}, false)
<anon>:6 fn new() -> Result<MyEnum, String> {
                     ^~~~~~~~~~~~~~~~~~~~~~

Error message comes from astconv, so we could probably catch this in resolve?

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