about summary refs log tree commit diff
diff options
context:
space:
mode:
authorZack M. Davis <code@zackmdavis.net>2018-03-11 00:04:15 -0800
committerZack M. Davis <code@zackmdavis.net>2018-03-11 00:12:06 -0800
commit9b599856a4b7e375e4e54eb759c250be969f5562 (patch)
tree57b2184cdf8b196487c70d2b696ae8d40f1a9a61
parent2f0e6a3ba585e00205805d6cb9fdcbe4b1d1be63 (diff)
downloadrust-9b599856a4b7e375e4e54eb759c250be969f5562.tar.gz
rust-9b599856a4b7e375e4e54eb759c250be969f5562.zip
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.)
-rw-r--r--src/librustc_typeck/check/mod.rs8
-rw-r--r--src/libsyntax/parse/parser.rs13
-rw-r--r--src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.rs (renamed from src/test/ui/did_you_mean/issue-41679.rs)2
-rw-r--r--src/test/ui/did_you_mean/issue-41679-tilde-bitwise-negation-attempt.stderr8
-rw-r--r--src/test/ui/did_you_mean/issue-41679.stderr10
-rw-r--r--src/test/ui/did_you_mean/match-refactor-to-expr.rs (renamed from src/test/parse-fail/match-refactor-to-expr.rs)2
-rw-r--r--src/test/ui/did_you_mean/match-refactor-to-expr.stderr13
-rw-r--r--src/test/ui/did_you_mean/pub-macro-rules.rs (renamed from src/test/parse-fail/pub-macro-rules.rs)3
-rw-r--r--src/test/ui/did_you_mean/pub-macro-rules.stderr8
-rw-r--r--src/test/ui/issue-11004.stderr8
10 files changed, 46 insertions, 29 deletions
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index 19085ff039e..1ea1ff1fae2 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 f5aa01fb034..bd0ca0e6704 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
index 98c909e212f..e8fd248011c 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 00000000000..f13f15f6377
--- /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 c17812fc0cb..00000000000
--- 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
index e2fee1d1895..3c88608697a 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 00000000000..ecca781684c
--- /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
index 93b992f2f8a..65a0d642cd7 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 00000000000..dfeab75525b
--- /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 4cfc7d23bd0..268c3cd6d2a 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