Skip to content

unhelpful "expected item" error when putting let binding outside of function #61764

Open
@matthiaskrgr

Description

@matthiaskrgr
let s = String::new();

fn main()  {
    println!("Hello world");
}
   Compiling playground v0.0.1 (/playground)
error: expected item, found keyword `let`
 --> src/main.rs:1:1
  |
1 | let s = String::new();
  | ^^^ expected item

Could we have some suggestions what kind of item should be put there? :)
Also there seems to be no error code which is strange..

rustc 1.37.0-nightly (02564de47 2019-06-10)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTC-enhancementCategory: An issue proposing an enhancement or a PR with one.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