Skip to content

Commit 867c6fe

Browse files
committed
Reword diagnostics about relaxed bounds in invalid contexts
1 parent a369915 commit 867c6fe

19 files changed

+79
-75
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,11 +2085,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20852085

20862086
match reason {
20872087
RelaxedBoundForbiddenReason::TraitObjectTy => {
2088-
err("`?Trait` is not permitted in trait object types").emit();
2088+
err("relaxed bounds are not permitted in trait object types").emit();
20892089
return;
20902090
}
20912091
RelaxedBoundForbiddenReason::SuperTrait => {
2092-
let mut diag = err("`?Trait` is not permitted in supertraits");
2092+
let mut diag = err("relaxed bounds are not permitted in supertrait bounds");
20932093
if let Some(def_id) = trait_ref.trait_def_id()
20942094
&& self.tcx.is_lang_item(def_id, hir::LangItem::Sized)
20952095
{
@@ -2103,7 +2103,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21032103
}
21042104
}
21052105

2106-
err("`?Trait` bounds are only permitted at the point where a type parameter is declared")
2106+
err("this relaxed bound is not permitted here")
2107+
.with_note(
2108+
"in this context, relaxed bounds are only allowed on \
2109+
type parameters defined by the closest item",
2110+
)
21072111
.emit();
21082112
}
21092113

tests/ui/associated-item/missing-associated_item_or_field_def_ids.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
fn main() -> dyn Iterator + ?Iterator::advance_by(usize) {
44
//~^ ERROR expected trait, found associated function `Iterator::advance_by`
5-
//~| ERROR `?Trait` is not permitted in trait object types
5+
//~| ERROR relaxed bounds are not permitted in trait object types
66
todo!()
77
}

tests/ui/associated-item/missing-associated_item_or_field_def_ids.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0404]: expected trait, found associated function `Iterator::advance_by`
44
LL | fn main() -> dyn Iterator + ?Iterator::advance_by(usize) {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a trait
66

7-
error[E0658]: `?Trait` is not permitted in trait object types
7+
error[E0658]: relaxed bounds are not permitted in trait object types
88
--> $DIR/missing-associated_item_or_field_def_ids.rs:3:29
99
|
1010
LL | fn main() -> dyn Iterator + ?Iterator::advance_by(usize) {

tests/ui/associated-types/avoid-getting-associated-items-of-undefined-trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ trait Tr {
77
fn main() {
88
let _: dyn Tr + ?Foo<Assoc = ()>;
99
//~^ ERROR: cannot find trait `Foo` in this scope
10-
//~| ERROR: `?Trait` is not permitted in trait object types
10+
//~| ERROR: relaxed bounds are not permitted in trait object types
1111
}

tests/ui/associated-types/avoid-getting-associated-items-of-undefined-trait.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0405]: cannot find trait `Foo` in this scope
44
LL | let _: dyn Tr + ?Foo<Assoc = ()>;
55
| ^^^ not found in this scope
66

7-
error[E0658]: `?Trait` is not permitted in trait object types
7+
error[E0658]: relaxed bounds are not permitted in trait object types
88
--> $DIR/avoid-getting-associated-items-of-undefined-trait.rs:8:21
99
|
1010
LL | let _: dyn Tr + ?Foo<Assoc = ()>;

tests/ui/feature-gates/feature-gate-more-maybe-bounds.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
trait Trait1 {}
44
auto trait Trait2 {}
5-
trait Trait3: ?Trait1 {}
6-
//~^ ERROR `?Trait` is not permitted in supertraits
7-
trait Trait4 where Self: ?Trait1 {}
8-
//~^ ERROR ?Trait` bounds are only permitted at the point where a type parameter is declared
5+
trait Trait3: ?Trait1 {} //~ ERROR relaxed bounds are not permitted in supertrait bounds
6+
trait Trait4 where Self: ?Trait1 {} //~ ERROR this relaxed bound is not permitted here
97

108
fn foo(_: Box<dyn Trait1 + ?Trait2>) {}
11-
//~^ ERROR `?Trait` is not permitted in trait object types
9+
//~^ ERROR relaxed bounds are not permitted in trait object types
1210
fn bar<T: ?Trait1 + ?Trait2>(_: T) {}
1311
//~^ ERROR type parameter has more than one relaxed default bound, only one is supported
1412
//~| ERROR relaxing a default bound only does something for `?Sized`; all other traits are not bound by default

tests/ui/feature-gates/feature-gate-more-maybe-bounds.stderr

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0658]: `?Trait` is not permitted in supertraits
1+
error[E0658]: relaxed bounds are not permitted in supertrait bounds
22
--> $DIR/feature-gate-more-maybe-bounds.rs:5:15
33
|
44
LL | trait Trait3: ?Trait1 {}
@@ -7,17 +7,18 @@ LL | trait Trait3: ?Trait1 {}
77
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
88
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
99

10-
error[E0658]: `?Trait` bounds are only permitted at the point where a type parameter is declared
11-
--> $DIR/feature-gate-more-maybe-bounds.rs:7:26
10+
error[E0658]: this relaxed bound is not permitted here
11+
--> $DIR/feature-gate-more-maybe-bounds.rs:6:26
1212
|
1313
LL | trait Trait4 where Self: ?Trait1 {}
1414
| ^^^^^^^
1515
|
1616
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
1717
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
18+
= note: in this context, relaxed bounds are only allowed on type parameters defined by the closest item
1819

19-
error[E0658]: `?Trait` is not permitted in trait object types
20-
--> $DIR/feature-gate-more-maybe-bounds.rs:10:28
20+
error[E0658]: relaxed bounds are not permitted in trait object types
21+
--> $DIR/feature-gate-more-maybe-bounds.rs:8:28
2122
|
2223
LL | fn foo(_: Box<dyn Trait1 + ?Trait2>) {}
2324
| ^^^^^^^
@@ -26,7 +27,7 @@ LL | fn foo(_: Box<dyn Trait1 + ?Trait2>) {}
2627
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2728

2829
error[E0203]: type parameter has more than one relaxed default bound, only one is supported
29-
--> $DIR/feature-gate-more-maybe-bounds.rs:12:11
30+
--> $DIR/feature-gate-more-maybe-bounds.rs:10:11
3031
|
3132
LL | fn bar<T: ?Trait1 + ?Trait2>(_: T) {}
3233
| ^^^^^^^ ^^^^^^^
@@ -35,31 +36,31 @@ LL | fn bar<T: ?Trait1 + ?Trait2>(_: T) {}
3536
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
3637

3738
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
38-
--> $DIR/feature-gate-more-maybe-bounds.rs:12:11
39+
--> $DIR/feature-gate-more-maybe-bounds.rs:10:11
3940
|
4041
LL | fn bar<T: ?Trait1 + ?Trait2>(_: T) {}
4142
| ^^^^^^^
4243

4344
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
44-
--> $DIR/feature-gate-more-maybe-bounds.rs:12:21
45+
--> $DIR/feature-gate-more-maybe-bounds.rs:10:21
4546
|
4647
LL | fn bar<T: ?Trait1 + ?Trait2>(_: T) {}
4748
| ^^^^^^^
4849

4950
error[E0203]: type parameter has more than one relaxed default bound, only one is supported
50-
--> $DIR/feature-gate-more-maybe-bounds.rs:19:11
51+
--> $DIR/feature-gate-more-maybe-bounds.rs:17:11
5152
|
5253
LL | fn baz<T: ?Trait + ?Trait>(_ : T) {}
5354
| ^^^^^^ ^^^^^^
5455

5556
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
56-
--> $DIR/feature-gate-more-maybe-bounds.rs:19:11
57+
--> $DIR/feature-gate-more-maybe-bounds.rs:17:11
5758
|
5859
LL | fn baz<T: ?Trait + ?Trait>(_ : T) {}
5960
| ^^^^^^
6061

6162
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
62-
--> $DIR/feature-gate-more-maybe-bounds.rs:19:20
63+
--> $DIR/feature-gate-more-maybe-bounds.rs:17:20
6364
|
6465
LL | fn baz<T: ?Trait + ?Trait>(_ : T) {}
6566
| ^^^^^^

tests/ui/maybe-bounds.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
trait Tr: ?Sized {}
2-
//~^ ERROR `?Trait` is not permitted in supertraits
2+
//~^ ERROR relaxed bounds are not permitted in supertrait bounds
33

44
type A1 = dyn Tr + (?Sized);
5-
//~^ ERROR `?Trait` is not permitted in trait object types
5+
//~^ ERROR relaxed bounds are not permitted in trait object types
66
type A2 = dyn for<'a> Tr + (?Sized);
7-
//~^ ERROR `?Trait` is not permitted in trait object types
7+
//~^ ERROR relaxed bounds are not permitted in trait object types
88

99
fn main() {}

tests/ui/maybe-bounds.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0658]: `?Trait` is not permitted in supertraits
1+
error[E0658]: relaxed bounds are not permitted in supertrait bounds
22
--> $DIR/maybe-bounds.rs:1:11
33
|
44
LL | trait Tr: ?Sized {}
@@ -8,7 +8,7 @@ LL | trait Tr: ?Sized {}
88
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
99
= note: traits are `?Sized` by default
1010

11-
error[E0658]: `?Trait` is not permitted in trait object types
11+
error[E0658]: relaxed bounds are not permitted in trait object types
1212
--> $DIR/maybe-bounds.rs:4:20
1313
|
1414
LL | type A1 = dyn Tr + (?Sized);
@@ -17,7 +17,7 @@ LL | type A1 = dyn Tr + (?Sized);
1717
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
1818
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1919

20-
error[E0658]: `?Trait` is not permitted in trait object types
20+
error[E0658]: relaxed bounds are not permitted in trait object types
2121
--> $DIR/maybe-bounds.rs:6:28
2222
|
2323
LL | type A2 = dyn for<'a> Tr + (?Sized);

tests/ui/parser/trait-object-trait-parens.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ fn f<T: (Copy) + (?Sized) + (for<'a> Trait<'a>)>() {}
66

77
fn main() {
88
let _: Box<(Obj) + (?Sized) + (for<'a> Trait<'a>)>;
9-
//~^ ERROR `?Trait` is not permitted in trait object types
9+
//~^ ERROR relaxed bounds are not permitted in trait object types
1010
//~| ERROR only auto traits can be used as additional traits
1111
//~| WARN trait objects without an explicit `dyn` are deprecated
1212
//~| WARN this is accepted in the current edition
1313
let _: Box<?Sized + (for<'a> Trait<'a>) + (Obj)>;
14-
//~^ ERROR `?Trait` is not permitted in trait object types
14+
//~^ ERROR relaxed bounds are not permitted in trait object types
1515
//~| ERROR only auto traits can be used as additional traits
1616
//~| WARN trait objects without an explicit `dyn` are deprecated
1717
//~| WARN this is accepted in the current edition
1818
let _: Box<for<'a> Trait<'a> + (Obj) + (?Sized)>;
19-
//~^ ERROR `?Trait` is not permitted in trait object types
19+
//~^ ERROR relaxed bounds are not permitted in trait object types
2020
//~| ERROR only auto traits can be used as additional traits
2121
//~| WARN trait objects without an explicit `dyn` are deprecated
2222
//~| WARN this is accepted in the current edition

0 commit comments

Comments
 (0)