未验证 提交 14574db7 编写于 作者: K kennytm 提交者: GitHub

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
......@@ -3096,10 +3096,10 @@ fn check_field(&self,
};
}
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);
}
_ => {}
}
......
......@@ -2831,9 +2831,10 @@ pub fn parse_prefix_expr(&mut self,
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 @@ fn parse_match_expr(&mut self, mut attrs: ThinVec<Attribute>) -> PResult<'a, P<E
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 @@ fn complain_if_pub_macro_diag(&mut self, vis: &VisibilityKind, sp: Span) -> PRes
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()
......
......@@ -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
}
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
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
......@@ -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
......
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
......@@ -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
......
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
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册