Skip to content

Poor error when using single quotes with println! #26101

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

Closed
steveklabnik opened this issue Jun 8, 2015 · 4 comments
Closed

Poor error when using single quotes with println! #26101

steveklabnik opened this issue Jun 8, 2015 · 4 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-diagnostics Working group: Diagnostics

Comments

@steveklabnik
Copy link
Member

fn main() {
    println!('{}', 5);
}

This error leaves much to be desired:

hello.rs:2:14: 2:16 error: unterminated character constant: '{
hello.rs:2     println!('{}', 5);
                        ^~

The issue is that you need double quotes.

originally found in http://joelmccracken.github.io/entries/a-simple-web-app-in-rust-pt-2b/ /cc @joelmccracken

@steveklabnik steveklabnik added the A-diagnostics Area: Messages for errors, warnings, and lints label Jun 8, 2015
@bstrie
Copy link
Contributor

bstrie commented Jun 9, 2015

Consider changing the title, because this isn't println-specific. The following code exhibits the same error message:

fn main() {
    'abc';
}

@joelmccracken
Copy link

I was wondering about this -- I assumed this is a string thing. The way it is worded made me think that it was caused by some fancy println macroings.

@birkenfeld
Copy link
Contributor

The current error is error: character literal may only contain one codepoint: '{

@steveklabnik steveklabnik added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@Mark-Simulacrum
Copy link
Member

Looking at the code, there doesn't appear to be a current way to add a help message to this diagnostic, though adding one shouldn't be too hard. Could someone familiar with the parser, perhaps @jseyfried or @nrc, type up a quick mentoring summary for adding a help: Maybe use double quotes (") instead of single quotes (')? It looks like ultimately self.sess.span_diagnostic.struct_span_fatal needs to be called with the appropriate parameters.

@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 22, 2017
@estebank estebank added E-needs-mentor WG-diagnostics Working group: Diagnostics labels Nov 29, 2017
bors added a commit that referenced this issue Dec 15, 2017
When attempting to write str with single quote suggest double quotes

Fix #26101.
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 C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-diagnostics Working group: Diagnostics
Projects
None yet
Development

No branches or pull requests

6 participants