From 9b599856a4b7e375e4e54eb759c250be969f5562 Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Sun, 11 Mar 2018 00:04:15 -0800 Subject: [PATCH] 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.) --- src/librustc_typeck/check/mod.rs | 8 ++++---- src/libsyntax/parse/parser.rs | 13 ++++++++----- ...> issue-41679-tilde-bitwise-negation-attempt.rs} | 2 +- ...ssue-41679-tilde-bitwise-negation-attempt.stderr | 8 ++++++++ src/test/ui/did_you_mean/issue-41679.stderr | 10 ---------- .../did_you_mean}/match-refactor-to-expr.rs | 2 +- .../ui/did_you_mean/match-refactor-to-expr.stderr | 13 +++++++++++++ .../did_you_mean}/pub-macro-rules.rs | 3 +-- src/test/ui/did_you_mean/pub-macro-rules.stderr | 8 ++++++++ src/test/ui/issue-11004.stderr | 8 ++------ 10 files changed, 46 insertions(+), 29 deletions(-) rename src/test/ui/did_you_mean/{issue-41679.rs => issue-41679-tilde-bitwise-negation-attempt.rs} (88%) create mode 100644 src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.stderr delete mode 100644 src/test/ui/did_you_mean/issue-41679.stderr rename src/test/{parse-fail => ui/did_you_mean}/match-refactor-to-expr.rs (91%) create mode 100644 src/test/ui/did_you_mean/match-refactor-to-expr.stderr rename src/test/{parse-fail => ui/did_you_mean}/pub-macro-rules.rs (91%) create mode 100644 src/test/ui/did_you_mean/pub-macro-rules.stderr diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 19085ff039ec5..1ea1ff1fae24d 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3096,10 +3096,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { }; } ty::TyRawPtr(..) => { - err.note(&format!("`{0}` is a native pointer; perhaps you need to deref \ - with `(*{0}).{1}`", - self.tcx.hir.node_to_pretty_string(base.id), - field.node)); + let base = self.tcx.hir.node_to_pretty_string(base.id); + let msg = format!("`{}` is a native pointer; try dereferencing it", base); + let suggestion = format!("(*{}).{}", base, field.node); + err.span_suggestion(field.span, &msg, suggestion); } _ => {} } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index f5aa01fb03459..bd0ca0e670487 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2831,9 +2831,10 @@ impl<'a> Parser<'a> { let (span, e) = self.interpolated_or_expr_span(e)?; let span_of_tilde = lo; let mut err = self.diagnostic().struct_span_err(span_of_tilde, - "`~` can not be used as a unary operator"); - err.span_label(span_of_tilde, "did you mean `!`?"); - err.help("use `!` instead of `~` if you meant to perform bitwise negation"); + "`~` cannot be used as a unary operator"); + err.span_suggestion_short(span_of_tilde, + "use `!` to perform bitwise negation", + "!".to_owned()); err.emit(); (lo.to(span), self.mk_unary(UnOp::Not, e)) } @@ -3389,7 +3390,7 @@ impl<'a> Parser<'a> { None)?; if let Err(mut e) = self.expect(&token::OpenDelim(token::Brace)) { if self.token == token::Token::Semi { - e.span_note(match_span, "did you mean to remove this `match` keyword?"); + e.span_suggestion_short(match_span, "try removing this `match`", "".to_owned()); } return Err(e) } @@ -5361,7 +5362,9 @@ impl<'a> Parser<'a> { if is_macro_rules { let mut err = self.diagnostic() .struct_span_err(sp, "can't qualify macro_rules invocation with `pub`"); - err.help("did you mean #[macro_export]?"); + err.span_suggestion(sp, + "try exporting the macro", + "#[macro_export]".to_owned()); Err(err) } else { let mut err = self.diagnostic() diff --git a/src/test/ui/did_you_mean/issue-41679.rs b/src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.rs similarity index 88% rename from src/test/ui/did_you_mean/issue-41679.rs rename to src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.rs index 98c909e212fdd..e8fd248011cb8 100644 --- a/src/test/ui/did_you_mean/issue-41679.rs +++ b/src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.rs @@ -9,5 +9,5 @@ // except according to those terms. fn main() { - let x = ~1; //~ ERROR can not be used as a unary operator + let x = ~1; //~ ERROR cannot be used as a unary operator } diff --git a/src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.stderr b/src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.stderr new file mode 100644 index 0000000000000..f13f15f63771d --- /dev/null +++ b/src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.stderr @@ -0,0 +1,8 @@ +error: `~` cannot be used as a unary operator + --> $DIR/issue-41679-tilde-bitwise-negation-attempt.rs:12:13 + | +LL | let x = ~1; //~ ERROR cannot be used as a unary operator + | ^ help: use `!` to perform bitwise negation + +error: aborting due to previous error + diff --git a/src/test/ui/did_you_mean/issue-41679.stderr b/src/test/ui/did_you_mean/issue-41679.stderr deleted file mode 100644 index c17812fc0cb9d..0000000000000 --- a/src/test/ui/did_you_mean/issue-41679.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: `~` can not be used as a unary operator - --> $DIR/issue-41679.rs:12:13 - | -LL | let x = ~1; //~ ERROR can not be used as a unary operator - | ^ did you mean `!`? - | - = help: use `!` instead of `~` if you meant to perform bitwise negation - -error: aborting due to previous error - diff --git a/src/test/parse-fail/match-refactor-to-expr.rs b/src/test/ui/did_you_mean/match-refactor-to-expr.rs similarity index 91% rename from src/test/parse-fail/match-refactor-to-expr.rs rename to src/test/ui/did_you_mean/match-refactor-to-expr.rs index e2fee1d189591..3c88608697aad 100644 --- a/src/test/parse-fail/match-refactor-to-expr.rs +++ b/src/test/ui/did_you_mean/match-refactor-to-expr.rs @@ -12,7 +12,7 @@ fn main() { let foo = - match //~ NOTE did you mean to remove this `match` keyword? + match Some(4).unwrap_or_else(5) //~^ NOTE expected one of `.`, `?`, `{`, or an operator here ; //~ NOTE unexpected token diff --git a/src/test/ui/did_you_mean/match-refactor-to-expr.stderr b/src/test/ui/did_you_mean/match-refactor-to-expr.stderr new file mode 100644 index 0000000000000..ecca781684cec --- /dev/null +++ b/src/test/ui/did_you_mean/match-refactor-to-expr.stderr @@ -0,0 +1,13 @@ +error: expected one of `.`, `?`, `{`, or an operator, found `;` + --> $DIR/match-refactor-to-expr.rs:18:9 + | +LL | match + | ----- help: try removing this `match` +LL | Some(4).unwrap_or_else(5) + | - expected one of `.`, `?`, `{`, or an operator here +LL | //~^ NOTE expected one of `.`, `?`, `{`, or an operator here +LL | ; //~ NOTE unexpected token + | ^ unexpected token + +error: aborting due to previous error + diff --git a/src/test/parse-fail/pub-macro-rules.rs b/src/test/ui/did_you_mean/pub-macro-rules.rs similarity index 91% rename from src/test/parse-fail/pub-macro-rules.rs rename to src/test/ui/did_you_mean/pub-macro-rules.rs index 93b992f2f8af2..65a0d642cd7d1 100644 --- a/src/test/parse-fail/pub-macro-rules.rs +++ b/src/test/ui/did_you_mean/pub-macro-rules.rs @@ -9,8 +9,7 @@ // except according to those terms. #[macro_use] mod bleh { - pub macro_rules! foo { //~ ERROR can't qualify macro_rules invocation with `pub` - //~^ HELP did you mean #[macro_export]? + pub macro_rules! foo { //~ ERROR can't qualify macro_rules invocation ($n:ident) => ( fn $n () -> i32 { 1 diff --git a/src/test/ui/did_you_mean/pub-macro-rules.stderr b/src/test/ui/did_you_mean/pub-macro-rules.stderr new file mode 100644 index 0000000000000..dfeab75525ba3 --- /dev/null +++ b/src/test/ui/did_you_mean/pub-macro-rules.stderr @@ -0,0 +1,8 @@ +error: can't qualify macro_rules invocation with `pub` + --> $DIR/pub-macro-rules.rs:12:5 + | +LL | pub macro_rules! foo { //~ ERROR can't qualify macro_rules invocation + | ^^^ help: try exporting the macro: `#[macro_export]` + +error: aborting due to previous error + diff --git a/src/test/ui/issue-11004.stderr b/src/test/ui/issue-11004.stderr index 4cfc7d23bd0b9..268c3cd6d2afd 100644 --- a/src/test/ui/issue-11004.stderr +++ b/src/test/ui/issue-11004.stderr @@ -2,17 +2,13 @@ error[E0609]: no field `x` on type `*mut A` --> $DIR/issue-11004.rs:17:21 | LL | let x : i32 = n.x; //~ no field `x` on type `*mut A` - | ^ - | - = note: `n` is a native pointer; perhaps you need to deref with `(*n).x` + | ^ help: `n` is a native pointer; try dereferencing it: `(*n).x` error[E0609]: no field `y` on type `*mut A` --> $DIR/issue-11004.rs:18:21 | LL | let y : f64 = n.y; //~ no field `y` on type `*mut A` - | ^ - | - = note: `n` is a native pointer; perhaps you need to deref with `(*n).y` + | ^ help: `n` is a native pointer; try dereferencing it: `(*n).y` error: aborting due to 2 previous errors