Skip to content

Added a hint for wrong escaping of curly braces in format strings. #24295

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

Merged
merged 1 commit into from
Apr 14, 2015
Merged

Added a hint for wrong escaping of curly braces in format strings. #24295

merged 1 commit into from
Apr 14, 2015

Conversation

contradictioned
Copy link
Contributor

As i proposed in #24262 (and found acceptance in the IRC channel), added a compiler warning for wrong escaping of curly braces.

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see CONTRIBUTING.md for more information.

@alexcrichton
Copy link
Member

Unfortunately this may not be the best place for this error. For example I think that this will trigger the error message as well:

let foo = "\{";

@alexcrichton
Copy link
Member

Er sorry, posted too soon! Perhaps this could issue a span_help after the normal span_err is emitted? It may also want to mention something along the lines of "if you're in a formatting string, use ..."

@contradictioned
Copy link
Contributor Author

@alexcrichton thanks, I will look into this tomorrow!

@contradictioned
Copy link
Contributor Author

When you forget to put a self before an attribute attr in a method, the compiler gives the following warning:

unresolved name `attr`. Did you mean `self.attr`?

So the information is all in one error. I wanted to emulate this behaviour. I have followed your suggestion and added a span_help, such that the compiler output looks like:

msg_test.rs:12:21: 12:22 error: unknown character escape
msg_test.rs:12   let foo = "hello \{";
                                   ^
msg_test.rs:12:21: 12:22 help: If used in a formatting string, curly braces are escaped with '{{' and '}}'.
msg_test.rs:12   let foo = "hello \{";
                                   ^

(PS: this also confirms that this can also happen in a non-format string :))

@rprichard
Copy link
Contributor

Oh sorry, I didn't read your comment very closely.

@contradictioned
Copy link
Contributor Author

I did the changes suggested by @rprichard, thanks for those!

@alexcrichton
Copy link
Member

Thanks! Could you squash the commits together and add a test as well?

…braces in a format string if a wrongly escaped one is detected in a string.
@contradictioned
Copy link
Contributor Author

Sorry for the confusion-if any-but I somewhat destroyed my git history whilst trying to squash, and then Github automatically closed the pr. Sorry for your lost comments @rprichard.

I have added the test, and put it together with the changes into one commit.

@alexcrichton
Copy link
Member

@bors: r+ 4abade5

Thanks!

@bors
Copy link
Collaborator

bors commented Apr 14, 2015

⌛ Testing commit 4abade5 with merge a4eb5a6...

bors added a commit that referenced this pull request Apr 14, 2015
As i proposed in #24262 (and found acceptance in the IRC channel), added a compiler warning for wrong escaping of curly braces.
@bors
Copy link
Collaborator

bors commented Apr 14, 2015

@bors bors merged commit 4abade5 into rust-lang:master Apr 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants