Skip to content

Commit 18d727f

Browse files
committed
Tweak unsupported negative trait bounds message
1 parent 690bc57 commit 18d727f

File tree

6 files changed

+55
-38
lines changed

6 files changed

+55
-38
lines changed

src/librustc_errors/diagnostic.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5599,8 +5599,14 @@ impl<'a> Parser<'a> {
55995599

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

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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 8 additions & 3 deletions
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

Lines changed: 10 additions & 5 deletions
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

Lines changed: 20 additions & 21 deletions
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)