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.)
This commit is contained in:
Zack M. Davis 2018-03-11 00:04:15 -08:00
parent 2f0e6a3ba5
commit 9b599856a4
10 changed files with 46 additions and 29 deletions

View File

@ -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);
}
_ => {}
}

View File

@ -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()

View File

@ -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
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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