Skip to content

Commit

Permalink
Reword invalid suffixe errors
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Mar 26, 2019
1 parent c7ddb83 commit 1bb3694
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 37 deletions.
13 changes: 6 additions & 7 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1119,9 +1119,8 @@ impl<'a> Parser<'a> {
if text.is_empty() {
self.span_bug(sp, "found empty literal suffix in Some")
}
let msg = format!("{} with a suffix is invalid", kind);
self.struct_span_err(sp, &msg)
.span_label(sp, msg)
self.struct_span_err(sp, &format!("suffixes on {} are invalid", kind))
.span_label(sp, format!("invalid suffix `{}`", text))
.emit();
}
}
Expand Down Expand Up @@ -2150,7 +2149,7 @@ impl<'a> Parser<'a> {

if suffix_illegal {
let sp = self.span;
self.expect_no_suffix(sp, lit.literal_name(), suf)
self.expect_no_suffix(sp, &format!("a {}", lit.literal_name()), suf)
}

result.unwrap()
Expand Down Expand Up @@ -3205,7 +3204,7 @@ impl<'a> Parser<'a> {
let field = ExprKind::Field(e, Ident::new(name, span));
e = self.mk_expr(lo.to(span), field, ThinVec::new());

self.expect_no_suffix(span, "tuple index", suffix);
self.expect_no_suffix(span, "a tuple index", suffix);
}
token::Literal(token::Float(n), _suf) => {
self.bump();
Expand Down Expand Up @@ -7791,7 +7790,7 @@ impl<'a> Parser<'a> {
match self.token {
token::Literal(token::Str_(s), suf) | token::Literal(token::StrRaw(s, _), suf) => {
let sp = self.span;
self.expect_no_suffix(sp, "ABI spec", suf);
self.expect_no_suffix(sp, "an ABI spec", suf);
self.bump();
match abi::lookup(&s.as_str()) {
Some(abi) => Ok(Some(abi)),
Expand Down Expand Up @@ -8612,7 +8611,7 @@ impl<'a> Parser<'a> {
match self.parse_optional_str() {
Some((s, style, suf)) => {
let sp = self.prev_span;
self.expect_no_suffix(sp, "string literal", suf);
self.expect_no_suffix(sp, "a string literal", suf);
Ok((s, style))
}
_ => {
Expand Down
16 changes: 8 additions & 8 deletions src/test/ui/parser/bad-lit-suffixes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@


extern
"C"suffix //~ ERROR ABI spec with a suffix is invalid
"C"suffix //~ ERROR suffixes on an ABI spec are invalid
fn foo() {}

extern
"C"suffix //~ ERROR ABI spec with a suffix is invalid
"C"suffix //~ ERROR suffixes on an ABI spec are invalid
{}

fn main() {
""suffix; //~ ERROR string literal with a suffix is invalid
b""suffix; //~ ERROR byte string literal with a suffix is invalid
r#""#suffix; //~ ERROR string literal with a suffix is invalid
br#""#suffix; //~ ERROR byte string literal with a suffix is invalid
'a'suffix; //~ ERROR char literal with a suffix is invalid
b'a'suffix; //~ ERROR byte literal with a suffix is invalid
""suffix; //~ ERROR suffixes on a string literal are invalid
b""suffix; //~ ERROR suffixes on a byte string literal are invalid
r#""#suffix; //~ ERROR suffixes on a string literal are invalid
br#""#suffix; //~ ERROR suffixes on a byte string literal are invalid
'a'suffix; //~ ERROR suffixes on a char literal are invalid
b'a'suffix; //~ ERROR suffixes on a byte literal are invalid

1234u1024; //~ ERROR invalid width `1024` for integer literal
1234i1024; //~ ERROR invalid width `1024` for integer literal
Expand Down
32 changes: 16 additions & 16 deletions src/test/ui/parser/bad-lit-suffixes.stderr
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
error: ABI spec with a suffix is invalid
error: suffixes on an ABI spec are invalid
--> $DIR/bad-lit-suffixes.rs:5:5
|
LL | "C"suffix
| ^^^^^^^^^ ABI spec with a suffix is invalid
| ^^^^^^^^^ invalid suffix `suffix`

error: ABI spec with a suffix is invalid
error: suffixes on an ABI spec are invalid
--> $DIR/bad-lit-suffixes.rs:9:5
|
LL | "C"suffix
| ^^^^^^^^^ ABI spec with a suffix is invalid
| ^^^^^^^^^ invalid suffix `suffix`

error: string literal with a suffix is invalid
error: suffixes on a string literal are invalid
--> $DIR/bad-lit-suffixes.rs:13:5
|
LL | ""suffix;
| ^^^^^^^^ string literal with a suffix is invalid
| ^^^^^^^^ invalid suffix `suffix`

error: byte string literal with a suffix is invalid
error: suffixes on a byte string literal are invalid
--> $DIR/bad-lit-suffixes.rs:14:5
|
LL | b""suffix;
| ^^^^^^^^^ byte string literal with a suffix is invalid
| ^^^^^^^^^ invalid suffix `suffix`

error: string literal with a suffix is invalid
error: suffixes on a string literal are invalid
--> $DIR/bad-lit-suffixes.rs:15:5
|
LL | r#""#suffix;
| ^^^^^^^^^^^ string literal with a suffix is invalid
| ^^^^^^^^^^^ invalid suffix `suffix`

error: byte string literal with a suffix is invalid
error: suffixes on a byte string literal are invalid
--> $DIR/bad-lit-suffixes.rs:16:5
|
LL | br#""#suffix;
| ^^^^^^^^^^^^ byte string literal with a suffix is invalid
| ^^^^^^^^^^^^ invalid suffix `suffix`

error: char literal with a suffix is invalid
error: suffixes on a char literal are invalid
--> $DIR/bad-lit-suffixes.rs:17:5
|
LL | 'a'suffix;
| ^^^^^^^^^ char literal with a suffix is invalid
| ^^^^^^^^^ invalid suffix `suffix`

error: byte literal with a suffix is invalid
error: suffixes on a byte literal are invalid
--> $DIR/bad-lit-suffixes.rs:18:5
|
LL | b'a'suffix;
| ^^^^^^^^^^ byte literal with a suffix is invalid
| ^^^^^^^^^^ invalid suffix `suffix`

error: invalid width `1024` for integer literal
--> $DIR/bad-lit-suffixes.rs:20:5
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/parser/issue-59418.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ struct X(i32,i32,i32);
fn main() {
let a = X(1, 2, 3);
let b = a.1suffix;
//~^ ERROR tuple index with a suffix is invalid
//~^ ERROR suffixes on a tuple index are invalid
println!("{}", b);
let c = (1, 2, 3);
let d = c.1suffix;
//~^ ERROR tuple index with a suffix is invalid
//~^ ERROR suffixes on a tuple index are invalid
println!("{}", d);
}
8 changes: 4 additions & 4 deletions src/test/ui/parser/issue-59418.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
error: tuple index with a suffix is invalid
error: suffixes on a tuple index are invalid
--> $DIR/issue-59418.rs:5:15
|
LL | let b = a.1suffix;
| ^^^^^^^ tuple index with a suffix is invalid
| ^^^^^^^ invalid suffix `suffix`

error: tuple index with a suffix is invalid
error: suffixes on a tuple index are invalid
--> $DIR/issue-59418.rs:9:15
|
LL | let d = c.1suffix;
| ^^^^^^^ tuple index with a suffix is invalid
| ^^^^^^^ invalid suffix `suffix`

error: aborting due to 2 previous errors

0 comments on commit 1bb3694

Please sign in to comment.