Improve E0178 suggestion placement
This commit is contained in:
parent
3a5567bad4
commit
f4b1e2af68
7 changed files with 60 additions and 23 deletions
|
@ -37,9 +37,12 @@ impl Emitter for EmitterWriter {
|
||||||
|
|
||||||
if let Some(sugg) = db.suggestion.clone() {
|
if let Some(sugg) = db.suggestion.clone() {
|
||||||
assert_eq!(sugg.msp.primary_spans().len(), sugg.substitutes.len());
|
assert_eq!(sugg.msp.primary_spans().len(), sugg.substitutes.len());
|
||||||
if sugg.substitutes.len() == 1 && // don't display multispans as labels
|
// don't display multispans as labels
|
||||||
sugg.msg.split_whitespace().count() < 10 && // don't display long messages as labels
|
if sugg.substitutes.len() == 1 &&
|
||||||
sugg.substitutes[0].find('\n').is_none() { // don't display multiline suggestions as labels
|
// don't display long messages as labels
|
||||||
|
sugg.msg.split_whitespace().count() < 10 &&
|
||||||
|
// don't display multiline suggestions as labels
|
||||||
|
sugg.substitutes[0].find('\n').is_none() {
|
||||||
let msg = format!("{} `{}`", sugg.msg, sugg.substitutes[0]);
|
let msg = format!("{} `{}`", sugg.msg, sugg.substitutes[0]);
|
||||||
primary_span.push_span_label(sugg.msp.primary_spans()[0], msg);
|
primary_span.push_span_label(sugg.msp.primary_spans()[0], msg);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3185,7 +3185,7 @@ implementing traits from `std::ops`.
|
||||||
String concatenation appends the string on the right to the string on the
|
String concatenation appends the string on the right to the string on the
|
||||||
left and may require reallocation. This requires ownership of the string
|
left and may require reallocation. This requires ownership of the string
|
||||||
on the left. If something should be added to a string literal, move the
|
on the left. If something should be added to a string literal, move the
|
||||||
literal to the heap by allocating it with `to_owned()` like in
|
literal to the heap by allocating it with `to_owned()` like in
|
||||||
`"Your text".to_owned()`.
|
`"Your text".to_owned()`.
|
||||||
|
|
||||||
"##,
|
"##,
|
||||||
|
|
|
@ -1490,9 +1490,8 @@ impl<'a> Parser<'a> {
|
||||||
let bounds = self.parse_ty_param_bounds()?;
|
let bounds = self.parse_ty_param_bounds()?;
|
||||||
let sum_span = ty.span.to(self.prev_span);
|
let sum_span = ty.span.to(self.prev_span);
|
||||||
|
|
||||||
let mut err = struct_span_err!(self.sess.span_diagnostic, ty.span, E0178,
|
let mut err = struct_span_err!(self.sess.span_diagnostic, sum_span, E0178,
|
||||||
"expected a path on the left-hand side of `+`, not `{}`", pprust::ty_to_string(&ty));
|
"expected a path on the left-hand side of `+`, not `{}`", pprust::ty_to_string(&ty));
|
||||||
err.span_label(ty.span, &format!("expected a path"));
|
|
||||||
|
|
||||||
match ty.node {
|
match ty.node {
|
||||||
TyKind::Rptr(ref lifetime, ref mut_ty) => {
|
TyKind::Rptr(ref lifetime, ref mut_ty) => {
|
||||||
|
@ -1511,9 +1510,11 @@ impl<'a> Parser<'a> {
|
||||||
err.span_suggestion(sum_span, "try adding parentheses:", sum_with_parens);
|
err.span_suggestion(sum_span, "try adding parentheses:", sum_with_parens);
|
||||||
}
|
}
|
||||||
TyKind::Ptr(..) | TyKind::BareFn(..) => {
|
TyKind::Ptr(..) | TyKind::BareFn(..) => {
|
||||||
help!(&mut err, "perhaps you forgot parentheses?");
|
err.span_label(sum_span, &"perhaps you forgot parentheses?");
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {
|
||||||
|
err.span_label(sum_span, &"expected a path");
|
||||||
|
},
|
||||||
}
|
}
|
||||||
err.emit();
|
err.emit();
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -12,17 +12,9 @@ trait Foo {}
|
||||||
|
|
||||||
struct Bar<'a> {
|
struct Bar<'a> {
|
||||||
w: &'a Foo + Copy,
|
w: &'a Foo + Copy,
|
||||||
//~^ ERROR E0178
|
|
||||||
//~| NOTE expected a path
|
|
||||||
x: &'a Foo + 'a,
|
x: &'a Foo + 'a,
|
||||||
//~^ ERROR E0178
|
|
||||||
//~| NOTE expected a path
|
|
||||||
y: &'a mut Foo + 'a,
|
y: &'a mut Foo + 'a,
|
||||||
//~^ ERROR E0178
|
|
||||||
//~| NOTE expected a path
|
|
||||||
z: fn() -> Foo + 'a,
|
z: fn() -> Foo + 'a,
|
||||||
//~^ ERROR E0178
|
|
||||||
//~| NOTE expected a path
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
26
src/test/ui/did_you_mean/E0178.stderr
Normal file
26
src/test/ui/did_you_mean/E0178.stderr
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
error[E0178]: expected a path on the left-hand side of `+`, not `&'a Foo`
|
||||||
|
--> $DIR/E0178.rs:14:8
|
||||||
|
|
|
||||||
|
14 | w: &'a Foo + Copy,
|
||||||
|
| ^^^^^^^^^^^^^^ try adding parentheses: `&'a (Foo + Copy)`
|
||||||
|
|
||||||
|
error[E0178]: expected a path on the left-hand side of `+`, not `&'a Foo`
|
||||||
|
--> $DIR/E0178.rs:15:8
|
||||||
|
|
|
||||||
|
15 | x: &'a Foo + 'a,
|
||||||
|
| ^^^^^^^^^^^^ try adding parentheses: `&'a (Foo + 'a)`
|
||||||
|
|
||||||
|
error[E0178]: expected a path on the left-hand side of `+`, not `&'a mut Foo`
|
||||||
|
--> $DIR/E0178.rs:16:8
|
||||||
|
|
|
||||||
|
16 | y: &'a mut Foo + 'a,
|
||||||
|
| ^^^^^^^^^^^^^^^^ try adding parentheses: `&'a mut (Foo + 'a)`
|
||||||
|
|
||||||
|
error[E0178]: expected a path on the left-hand side of `+`, not `fn() -> Foo`
|
||||||
|
--> $DIR/E0178.rs:17:8
|
||||||
|
|
|
||||||
|
17 | z: fn() -> Foo + 'a,
|
||||||
|
| ^^^^^^^^^^^^^^^^ perhaps you forgot parentheses?
|
||||||
|
|
||||||
|
error: aborting due to 4 previous errors
|
||||||
|
|
|
@ -10,12 +10,5 @@
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let _: &Copy + 'static;
|
let _: &Copy + 'static;
|
||||||
//~^ ERROR expected a path
|
|
||||||
//~| HELP try adding parentheses
|
|
||||||
//~| SUGGESTION let _: &(Copy + 'static);
|
|
||||||
//~| ERROR the trait `std::marker::Copy` cannot be made into an object
|
|
||||||
let _: &'static Copy + 'static;
|
let _: &'static Copy + 'static;
|
||||||
//~^ ERROR expected a path
|
|
||||||
//~| HELP try adding parentheses
|
|
||||||
//~| SUGGESTION let _: &'static (Copy + 'static);
|
|
||||||
}
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
error[E0178]: expected a path on the left-hand side of `+`, not `&Copy`
|
||||||
|
--> $DIR/trait-object-reference-without-parens-suggestion.rs:12:12
|
||||||
|
|
|
||||||
|
12 | let _: &Copy + 'static;
|
||||||
|
| ^^^^^^^^^^^^^^^ try adding parentheses: `&(Copy + 'static)`
|
||||||
|
|
||||||
|
error[E0178]: expected a path on the left-hand side of `+`, not `&'static Copy`
|
||||||
|
--> $DIR/trait-object-reference-without-parens-suggestion.rs:13:12
|
||||||
|
|
|
||||||
|
13 | let _: &'static Copy + 'static;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^ try adding parentheses: `&'static (Copy + 'static)`
|
||||||
|
|
||||||
|
error[E0038]: the trait `std::marker::Copy` cannot be made into an object
|
||||||
|
--> $DIR/trait-object-reference-without-parens-suggestion.rs:12:12
|
||||||
|
|
|
||||||
|
12 | let _: &Copy + 'static;
|
||||||
|
| ^^^^^ the trait `std::marker::Copy` cannot be made into an object
|
||||||
|
|
|
||||||
|
= note: the trait cannot require that `Self : Sized`
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue