Tweak incorrect escaped char diagnostic
This commit is contained in:
parent
7cf074a1e6
commit
a8120d660a
10 changed files with 51 additions and 72 deletions
|
@ -968,9 +968,10 @@ impl<'a> StringReader<'a> {
|
||||||
} else {
|
} else {
|
||||||
let span = self.mk_sp(start, self.pos);
|
let span = self.mk_sp(start, self.pos);
|
||||||
let mut suggestion = "\\u{".to_owned();
|
let mut suggestion = "\\u{".to_owned();
|
||||||
|
let msg = "incorrect unicode escape sequence";
|
||||||
let mut err = self.sess.span_diagnostic.struct_span_err(
|
let mut err = self.sess.span_diagnostic.struct_span_err(
|
||||||
span,
|
span,
|
||||||
"incorrect unicode escape sequence",
|
msg,
|
||||||
);
|
);
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
while let (Some(ch), true) = (self.ch, i < 6) {
|
while let (Some(ch), true) = (self.ch, i < 6) {
|
||||||
|
@ -991,8 +992,8 @@ impl<'a> StringReader<'a> {
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
err.span_help(
|
err.span_label(span, msg);
|
||||||
span,
|
err.help(
|
||||||
"format of unicode escape sequences is `\\u{...}`",
|
"format of unicode escape sequences is `\\u{...}`",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1018,25 +1019,24 @@ impl<'a> StringReader<'a> {
|
||||||
}
|
}
|
||||||
c => {
|
c => {
|
||||||
let pos = self.pos;
|
let pos = self.pos;
|
||||||
let mut err = self.struct_err_span_char(escaped_pos,
|
let msg = if ascii_only {
|
||||||
pos,
|
"unknown byte escape"
|
||||||
if ascii_only {
|
} else {
|
||||||
"unknown byte escape"
|
"unknown character escape"
|
||||||
} else {
|
};
|
||||||
"unknown character \
|
let mut err = self.struct_err_span_char(escaped_pos, pos, msg, c);
|
||||||
escape"
|
err.span_label(self.mk_sp(escaped_pos, pos), msg);
|
||||||
},
|
|
||||||
c);
|
|
||||||
if e == '\r' {
|
if e == '\r' {
|
||||||
err.span_help(self.mk_sp(escaped_pos, pos),
|
err.help(
|
||||||
"this is an isolated carriage return; consider \
|
"this is an isolated carriage return; consider checking \
|
||||||
checking your editor and version control \
|
your editor and version control settings",
|
||||||
settings");
|
);
|
||||||
}
|
}
|
||||||
if (e == '{' || e == '}') && !ascii_only {
|
if (e == '{' || e == '}') && !ascii_only {
|
||||||
err.span_help(self.mk_sp(escaped_pos, pos),
|
err.help(
|
||||||
"if used in a formatting string, curly braces \
|
"if used in a formatting string, curly braces are escaped \
|
||||||
are escaped with `{{` and `}}`");
|
with `{{` and `}}`",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
err.emit();
|
err.emit();
|
||||||
false
|
false
|
||||||
|
|
|
@ -4229,19 +4229,24 @@ impl<'a> Parser<'a> {
|
||||||
fn parse_pat_list(&mut self) -> PResult<'a, (Vec<P<Pat>>, Option<usize>, bool)> {
|
fn parse_pat_list(&mut self) -> PResult<'a, (Vec<P<Pat>>, Option<usize>, bool)> {
|
||||||
let mut fields = Vec::new();
|
let mut fields = Vec::new();
|
||||||
let mut ddpos = None;
|
let mut ddpos = None;
|
||||||
|
let mut prev_dd_sp = None;
|
||||||
let mut trailing_comma = false;
|
let mut trailing_comma = false;
|
||||||
loop {
|
loop {
|
||||||
if self.eat(&token::DotDot) {
|
if self.eat(&token::DotDot) {
|
||||||
if ddpos.is_none() {
|
if ddpos.is_none() {
|
||||||
ddpos = Some(fields.len());
|
ddpos = Some(fields.len());
|
||||||
|
prev_dd_sp = Some(self.prev_span);
|
||||||
} else {
|
} else {
|
||||||
// Emit a friendly error, ignore `..` and continue parsing
|
// Emit a friendly error, ignore `..` and continue parsing
|
||||||
self.struct_span_err(
|
let mut err = self.struct_span_err(
|
||||||
self.prev_span,
|
self.prev_span,
|
||||||
"`..` can only be used once per tuple or tuple struct pattern",
|
"`..` can only be used once per tuple or tuple struct pattern",
|
||||||
)
|
);
|
||||||
.span_label(self.prev_span, "can only be used once per pattern")
|
err.span_label(self.prev_span, "can only be used once per pattern");
|
||||||
.emit();
|
if let Some(sp) = prev_dd_sp {
|
||||||
|
err.span_label(sp, "previously present here");
|
||||||
|
}
|
||||||
|
err.emit();
|
||||||
}
|
}
|
||||||
} else if !self.check(&token::CloseDelim(token::Paren)) {
|
} else if !self.check(&token::CloseDelim(token::Paren)) {
|
||||||
fields.push(self.parse_pat(None)?);
|
fields.push(self.parse_pat(None)?);
|
||||||
|
|
|
@ -2,13 +2,13 @@ error: unknown byte escape: f
|
||||||
--> $DIR/byte-literals.rs:6:21
|
--> $DIR/byte-literals.rs:6:21
|
||||||
|
|
|
|
||||||
LL | static FOO: u8 = b'/f';
|
LL | static FOO: u8 = b'/f';
|
||||||
| ^
|
| ^ unknown byte escape
|
||||||
|
|
||||||
error: unknown byte escape: f
|
error: unknown byte escape: f
|
||||||
--> $DIR/byte-literals.rs:9:8
|
--> $DIR/byte-literals.rs:9:8
|
||||||
|
|
|
|
||||||
LL | b'/f';
|
LL | b'/f';
|
||||||
| ^
|
| ^ unknown byte escape
|
||||||
|
|
||||||
error: invalid character in numeric character escape: Z
|
error: invalid character in numeric character escape: Z
|
||||||
--> $DIR/byte-literals.rs:10:10
|
--> $DIR/byte-literals.rs:10:10
|
||||||
|
|
|
@ -2,13 +2,13 @@ error: unknown byte escape: f
|
||||||
--> $DIR/byte-string-literals.rs:6:32
|
--> $DIR/byte-string-literals.rs:6:32
|
||||||
|
|
|
|
||||||
LL | static FOO: &'static [u8] = b"/f";
|
LL | static FOO: &'static [u8] = b"/f";
|
||||||
| ^
|
| ^ unknown byte escape
|
||||||
|
|
||||||
error: unknown byte escape: f
|
error: unknown byte escape: f
|
||||||
--> $DIR/byte-string-literals.rs:9:8
|
--> $DIR/byte-string-literals.rs:9:8
|
||||||
|
|
|
|
||||||
LL | b"/f";
|
LL | b"/f";
|
||||||
| ^
|
| ^ unknown byte escape
|
||||||
|
|
||||||
error: invalid character in numeric character escape: Z
|
error: invalid character in numeric character escape: Z
|
||||||
--> $DIR/byte-string-literals.rs:10:10
|
--> $DIR/byte-string-literals.rs:10:10
|
||||||
|
|
|
@ -14,13 +14,9 @@ error: incorrect unicode escape sequence
|
||||||
--> $DIR/issue-23620-invalid-escapes.rs:10:15
|
--> $DIR/issue-23620-invalid-escapes.rs:10:15
|
||||||
|
|
|
|
||||||
LL | let _ = b'/u';
|
LL | let _ = b'/u';
|
||||||
| ^^
|
| ^^ incorrect unicode escape sequence
|
||||||
|
|
|
|
||||||
help: format of unicode escape sequences is `/u{...}`
|
= help: format of unicode escape sequences is `/u{...}`
|
||||||
--> $DIR/issue-23620-invalid-escapes.rs:10:15
|
|
||||||
|
|
|
||||||
LL | let _ = b'/u';
|
|
||||||
| ^^
|
|
||||||
|
|
||||||
error: unicode escape sequences cannot be used as a byte or in a byte string
|
error: unicode escape sequences cannot be used as a byte or in a byte string
|
||||||
--> $DIR/issue-23620-invalid-escapes.rs:10:15
|
--> $DIR/issue-23620-invalid-escapes.rs:10:15
|
||||||
|
@ -80,13 +76,9 @@ error: incorrect unicode escape sequence
|
||||||
--> $DIR/issue-23620-invalid-escapes.rs:28:28
|
--> $DIR/issue-23620-invalid-escapes.rs:28:28
|
||||||
|
|
|
|
||||||
LL | let _ = b"/u{a4a4} /xf /u";
|
LL | let _ = b"/u{a4a4} /xf /u";
|
||||||
| ^^
|
| ^^ incorrect unicode escape sequence
|
||||||
|
|
|
|
||||||
help: format of unicode escape sequences is `/u{...}`
|
= help: format of unicode escape sequences is `/u{...}`
|
||||||
--> $DIR/issue-23620-invalid-escapes.rs:28:28
|
|
||||||
|
|
|
||||||
LL | let _ = b"/u{a4a4} /xf /u";
|
|
||||||
| ^^
|
|
||||||
|
|
||||||
error: unicode escape sequences cannot be used as a byte or in a byte string
|
error: unicode escape sequences cannot be used as a byte or in a byte string
|
||||||
--> $DIR/issue-23620-invalid-escapes.rs:28:28
|
--> $DIR/issue-23620-invalid-escapes.rs:28:28
|
||||||
|
@ -110,13 +102,9 @@ error: incorrect unicode escape sequence
|
||||||
--> $DIR/issue-23620-invalid-escapes.rs:34:18
|
--> $DIR/issue-23620-invalid-escapes.rs:34:18
|
||||||
|
|
|
|
||||||
LL | let _ = "/xf /u";
|
LL | let _ = "/xf /u";
|
||||||
| ^^
|
| ^^ incorrect unicode escape sequence
|
||||||
|
|
|
|
||||||
help: format of unicode escape sequences is `/u{...}`
|
= help: format of unicode escape sequences is `/u{...}`
|
||||||
--> $DIR/issue-23620-invalid-escapes.rs:34:18
|
|
||||||
|
|
|
||||||
LL | let _ = "/xf /u";
|
|
||||||
| ^^
|
|
||||||
|
|
||||||
error: incorrect unicode escape sequence
|
error: incorrect unicode escape sequence
|
||||||
--> $DIR/issue-23620-invalid-escapes.rs:39:14
|
--> $DIR/issue-23620-invalid-escapes.rs:39:14
|
||||||
|
|
|
@ -14,13 +14,13 @@ error: unknown character escape: /u{25cf}
|
||||||
--> $DIR/lex-bad-char-literals-1.rs:11:7
|
--> $DIR/lex-bad-char-literals-1.rs:11:7
|
||||||
|
|
|
|
||||||
LL | '/●'
|
LL | '/●'
|
||||||
| ^
|
| ^ unknown character escape
|
||||||
|
|
||||||
error: unknown character escape: /u{25cf}
|
error: unknown character escape: /u{25cf}
|
||||||
--> $DIR/lex-bad-char-literals-1.rs:15:7
|
--> $DIR/lex-bad-char-literals-1.rs:15:7
|
||||||
|
|
|
|
||||||
LL | "/●"
|
LL | "/●"
|
||||||
| ^
|
| ^ unknown character escape
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
|
|
|
@ -38,13 +38,9 @@ error: unknown character escape: /r
|
||||||
--> $DIR/lex-bare-cr-string-literal-doc-comment.rs:27:19
|
--> $DIR/lex-bare-cr-string-literal-doc-comment.rs:27:19
|
||||||
|
|
|
|
||||||
LL | let _s = "foo/
bar";
|
LL | let _s = "foo/
bar";
|
||||||
| ^
|
| ^ unknown character escape
|
||||||
|
|
|
|
||||||
help: this is an isolated carriage return; consider checking your editor and version control settings
|
= help: this is an isolated carriage return; consider checking your editor and version control settings
|
||||||
--> $DIR/lex-bare-cr-string-literal-doc-comment.rs:27:19
|
|
||||||
|
|
|
||||||
LL | let _s = "foo/
bar";
|
|
||||||
| ^
|
|
||||||
|
|
||||||
error: aborting due to 7 previous errors
|
error: aborting due to 7 previous errors
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,9 @@ error: `..` can only be used once per tuple or tuple struct pattern
|
||||||
--> $DIR/pat-tuple-3.rs:3:19
|
--> $DIR/pat-tuple-3.rs:3:19
|
||||||
|
|
|
|
||||||
LL | (.., pat, ..) => {}
|
LL | (.., pat, ..) => {}
|
||||||
| ^^ can only be used once per pattern
|
| -- ^^ can only be used once per pattern
|
||||||
|
| |
|
||||||
|
| previously present here
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,9 @@ error: unknown character escape: /r
|
||||||
--> $DIR/trailing-carriage-return-in-string.rs:10:25
|
--> $DIR/trailing-carriage-return-in-string.rs:10:25
|
||||||
|
|
|
|
||||||
LL | let bad = "This is /
a test";
|
LL | let bad = "This is /
a test";
|
||||||
| ^
|
| ^ unknown character escape
|
||||||
|
|
|
|
||||||
help: this is an isolated carriage return; consider checking your editor and version control settings
|
= help: this is an isolated carriage return; consider checking your editor and version control settings
|
||||||
--> $DIR/trailing-carriage-return-in-string.rs:10:25
|
|
||||||
|
|
|
||||||
LL | let bad = "This is /
a test";
|
|
||||||
| ^
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -2,25 +2,17 @@ error: unknown character escape: {
|
||||||
--> $DIR/wrong-escape-of-curly-braces.rs:3:17
|
--> $DIR/wrong-escape-of-curly-braces.rs:3:17
|
||||||
|
|
|
|
||||||
LL | let bad = "/{it is wrong/}";
|
LL | let bad = "/{it is wrong/}";
|
||||||
| ^
|
| ^ unknown character escape
|
||||||
|
|
|
|
||||||
help: if used in a formatting string, curly braces are escaped with `{{` and `}}`
|
= help: if used in a formatting string, curly braces are escaped with `{{` and `}}`
|
||||||
--> $DIR/wrong-escape-of-curly-braces.rs:3:17
|
|
||||||
|
|
|
||||||
LL | let bad = "/{it is wrong/}";
|
|
||||||
| ^
|
|
||||||
|
|
||||||
error: unknown character escape: }
|
error: unknown character escape: }
|
||||||
--> $DIR/wrong-escape-of-curly-braces.rs:3:30
|
--> $DIR/wrong-escape-of-curly-braces.rs:3:30
|
||||||
|
|
|
|
||||||
LL | let bad = "/{it is wrong/}";
|
LL | let bad = "/{it is wrong/}";
|
||||||
| ^
|
| ^ unknown character escape
|
||||||
|
|
|
|
||||||
help: if used in a formatting string, curly braces are escaped with `{{` and `}}`
|
= help: if used in a formatting string, curly braces are escaped with `{{` and `}}`
|
||||||
--> $DIR/wrong-escape-of-curly-braces.rs:3:30
|
|
||||||
|
|
|
||||||
LL | let bad = "/{it is wrong/}";
|
|
||||||
| ^
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue