Skip to content

Suggest using single quotes when confusing single character strings and chars #92479

Closed
@xTibor

Description

@xTibor

Consider the following example:

fn main() {
    // mismatched types expected `char`, found `&str` rustc(E0308)
    let my_character: char = "s";
}

The compiler could be more friendly in this case, having a diagnostic for suggesting using single quotes when people confuse single character strings with char literals. Something like this:

note: character literals are delimited by single quotes 
--> main.rs:3:4
  |
3 | let my_character: char = 's';
  |                          ---
  |                          |
  |                          use single quotes here 

This could help new Rust devs coming from languages where there are no distinction between these things. (Python, Javascript, etc.)

Metadata

Metadata

Assignees

Labels

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