suggest using raw string literals when invalid escapes appear
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.
This commit is contained in:
parent
52dd59ed21
commit
e59cda9ee1
4 changed files with 38 additions and 0 deletions
|
@ -185,6 +185,15 @@ pub(crate) fn emit_unescape_error(
|
|||
version control settings",
|
||||
);
|
||||
} else {
|
||||
if !mode.is_bytes() {
|
||||
diag.span_suggestion(
|
||||
span_with_quotes,
|
||||
"if you meant to write a literal backslash (perhaps escaping in a regular expression), consider a raw string literal",
|
||||
format!("r\"{}\"", lit),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
|
||||
diag.help(
|
||||
"for more information, visit \
|
||||
<https://static.rust-lang.org/doc/master/reference.html#literals>",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue