Skip to content

Unclear error message on trailing semicolon in assignment block #44173

Closed
@zmanian

Description

@zmanian

Consider this case

fn main() {

    let x = {
        println!("foo");
        "bar";
    };
    println!("{}",x)
}

this results in the type checking error.

error[E0277]: the trait bound `(): std::fmt::Display` is not satisfied
 --> src/main.rs:8:19
  |
8 |     println!("{}",x)
  |                   ^ `()` cannot be formatted with the default formatter; try using `:?` instead if you are using a format string
  |
  = help: the trait `std::fmt::Display` is not implemented for `()`
  = note: required by `std::fmt::Display::fmt`

when the actual error is the trailing semicolon in "bar";

This is similar to #30497 but that handles the case of a function type signature not an assignment.

@Manishearth mentioned it might be easiest to introduce a lint. Looking for mentorship on contributing a fix.

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.D-confusingDiagnostics: Confusing error or lint that should be reworked.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.T-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