Skip to content

Diagnostics could be more helpful when confusing character and string literals #119685

Closed
@Wilfred

Description

@Wilfred

Code

fn main() {
    println!('hello world');
}

Current output

error: prefix `world` is unknown
 --> src/main.rs:4:21
  |
4 |     println!('hello world');
  |                     ^^^^^ unknown prefix
  |
  = note: prefixed identifiers and literals are reserved since Rust 2021
help: consider inserting whitespace here
  |
4 |     println!('hello world ');
  |                          +

error[E0762]: unterminated character literal
 --> src/main.rs:4:26
  |
4 |     println!('hello world');
  |                          ^^^

Desired output

error: format argument must be a string literal
 --> src/main.rs:2:14
  |
4 |     println!('hello world');
  |              ^^^^^^^^^^^^^
  |
help: you might have intended a string literal
  |
4 |     println!("hello world");
  |              +++++++++++++

Rationale and extra context

No response

Other cases

No response

Anything else?

No response

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-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