Skip to content

Commit 14574db

Browse files
authored
Rollup merge of #48928 - zackmdavis:span_suggestion_field_day, r=estebank
in which some labels and notes are upgraded to structured suggestions (Meanwhile, a couple of parse-fail tests are moved to UI tests so that the reader can see the new output, and an existing UI test is given a more evocative name.) r? @estebank
2 parents 2d13cc4 + 9b59985 commit 14574db

10 files changed

+46
-29
lines changed

src/librustc_typeck/check/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3096,10 +3096,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
30963096
};
30973097
}
30983098
ty::TyRawPtr(..) => {
3099-
err.note(&format!("`{0}` is a native pointer; perhaps you need to deref \
3100-
with `(*{0}).{1}`",
3101-
self.tcx.hir.node_to_pretty_string(base.id),
3102-
field.node));
3099+
let base = self.tcx.hir.node_to_pretty_string(base.id);
3100+
let msg = format!("`{}` is a native pointer; try dereferencing it", base);
3101+
let suggestion = format!("(*{}).{}", base, field.node);
3102+
err.span_suggestion(field.span, &msg, suggestion);
31033103
}
31043104
_ => {}
31053105
}

src/libsyntax/parse/parser.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -2831,9 +2831,10 @@ impl<'a> Parser<'a> {
28312831
let (span, e) = self.interpolated_or_expr_span(e)?;
28322832
let span_of_tilde = lo;
28332833
let mut err = self.diagnostic().struct_span_err(span_of_tilde,
2834-
"`~` can not be used as a unary operator");
2835-
err.span_label(span_of_tilde, "did you mean `!`?");
2836-
err.help("use `!` instead of `~` if you meant to perform bitwise negation");
2834+
"`~` cannot be used as a unary operator");
2835+
err.span_suggestion_short(span_of_tilde,
2836+
"use `!` to perform bitwise negation",
2837+
"!".to_owned());
28372838
err.emit();
28382839
(lo.to(span), self.mk_unary(UnOp::Not, e))
28392840
}
@@ -3389,7 +3390,7 @@ impl<'a> Parser<'a> {
33893390
None)?;
33903391
if let Err(mut e) = self.expect(&token::OpenDelim(token::Brace)) {
33913392
if self.token == token::Token::Semi {
3392-
e.span_note(match_span, "did you mean to remove this `match` keyword?");
3393+
e.span_suggestion_short(match_span, "try removing this `match`", "".to_owned());
33933394
}
33943395
return Err(e)
33953396
}
@@ -5361,7 +5362,9 @@ impl<'a> Parser<'a> {
53615362
if is_macro_rules {
53625363
let mut err = self.diagnostic()
53635364
.struct_span_err(sp, "can't qualify macro_rules invocation with `pub`");
5364-
err.help("did you mean #[macro_export]?");
5365+
err.span_suggestion(sp,
5366+
"try exporting the macro",
5367+
"#[macro_export]".to_owned());
53655368
Err(err)
53665369
} else {
53675370
let mut err = self.diagnostic()

src/test/ui/did_you_mean/issue-41679.rs renamed to src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
// except according to those terms.
1010

1111
fn main() {
12-
let x = ~1; //~ ERROR can not be used as a unary operator
12+
let x = ~1; //~ ERROR cannot be used as a unary operator
1313
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: `~` cannot be used as a unary operator
2+
--> $DIR/issue-41679-tilde-bitwise-negation-attempt.rs:12:13
3+
|
4+
LL | let x = ~1; //~ ERROR cannot be used as a unary operator
5+
| ^ help: use `!` to perform bitwise negation
6+
7+
error: aborting due to previous error
8+

src/test/ui/did_you_mean/issue-41679.stderr

-10
This file was deleted.

src/test/parse-fail/match-refactor-to-expr.rs renamed to src/test/ui/did_you_mean/match-refactor-to-expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
fn main() {
1414
let foo =
15-
match //~ NOTE did you mean to remove this `match` keyword?
15+
match
1616
Some(4).unwrap_or_else(5)
1717
//~^ NOTE expected one of `.`, `?`, `{`, or an operator here
1818
; //~ NOTE unexpected token
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error: expected one of `.`, `?`, `{`, or an operator, found `;`
2+
--> $DIR/match-refactor-to-expr.rs:18:9
3+
|
4+
LL | match
5+
| ----- help: try removing this `match`
6+
LL | Some(4).unwrap_or_else(5)
7+
| - expected one of `.`, `?`, `{`, or an operator here
8+
LL | //~^ NOTE expected one of `.`, `?`, `{`, or an operator here
9+
LL | ; //~ NOTE unexpected token
10+
| ^ unexpected token
11+
12+
error: aborting due to previous error
13+

src/test/parse-fail/pub-macro-rules.rs renamed to src/test/ui/did_you_mean/pub-macro-rules.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
// except according to those terms.
1010

1111
#[macro_use] mod bleh {
12-
pub macro_rules! foo { //~ ERROR can't qualify macro_rules invocation with `pub`
13-
//~^ HELP did you mean #[macro_export]?
12+
pub macro_rules! foo { //~ ERROR can't qualify macro_rules invocation
1413
($n:ident) => (
1514
fn $n () -> i32 {
1615
1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: can't qualify macro_rules invocation with `pub`
2+
--> $DIR/pub-macro-rules.rs:12:5
3+
|
4+
LL | pub macro_rules! foo { //~ ERROR can't qualify macro_rules invocation
5+
| ^^^ help: try exporting the macro: `#[macro_export]`
6+
7+
error: aborting due to previous error
8+

src/test/ui/issue-11004.stderr

+2-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@ error[E0609]: no field `x` on type `*mut A`
22
--> $DIR/issue-11004.rs:17:21
33
|
44
LL | let x : i32 = n.x; //~ no field `x` on type `*mut A`
5-
| ^
6-
|
7-
= note: `n` is a native pointer; perhaps you need to deref with `(*n).x`
5+
| ^ help: `n` is a native pointer; try dereferencing it: `(*n).x`
86

97
error[E0609]: no field `y` on type `*mut A`
108
--> $DIR/issue-11004.rs:18:21
119
|
1210
LL | let y : f64 = n.y; //~ no field `y` on type `*mut A`
13-
| ^
14-
|
15-
= note: `n` is a native pointer; perhaps you need to deref with `(*n).y`
11+
| ^ help: `n` is a native pointer; try dereferencing it: `(*n).y`
1612

1713
error: aborting due to 2 previous errors
1814

0 commit comments

Comments
 (0)