Skip to content

On places that pub would be "reasonable" but incorrect, provide better errors #56473

Closed
@estebank

Description

@estebank

When trying to incorrectly specify a pub fn in a trait, the error message just complains about the incorrect token:

trait T {
    pub fn foo(&self);
}

Ideally the compiler would explain that individual trait methods' visibility can't be modified, only the trait itself, and continue parsing the AST as if it were correct, possibly suggesting the following, if appropriate:

pub trait T {
    fn foo(&self);
}

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