Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
xTibor opened this issue Jan 1, 2022 · 1 comment · Fixed by #92507
Closed

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

xTibor opened this issue Jan 1, 2022 · 1 comment · Fixed by #92507
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@xTibor
Copy link
Contributor

xTibor commented Jan 1, 2022

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.)

@xTibor xTibor added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 1, 2022
@chordtoll
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants