Skip to content

Commit d8ab552

Browse files
committed
Reword diagnostics about relaxed bounds in invalid contexts
1 parent a4dd910 commit d8ab552

19 files changed

+115
-180
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/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

tests/ui/parser/trait-object-trait-parens.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 trait object types
1+
error[E0658]: relaxed bounds are not permitted in trait object types
22
--> $DIR/trait-object-trait-parens.rs:8:24
33
|
44
LL | let _: Box<(Obj) + (?Sized) + (for<'a> Trait<'a>)>;
@@ -7,7 +7,7 @@ LL | let _: Box<(Obj) + (?Sized) + (for<'a> Trait<'a>)>;
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` is not permitted in trait object types
10+
error[E0658]: relaxed bounds are not permitted in trait object types
1111
--> $DIR/trait-object-trait-parens.rs:13:16
1212
|
1313
LL | let _: Box<?Sized + (for<'a> Trait<'a>) + (Obj)>;
@@ -16,7 +16,7 @@ LL | let _: Box<?Sized + (for<'a> Trait<'a>) + (Obj)>;
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
1818

19-
error[E0658]: `?Trait` is not permitted in trait object types
19+
error[E0658]: relaxed bounds are not permitted in trait object types
2020
--> $DIR/trait-object-trait-parens.rs:18:44
2121
|
2222
LL | let _: Box<for<'a> Trait<'a> + (Obj) + (?Sized)>;

tests/ui/sized-hierarchy/default-supertrait.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ use std::marker::{MetaSized, PointeeSized};
66
trait Sized_: Sized { }
77

88
trait NegSized: ?Sized { }
9-
//~^ ERROR `?Trait` is not permitted in supertraits
9+
//~^ ERROR relaxed bounds are not permitted in supertrait bounds
1010

1111
trait MetaSized_: MetaSized { }
1212

1313
trait NegMetaSized: ?MetaSized { }
14-
//~^ ERROR `?Trait` is not permitted in supertraits
14+
//~^ ERROR relaxed bounds are not permitted in supertrait bounds
1515

1616

1717
trait PointeeSized_: PointeeSized { }
1818

1919
trait NegPointeeSized: ?PointeeSized { }
20-
//~^ ERROR `?Trait` is not permitted in supertraits
20+
//~^ ERROR relaxed bounds are not permitted in supertrait bounds
2121

2222
trait Bare {}
2323

tests/ui/sized-hierarchy/default-supertrait.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/default-supertrait.rs:8:17
33
|
44
LL | trait NegSized: ?Sized { }
@@ -8,7 +8,7 @@ LL | trait NegSized: ?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 supertraits
11+
error[E0658]: relaxed bounds are not permitted in supertrait bounds
1212
--> $DIR/default-supertrait.rs:13:21
1313
|
1414
LL | trait NegMetaSized: ?MetaSized { }
@@ -17,7 +17,7 @@ LL | trait NegMetaSized: ?MetaSized { }
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 supertraits
20+
error[E0658]: relaxed bounds are not permitted in supertrait bounds
2121
--> $DIR/default-supertrait.rs:19:24
2222
|
2323
LL | trait NegPointeeSized: ?PointeeSized { }

tests/ui/traits/maybe-trait-bounds-forbidden-locations.rs

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/ui/traits/maybe-trait-bounds-forbidden-locations.stderr

Lines changed: 0 additions & 31 deletions
This file was deleted.

tests/ui/traits/wf-object/maybe-bound.rs

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/ui/traits/wf-object/maybe-bound.stderr

Lines changed: 0 additions & 48 deletions
This file was deleted.

tests/ui/traits/wf-object/only-maybe-bound.rs

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

33
type _0 = dyn ?Sized;
44
//~^ ERROR at least one trait is required for an object type [E0224]
5-
//~| ERROR ?Trait` is not permitted in trait object types
5+
//~| ERROR relaxed bounds are not permitted in trait object types
66

77
fn main() {}

tests/ui/traits/wf-object/only-maybe-bound.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0658]: `?Trait` is not permitted in trait object types
1+
error[E0658]: relaxed bounds are not permitted in trait object types
22
--> $DIR/only-maybe-bound.rs:3:15
33
|
44
LL | type _0 = dyn ?Sized;

0 commit comments

Comments
 (0)