Tweak unsupported negative trait bounds message

This commit is contained in:
Esteban Küber 2019-03-10 19:46:44 -07:00
parent e1be8b0318
commit 9bfb0ef818
6 changed files with 55 additions and 38 deletions

View File

@ -366,7 +366,7 @@ pub fn span_suggestion_hidden(
}],
}],
msg: msg.to_owned(),
style: SuggestionStyle::HideCodeInline,
style: SuggestionStyle::HideCodeAlways,
applicability,
});
self

View File

@ -5598,8 +5598,14 @@ fn parse_generic_bounds_common(&mut self,
if !negative_bounds.is_empty() || was_negative {
let plural = negative_bounds.len() > 1;
let mut err = self.struct_span_err(negative_bounds,
"negative trait bounds are not supported");
let last_span = negative_bounds.last().map(|sp| *sp);
let mut err = self.struct_span_err(
negative_bounds,
"negative trait bounds are not supported",
);
if let Some(sp) = last_span {
err.span_label(sp, "negative trait bounds are not supported");
}
if let Some(bound_list) = colon_span {
let bound_list = bound_list.to(self.prev_span);
let mut new_bound_list = String::new();
@ -5612,11 +5618,12 @@ fn parse_generic_bounds_common(&mut self,
}
new_bound_list = new_bound_list.replacen(" +", ":", 1);
}
err.span_suggestion_short(bound_list,
&format!("remove the trait bound{}",
if plural { "s" } else { "" }),
new_bound_list,
Applicability::MachineApplicable);
err.span_suggestion_hidden(
bound_list,
&format!("remove the trait bound{}", if plural { "s" } else { "" }),
new_bound_list,
Applicability::MachineApplicable,
);
}
err.emit();
}

View File

@ -2,7 +2,8 @@ error: negative trait bounds are not supported
--> $DIR/issue-58857.rs:4:7
|
LL | impl<A: !Valid> Conj<A>{}
| ^^^^^^^^ help: remove the trait bound
| ^^^^^^^^ negative trait bounds are not supported
= help: remove the trait bound
error: aborting due to previous error

View File

@ -1,10 +1,15 @@
// run-rustfix
trait Tr {} //~ ERROR negative trait bounds are not supported
trait Tr2: SuperA {} //~ ERROR negative trait bounds are not supported
trait Tr3: SuperB {} //~ ERROR negative trait bounds are not supported
trait Tr {}
//~^ ERROR negative trait bounds are not supported
trait Tr2: SuperA {}
//~^ ERROR negative trait bounds are not supported
trait Tr3: SuperB {}
//~^ ERROR negative trait bounds are not supported
trait Tr4: SuperB + SuperD {}
//~^ ERROR negative trait bounds are not supported
trait Tr5 {}
//~^ ERROR negative trait bounds are not supported
trait SuperA {}
trait SuperB {}

View File

@ -1,12 +1,17 @@
// run-rustfix
trait Tr: !SuperA {} //~ ERROR negative trait bounds are not supported
trait Tr2: SuperA + !SuperB {} //~ ERROR negative trait bounds are not supported
trait Tr3: !SuperA + SuperB {} //~ ERROR negative trait bounds are not supported
trait Tr4: !SuperA + SuperB //~ ERROR negative trait bounds are not supported
trait Tr: !SuperA {}
//~^ ERROR negative trait bounds are not supported
trait Tr2: SuperA + !SuperB {}
//~^ ERROR negative trait bounds are not supported
trait Tr3: !SuperA + SuperB {}
//~^ ERROR negative trait bounds are not supported
trait Tr4: !SuperA + SuperB
+ !SuperC + SuperD {}
trait Tr5: !SuperA //~ ERROR negative trait bounds are not supported
//~^ ERROR negative trait bounds are not supported
trait Tr5: !SuperA
+ !SuperB {}
//~^ ERROR negative trait bounds are not supported
trait SuperA {}
trait SuperB {}

View File

@ -2,41 +2,40 @@ error: negative trait bounds are not supported
--> $DIR/issue-33418.rs:3:9
|
LL | trait Tr: !SuperA {}
| ^^^^^^^^^ help: remove the trait bound
| ^^^^^^^^^ negative trait bounds are not supported
= help: remove the trait bound
error: negative trait bounds are not supported
--> $DIR/issue-33418.rs:4:19
--> $DIR/issue-33418.rs:5:19
|
LL | trait Tr2: SuperA + !SuperB {}
| ---------^^^^^^^^^
| |
| help: remove the trait bound
| ^^^^^^^^^ negative trait bounds are not supported
= help: remove the trait bound
error: negative trait bounds are not supported
--> $DIR/issue-33418.rs:5:10
--> $DIR/issue-33418.rs:7:10
|
LL | trait Tr3: !SuperA + SuperB {}
| ^^^^^^^^^---------
| |
| help: remove the trait bound
| ^^^^^^^^^ negative trait bounds are not supported
= help: remove the trait bound
error: negative trait bounds are not supported
--> $DIR/issue-33418.rs:6:10
--> $DIR/issue-33418.rs:9:10
|
LL | trait Tr4: !SuperA + SuperB
| __________-^^^^^^^^
LL | | + !SuperC + SuperD {}
| |_____^^^^^^^^^________- help: remove the trait bounds
LL | trait Tr4: !SuperA + SuperB
| ^^^^^^^^^
LL | + !SuperC + SuperD {}
| ^^^^^^^^^ negative trait bounds are not supported
= help: remove the trait bounds
error: negative trait bounds are not supported
--> $DIR/issue-33418.rs:8:10
--> $DIR/issue-33418.rs:12:10
|
LL | trait Tr5: !SuperA
| __________-^^^^^^^^
LL | | + !SuperB {}
| | ^^^^^^^^-
| |_____________|
| help: remove the trait bounds
LL | trait Tr5: !SuperA
| ^^^^^^^^^
LL | + !SuperB {}
| ^^^^^^^^^ negative trait bounds are not supported
= help: remove the trait bounds
error: aborting due to 5 previous errors