Skip to content

Commit 9bfb0ef

Browse files
committed
Tweak unsupported negative trait bounds message
1 parent e1be8b0 commit 9bfb0ef

File tree

6 files changed

+55
-38
lines changed

6 files changed

+55
-38
lines changed

src/librustc_errors/diagnostic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ impl Diagnostic {
366366
}],
367367
}],
368368
msg: msg.to_owned(),
369-
style: SuggestionStyle::HideCodeInline,
369+
style: SuggestionStyle::HideCodeAlways,
370370
applicability,
371371
});
372372
self

src/libsyntax/parse/parser.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -5598,8 +5598,14 @@ impl<'a> Parser<'a> {
55985598

55995599
if !negative_bounds.is_empty() || was_negative {
56005600
let plural = negative_bounds.len() > 1;
5601-
let mut err = self.struct_span_err(negative_bounds,
5602-
"negative trait bounds are not supported");
5601+
let last_span = negative_bounds.last().map(|sp| *sp);
5602+
let mut err = self.struct_span_err(
5603+
negative_bounds,
5604+
"negative trait bounds are not supported",
5605+
);
5606+
if let Some(sp) = last_span {
5607+
err.span_label(sp, "negative trait bounds are not supported");
5608+
}
56035609
if let Some(bound_list) = colon_span {
56045610
let bound_list = bound_list.to(self.prev_span);
56055611
let mut new_bound_list = String::new();
@@ -5612,11 +5618,12 @@ impl<'a> Parser<'a> {
56125618
}
56135619
new_bound_list = new_bound_list.replacen(" +", ":", 1);
56145620
}
5615-
err.span_suggestion_short(bound_list,
5616-
&format!("remove the trait bound{}",
5617-
if plural { "s" } else { "" }),
5618-
new_bound_list,
5619-
Applicability::MachineApplicable);
5621+
err.span_suggestion_hidden(
5622+
bound_list,
5623+
&format!("remove the trait bound{}", if plural { "s" } else { "" }),
5624+
new_bound_list,
5625+
Applicability::MachineApplicable,
5626+
);
56205627
}
56215628
err.emit();
56225629
}

src/test/ui/issues/issue-58857.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ error: negative trait bounds are not supported
22
--> $DIR/issue-58857.rs:4:7
33
|
44
LL | impl<A: !Valid> Conj<A>{}
5-
| ^^^^^^^^ help: remove the trait bound
5+
| ^^^^^^^^ negative trait bounds are not supported
6+
= help: remove the trait bound
67

78
error: aborting due to previous error
89

src/test/ui/parser/issue-33418.fixed

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
// run-rustfix
22

3-
trait Tr {} //~ ERROR negative trait bounds are not supported
4-
trait Tr2: SuperA {} //~ ERROR negative trait bounds are not supported
5-
trait Tr3: SuperB {} //~ ERROR negative trait bounds are not supported
3+
trait Tr {}
4+
//~^ ERROR negative trait bounds are not supported
5+
trait Tr2: SuperA {}
6+
//~^ ERROR negative trait bounds are not supported
7+
trait Tr3: SuperB {}
8+
//~^ ERROR negative trait bounds are not supported
69
trait Tr4: SuperB + SuperD {}
10+
//~^ ERROR negative trait bounds are not supported
711
trait Tr5 {}
12+
//~^ ERROR negative trait bounds are not supported
813

914
trait SuperA {}
1015
trait SuperB {}

src/test/ui/parser/issue-33418.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
// run-rustfix
22

3-
trait Tr: !SuperA {} //~ ERROR negative trait bounds are not supported
4-
trait Tr2: SuperA + !SuperB {} //~ ERROR negative trait bounds are not supported
5-
trait Tr3: !SuperA + SuperB {} //~ ERROR negative trait bounds are not supported
6-
trait Tr4: !SuperA + SuperB //~ ERROR negative trait bounds are not supported
3+
trait Tr: !SuperA {}
4+
//~^ ERROR negative trait bounds are not supported
5+
trait Tr2: SuperA + !SuperB {}
6+
//~^ ERROR negative trait bounds are not supported
7+
trait Tr3: !SuperA + SuperB {}
8+
//~^ ERROR negative trait bounds are not supported
9+
trait Tr4: !SuperA + SuperB
710
+ !SuperC + SuperD {}
8-
trait Tr5: !SuperA //~ ERROR negative trait bounds are not supported
11+
//~^ ERROR negative trait bounds are not supported
12+
trait Tr5: !SuperA
913
+ !SuperB {}
14+
//~^ ERROR negative trait bounds are not supported
1015

1116
trait SuperA {}
1217
trait SuperB {}

src/test/ui/parser/issue-33418.stderr

+20-21
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,40 @@ error: negative trait bounds are not supported
22
--> $DIR/issue-33418.rs:3:9
33
|
44
LL | trait Tr: !SuperA {}
5-
| ^^^^^^^^^ help: remove the trait bound
5+
| ^^^^^^^^^ negative trait bounds are not supported
6+
= help: remove the trait bound
67

78
error: negative trait bounds are not supported
8-
--> $DIR/issue-33418.rs:4:19
9+
--> $DIR/issue-33418.rs:5:19
910
|
1011
LL | trait Tr2: SuperA + !SuperB {}
11-
| ---------^^^^^^^^^
12-
| |
13-
| help: remove the trait bound
12+
| ^^^^^^^^^ negative trait bounds are not supported
13+
= help: remove the trait bound
1414

1515
error: negative trait bounds are not supported
16-
--> $DIR/issue-33418.rs:5:10
16+
--> $DIR/issue-33418.rs:7:10
1717
|
1818
LL | trait Tr3: !SuperA + SuperB {}
19-
| ^^^^^^^^^---------
20-
| |
21-
| help: remove the trait bound
19+
| ^^^^^^^^^ negative trait bounds are not supported
20+
= help: remove the trait bound
2221

2322
error: negative trait bounds are not supported
24-
--> $DIR/issue-33418.rs:6:10
23+
--> $DIR/issue-33418.rs:9:10
2524
|
26-
LL | trait Tr4: !SuperA + SuperB
27-
| __________-^^^^^^^^
28-
LL | | + !SuperC + SuperD {}
29-
| |_____^^^^^^^^^________- help: remove the trait bounds
25+
LL | trait Tr4: !SuperA + SuperB
26+
| ^^^^^^^^^
27+
LL | + !SuperC + SuperD {}
28+
| ^^^^^^^^^ negative trait bounds are not supported
29+
= help: remove the trait bounds
3030

3131
error: negative trait bounds are not supported
32-
--> $DIR/issue-33418.rs:8:10
32+
--> $DIR/issue-33418.rs:12:10
3333
|
34-
LL | trait Tr5: !SuperA
35-
| __________-^^^^^^^^
36-
LL | | + !SuperB {}
37-
| | ^^^^^^^^-
38-
| |_____________|
39-
| help: remove the trait bounds
34+
LL | trait Tr5: !SuperA
35+
| ^^^^^^^^^
36+
LL | + !SuperB {}
37+
| ^^^^^^^^^ negative trait bounds are not supported
38+
= help: remove the trait bounds
4039

4140
error: aborting due to 5 previous errors
4241

0 commit comments

Comments
 (0)