-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #93999 - barzamin:suggest-raw-strings, r=jackh726
suggest using raw strings when invalid escapes appear in literals i'd guess about 70% of "bad escape" cases occur when someone meant to use a raw string literal because they're passing it directly to `Regex::new()`. this emits an advisory (`Applicability::MaybeIncorrect`) `help:` suggestion to the user that they use an `r""` string, on top of the normal notes about looking at the string literal documentation/spec.
- Loading branch information
Showing
4 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
fn main() { | ||
let ok = r"ab\[c"; | ||
let bad = "ab\[c"; | ||
//~^ ERROR unknown character escape: `[` | ||
//~| HELP for more information, visit <https://static.rust-lang.org/doc/master/reference.html#literals> | ||
//~| HELP if you meant to write a literal backslash (perhaps escaping in a regular expression), consider a raw string literal | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error: unknown character escape: `[` | ||
--> $DIR/bad-escape-suggest-raw-string.rs:3:19 | ||
| | ||
LL | let bad = "ab\[c"; | ||
| ^ unknown character escape | ||
| | ||
= help: for more information, visit <https://static.rust-lang.org/doc/master/reference.html#literals> | ||
help: if you meant to write a literal backslash (perhaps escaping in a regular expression), consider a raw string literal | ||
| | ||
LL | let bad = r"ab\[c"; | ||
| ~~~~~~~~ | ||
|
||
error: aborting due to previous error | ||
|