Skip to content

Multiple-character char literal error should mention non-printing characters #90857

New issue

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

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

Already on GitHub? # to your account

Closed
5225225 opened this issue Nov 13, 2021 · 1 comment · Fixed by #90861
Closed

Multiple-character char literal error should mention non-printing characters #90857

5225225 opened this issue Nov 13, 2021 · 1 comment · Fixed by #90861
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-Unicode Area: Unicode

Comments

@5225225
Copy link
Contributor

5225225 commented Nov 13, 2021

Given the following code:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1896e58442e271fd3b78e60396ffebc1

fn main() {
    let x = vec!['<​'];
    println!("{:?}", x);
}

(which has a zero width space between the < and its ending ')

The current output is:

error: character literal may only contain one codepoint
 --> src/main.rs:2:18
  |
2 |     let x = vec!['<​'];
  |                  ^^^
  |
help: if you meant to write a `str` literal, use double quotes
  |
2 |     let x = vec!["<​"];
  |                  ~~~ 

If there are any non-printing characters, show where they are (debug unicode representation on the whole string, maybe?), and if there's only one printing character, make a suggestion to remove everything but the printing character.

@5225225
Copy link
Contributor Author

5225225 commented Nov 13, 2021

@rustbot claim

@workingjubilee workingjubilee added A-diagnostics Area: Messages for errors, warnings, and lints A-Unicode Area: Unicode labels Nov 14, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 15, 2021
Print escaped string if char literal has multiple characters, but only one printable character

Fixes rust-lang#90857

I'm not sure about the error message here, it could get rather long and *maybe* using the names of characters would be better? That wouldn't help the length any, though.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 15, 2021
Print escaped string if char literal has multiple characters, but only one printable character

Fixes rust-lang#90857

I'm not sure about the error message here, it could get rather long and *maybe* using the names of characters would be better? That wouldn't help the length any, though.
JohnTitor added a commit to JohnTitor/rust that referenced this issue Nov 16, 2021
Print escaped string if char literal has multiple characters, but only one printable character

Fixes rust-lang#90857

I'm not sure about the error message here, it could get rather long and *maybe* using the names of characters would be better? That wouldn't help the length any, though.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 16, 2021
Print escaped string if char literal has multiple characters, but only one printable character

Fixes rust-lang#90857

I'm not sure about the error message here, it could get rather long and *maybe* using the names of characters would be better? That wouldn't help the length any, though.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 16, 2021
Print escaped string if char literal has multiple characters, but only one printable character

Fixes rust-lang#90857

I'm not sure about the error message here, it could get rather long and *maybe* using the names of characters would be better? That wouldn't help the length any, though.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 16, 2021
Print escaped string if char literal has multiple characters, but only one printable character

Fixes rust-lang#90857

I'm not sure about the error message here, it could get rather long and *maybe* using the names of characters would be better? That wouldn't help the length any, though.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 16, 2021
Print escaped string if char literal has multiple characters, but only one printable character

Fixes rust-lang#90857

I'm not sure about the error message here, it could get rather long and *maybe* using the names of characters would be better? That wouldn't help the length any, though.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 17, 2021
Print escaped string if char literal has multiple characters, but only one printable character

Fixes rust-lang#90857

I'm not sure about the error message here, it could get rather long and *maybe* using the names of characters would be better? That wouldn't help the length any, though.
@bors bors closed this as completed in ab958a7 Nov 17, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-Unicode Area: Unicode
Projects
None yet
2 participants