Skip to content

Commit 7feb802

Browse files
committed
Small tweaks to parser errors
1 parent de3c4be commit 7feb802

File tree

5 files changed

+39
-24
lines changed

5 files changed

+39
-24
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,10 @@ impl<'a> Parser<'a> {
10121012
if text.is_empty() {
10131013
self.span_bug(sp, "found empty literal suffix in Some")
10141014
}
1015-
self.span_err(sp, &format!("{} with a suffix is invalid", kind));
1015+
let msg = format!("{} with a suffix is invalid", kind);
1016+
self.struct_span_err(sp, &msg)
1017+
.span_label(sp, msg)
1018+
.emit();
10161019
}
10171020
}
10181021
}
@@ -1768,9 +1771,11 @@ impl<'a> Parser<'a> {
17681771
Mutability::Immutable
17691772
} else {
17701773
let span = self.prev_span;
1771-
self.span_err(span,
1772-
"expected mut or const in raw pointer type (use \
1773-
`*mut T` or `*const T` as appropriate)");
1774+
let msg = "expected mut or const in raw pointer type";
1775+
self.struct_span_err(span, msg)
1776+
.span_label(span, msg)
1777+
.help("use `*mut T` or `*const T` as appropriate")
1778+
.emit();
17741779
Mutability::Immutable
17751780
};
17761781
let t = self.parse_ty_no_plus()?;
@@ -5612,15 +5617,20 @@ impl<'a> Parser<'a> {
56125617
// *mut self
56135618
// *not_self
56145619
// Emit special error for `self` cases.
5620+
let msg = "cannot pass `self` by raw pointer";
56155621
(if isolated_self(self, 1) {
56165622
self.bump();
5617-
self.span_err(self.span, "cannot pass `self` by raw pointer");
5623+
self.struct_span_err(self.span, msg)
5624+
.span_label(self.span, msg)
5625+
.emit();
56185626
SelfKind::Value(Mutability::Immutable)
56195627
} else if self.look_ahead(1, |t| t.is_mutability()) &&
56205628
isolated_self(self, 2) {
56215629
self.bump();
56225630
self.bump();
5623-
self.span_err(self.span, "cannot pass `self` by raw pointer");
5631+
self.struct_span_err(self.span, msg)
5632+
.span_label(self.span, msg)
5633+
.emit();
56245634
SelfKind::Value(Mutability::Immutable)
56255635
} else {
56265636
return Ok(None);
@@ -5957,7 +5967,10 @@ impl<'a> Parser<'a> {
59575967
tps.where_clause = self.parse_where_clause()?;
59585968
self.expect(&token::Semi)?;
59595969
if unsafety != Unsafety::Normal {
5960-
self.span_err(self.prev_span, "trait aliases cannot be unsafe");
5970+
let msg = "trait aliases cannot be unsafe";
5971+
self.struct_span_err(self.prev_span, msg)
5972+
.span_label(self.prev_span, msg)
5973+
.emit();
59615974
}
59625975
Ok((ident, ItemKind::TraitAlias(tps, bounds), None))
59635976
} else {

src/test/ui/parser/bad-lit-suffixes.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,49 @@ error: ABI spec with a suffix is invalid
22
--> $DIR/bad-lit-suffixes.rs:5:5
33
|
44
LL | "C"suffix //~ ERROR ABI spec with a suffix is invalid
5-
| ^^^^^^^^^
5+
| ^^^^^^^^^ ABI spec with a suffix is invalid
66

77
error: ABI spec with a suffix is invalid
88
--> $DIR/bad-lit-suffixes.rs:9:5
99
|
1010
LL | "C"suffix //~ ERROR ABI spec with a suffix is invalid
11-
| ^^^^^^^^^
11+
| ^^^^^^^^^ ABI spec with a suffix is invalid
1212

1313
error: string literal with a suffix is invalid
1414
--> $DIR/bad-lit-suffixes.rs:13:5
1515
|
1616
LL | ""suffix; //~ ERROR string literal with a suffix is invalid
17-
| ^^^^^^^^
17+
| ^^^^^^^^ string literal with a suffix is invalid
1818

1919
error: byte string literal with a suffix is invalid
2020
--> $DIR/bad-lit-suffixes.rs:14:5
2121
|
2222
LL | b""suffix; //~ ERROR byte string literal with a suffix is invalid
23-
| ^^^^^^^^^
23+
| ^^^^^^^^^ byte string literal with a suffix is invalid
2424

2525
error: string literal with a suffix is invalid
2626
--> $DIR/bad-lit-suffixes.rs:15:5
2727
|
2828
LL | r#""#suffix; //~ ERROR string literal with a suffix is invalid
29-
| ^^^^^^^^^^^
29+
| ^^^^^^^^^^^ string literal with a suffix is invalid
3030

3131
error: byte string literal with a suffix is invalid
3232
--> $DIR/bad-lit-suffixes.rs:16:5
3333
|
3434
LL | br#""#suffix; //~ ERROR byte string literal with a suffix is invalid
35-
| ^^^^^^^^^^^^
35+
| ^^^^^^^^^^^^ byte string literal with a suffix is invalid
3636

3737
error: char literal with a suffix is invalid
3838
--> $DIR/bad-lit-suffixes.rs:17:5
3939
|
4040
LL | 'a'suffix; //~ ERROR char literal with a suffix is invalid
41-
| ^^^^^^^^^
41+
| ^^^^^^^^^ char literal with a suffix is invalid
4242

4343
error: byte literal with a suffix is invalid
4444
--> $DIR/bad-lit-suffixes.rs:18:5
4545
|
4646
LL | b'a'suffix; //~ ERROR byte literal with a suffix is invalid
47-
| ^^^^^^^^^^
47+
| ^^^^^^^^^^ byte literal with a suffix is invalid
4848

4949
error: invalid width `1024` for integer literal
5050
--> $DIR/bad-lit-suffixes.rs:20:5
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
fn foo(_: *()) {
2-
//~^ expected mut or const in raw pointer type (use `*mut T` or `*const T` as appropriate)
2+
//~^ ERROR expected mut or const in raw pointer type
33
}
44

55
fn main() {}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
error: expected mut or const in raw pointer type (use `*mut T` or `*const T` as appropriate)
1+
error: expected mut or const in raw pointer type
22
--> $DIR/bad-pointer-type.rs:1:11
33
|
44
LL | fn foo(_: *()) {
5-
| ^
5+
| ^ expected mut or const in raw pointer type
6+
|
7+
= help: use `*mut T` or `*const T` as appropriate
68

79
error: aborting due to previous error
810

src/test/ui/parser/no-unsafe-self.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,37 @@ error: cannot pass `self` by raw pointer
22
--> $DIR/no-unsafe-self.rs:4:17
33
|
44
LL | fn foo(*mut self); //~ ERROR cannot pass `self` by raw pointer
5-
| ^^^^
5+
| ^^^^ cannot pass `self` by raw pointer
66

77
error: cannot pass `self` by raw pointer
88
--> $DIR/no-unsafe-self.rs:5:19
99
|
1010
LL | fn baz(*const self); //~ ERROR cannot pass `self` by raw pointer
11-
| ^^^^
11+
| ^^^^ cannot pass `self` by raw pointer
1212

1313
error: cannot pass `self` by raw pointer
1414
--> $DIR/no-unsafe-self.rs:6:13
1515
|
1616
LL | fn bar(*self); //~ ERROR cannot pass `self` by raw pointer
17-
| ^^^^
17+
| ^^^^ cannot pass `self` by raw pointer
1818

1919
error: cannot pass `self` by raw pointer
2020
--> $DIR/no-unsafe-self.rs:11:17
2121
|
2222
LL | fn foo(*mut self) { } //~ ERROR cannot pass `self` by raw pointer
23-
| ^^^^
23+
| ^^^^ cannot pass `self` by raw pointer
2424

2525
error: cannot pass `self` by raw pointer
2626
--> $DIR/no-unsafe-self.rs:12:19
2727
|
2828
LL | fn baz(*const self) { } //~ ERROR cannot pass `self` by raw pointer
29-
| ^^^^
29+
| ^^^^ cannot pass `self` by raw pointer
3030

3131
error: cannot pass `self` by raw pointer
3232
--> $DIR/no-unsafe-self.rs:13:13
3333
|
3434
LL | fn bar(*self) { } //~ ERROR cannot pass `self` by raw pointer
35-
| ^^^^
35+
| ^^^^ cannot pass `self` by raw pointer
3636

3737
error: aborting due to 6 previous errors
3838

0 commit comments

Comments
 (0)