Skip to content

Commit 6b9b0a0

Browse files
authored
Rollup merge of #135841 - oli-obk:push-qxlnokwrkkym, r=compiler-errors
Reject `?Trait` bounds in various places where we unconditionally warned since 1.0 fixes #135730 fixes #135809 Also a breaking change, so let's see what crater says. This has been an unconditional warning since *before* 1.0
2 parents a53cd3c + c294da3 commit 6b9b0a0

21 files changed

+87
-63
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
102102
seen_sized_unbound = true;
103103
continue;
104104
}
105-
// There was a `?Trait` bound, but it was not `?Sized`; warn.
106-
self.dcx().span_warn(
105+
// There was a `?Trait` bound, but it was not `?Sized`
106+
self.dcx().span_err(
107107
unbound.span,
108108
"relaxing a default bound only does something for `?Sized`; \
109109
all other traits are not bound by default",
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// ignore-tidy-linelength
22
//! Check that `-A warnings` cli flag applies to non-lint warnings as well.
33
//!
4-
//! This test tries to exercise that by checking that the "relaxing a default bound only does
5-
//! something for `?Sized`; all other traits are not bound by default" non-lint warning (normally
4+
//! This test tries to exercise that by checking that a non-lint warning (normally
65
//! warn-by-default) is suppressed if the `-A warnings` cli flag is passed.
76
//!
87
//! Take special note that `warnings` is a special pseudo lint group in relationship to non-lint
@@ -14,14 +13,14 @@
1413
//! - Original impl PR: <https://github.com/rust-lang/rust/pull/21248>.
1514
//! - RFC 507 "Release channels":
1615
//! <https://github.com/rust-lang/rfcs/blob/c017755b9bfa0421570d92ba38082302e0f3ad4f/text/0507-release-channels.md>.
17-
#![crate_type = "lib"]
16+
#![feature(rustc_attrs)]
1817

1918
//@ revisions: without_flag with_flag
2019

2120
//@[with_flag] compile-flags: -Awarnings
2221

2322
//@ check-pass
2423

25-
pub trait Trait {}
26-
pub fn f<T: ?Trait>() {}
27-
//[without_flag]~^ WARN relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
24+
#[rustc_error(warn)]
25+
fn main() {}
26+
//[without_flag]~^ WARN unexpected annotation used with `#[rustc_error(...)]`!
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
2-
--> $DIR/allow-non-lint-warnings.rs:26:13
1+
warning: unexpected annotation used with `#[rustc_error(...)]`!
2+
--> $DIR/allow-non-lint-warnings.rs:25:1
33
|
4-
LL | pub fn f<T: ?Trait>() {}
5-
| ^^^^^^
4+
LL | fn main() {}
5+
| ^^^^^^^^^
66

77
warning: 1 warning emitted
88

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ fn foo(_: Box<dyn Trait1 + ?Trait2>) {}
1111
//~^ ERROR `?Trait` is not permitted in trait object types
1212
fn bar<T: ?Trait1 + ?Trait2>(_: T) {}
1313
//~^ ERROR type parameter has more than one relaxed default bound, only one is supported
14-
//~| WARN relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
15-
//~| WARN relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
14+
//~| ERROR relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
15+
//~| ERROR relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
1616

1717
trait Trait {}
1818
// Do not suggest `#![feature(more_maybe_bounds)]` for repetitions
1919
fn baz<T: ?Trait + ?Trait>(_ : T) {}
2020
//~^ ERROR type parameter has more than one relaxed default bound, only one is supported
21-
//~| WARN relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
22-
//~| WARN relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
21+
//~| ERROR relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
22+
//~| ERROR relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
2323

2424
fn main() {}

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ LL | fn bar<T: ?Trait1 + ?Trait2>(_: T) {}
3535
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
3636
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
3737

38-
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
38+
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
3939
--> $DIR/feature-gate-more-maybe-bounds.rs:12:11
4040
|
4141
LL | fn bar<T: ?Trait1 + ?Trait2>(_: T) {}
4242
| ^^^^^^^
4343

44-
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
44+
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
4545
--> $DIR/feature-gate-more-maybe-bounds.rs:12:21
4646
|
4747
LL | fn bar<T: ?Trait1 + ?Trait2>(_: T) {}
@@ -53,19 +53,19 @@ error[E0203]: type parameter has more than one relaxed default bound, only one i
5353
LL | fn baz<T: ?Trait + ?Trait>(_ : T) {}
5454
| ^^^^^^ ^^^^^^
5555

56-
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
56+
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
5757
--> $DIR/feature-gate-more-maybe-bounds.rs:19:11
5858
|
5959
LL | fn baz<T: ?Trait + ?Trait>(_ : T) {}
6060
| ^^^^^^
6161

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

68-
error: aborting due to 5 previous errors; 4 warnings emitted
68+
error: aborting due to 9 previous errors
6969

7070
Some errors have detailed explanations: E0203, E0658.
7171
For more information about an error, try `rustc --explain E0203`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//! Regression test for ICE https://github.com/rust-lang/rust/issues/135730
2+
//! This used
3+
4+
use std::future::Future;
5+
fn foo() -> impl ?Future<Output = impl Send> {
6+
//~^ ERROR: relaxing a default bound only does something for `?Sized`
7+
//~| ERROR: relaxing a default bound only does something for `?Sized`
8+
()
9+
}
10+
11+
pub fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
2+
--> $DIR/opt-out-bound-not-satisfied.rs:5:18
3+
|
4+
LL | fn foo() -> impl ?Future<Output = impl Send> {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
8+
--> $DIR/opt-out-bound-not-satisfied.rs:5:18
9+
|
10+
LL | fn foo() -> impl ?Future<Output = impl Send> {
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
|
13+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
14+
15+
error: aborting due to 2 previous errors
16+

tests/ui/issues/issue-37534.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
struct Foo<T: ?Hash> {}
22
//~^ ERROR expected trait, found derive macro `Hash`
3-
//~| WARN relaxing a default bound only does something for `?Sized`
3+
//~| ERROR relaxing a default bound only does something for `?Sized`
44

55
fn main() {}

tests/ui/issues/issue-37534.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ help: consider importing this trait instead
99
LL + use std::hash::Hash;
1010
|
1111

12-
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
12+
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
1313
--> $DIR/issue-37534.rs:1:15
1414
|
1515
LL | struct Foo<T: ?Hash> {}
1616
| ^^^^^
1717

18-
error: aborting due to 1 previous error; 1 warning emitted
18+
error: aborting due to 2 previous errors
1919

2020
For more information about this error, try `rustc --explain E0404`.

tests/ui/issues/issue-87199.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
// Check that these function definitions only emit warnings, not errors
88
fn arg<T: ?Send>(_: T) {}
9-
//~^ warning: relaxing a default bound only does something for `?Sized`
9+
//~^ ERROR: relaxing a default bound only does something for `?Sized`
1010
fn ref_arg<T: ?Send>(_: &T) {}
11-
//~^ warning: relaxing a default bound only does something for `?Sized`
11+
//~^ ERROR: relaxing a default bound only does something for `?Sized`
1212
fn ret() -> impl Iterator<Item = ()> + ?Send { std::iter::empty() }
13-
//~^ warning: relaxing a default bound only does something for `?Sized`
14-
//~| warning: relaxing a default bound only does something for `?Sized`
13+
//~^ ERROR: relaxing a default bound only does something for `?Sized`
14+
//~| ERROR: relaxing a default bound only does something for `?Sized`
1515

1616
// Check that there's no `?Sized` relaxation!
1717
fn main() {

tests/ui/issues/issue-87199.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
1+
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
22
--> $DIR/issue-87199.rs:8:11
33
|
44
LL | fn arg<T: ?Send>(_: T) {}
55
| ^^^^^
66

7-
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
7+
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
88
--> $DIR/issue-87199.rs:10:15
99
|
1010
LL | fn ref_arg<T: ?Send>(_: &T) {}
1111
| ^^^^^
1212

13-
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
13+
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
1414
--> $DIR/issue-87199.rs:12:40
1515
|
1616
LL | fn ret() -> impl Iterator<Item = ()> + ?Send { std::iter::empty() }
1717
| ^^^^^
1818

19-
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
19+
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
2020
--> $DIR/issue-87199.rs:12:40
2121
|
2222
LL | fn ret() -> impl Iterator<Item = ()> + ?Send { std::iter::empty() }
@@ -41,6 +41,6 @@ help: consider relaxing the implicit `Sized` restriction
4141
LL | fn ref_arg<T: ?Send + ?Sized>(_: &T) {}
4242
| ++++++++
4343

44-
error: aborting due to 1 previous error; 4 warnings emitted
44+
error: aborting due to 5 previous errors
4545

4646
For more information about this error, try `rustc --explain E0277`.

tests/ui/trait-bounds/maybe-bound-has-path-args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ trait Trait {}
22

33
fn test<T: ?self::<i32>::Trait>() {}
44
//~^ ERROR type arguments are not allowed on module `maybe_bound_has_path_args`
5-
//~| WARN relaxing a default bound only does something for `?Sized`
5+
//~| ERROR relaxing a default bound only does something for `?Sized`
66

77
fn main() {}

tests/ui/trait-bounds/maybe-bound-has-path-args.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
1+
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
22
--> $DIR/maybe-bound-has-path-args.rs:3:12
33
|
44
LL | fn test<T: ?self::<i32>::Trait>() {}
@@ -12,6 +12,6 @@ LL | fn test<T: ?self::<i32>::Trait>() {}
1212
| |
1313
| not allowed on module `maybe_bound_has_path_args`
1414

15-
error: aborting due to 1 previous error; 1 warning emitted
15+
error: aborting due to 2 previous errors
1616

1717
For more information about this error, try `rustc --explain E0109`.

tests/ui/trait-bounds/maybe-bound-with-assoc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ trait HasAssoc {
22
type Assoc;
33
}
44
fn hasassoc<T: ?HasAssoc<Assoc = ()>>() {}
5-
//~^ WARN relaxing a default bound
5+
//~^ ERROR relaxing a default bound
66

77
trait NoAssoc {}
88
fn noassoc<T: ?NoAssoc<Missing = ()>>() {}
9-
//~^ WARN relaxing a default bound
9+
//~^ ERROR relaxing a default bound
1010
//~| ERROR associated type `Missing` not found for `NoAssoc`
1111

1212
fn main() {}

tests/ui/trait-bounds/maybe-bound-with-assoc.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
1+
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
22
--> $DIR/maybe-bound-with-assoc.rs:4:16
33
|
44
LL | fn hasassoc<T: ?HasAssoc<Assoc = ()>>() {}
55
| ^^^^^^^^^^^^^^^^^^^^^
66

7-
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
7+
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
88
--> $DIR/maybe-bound-with-assoc.rs:8:15
99
|
1010
LL | fn noassoc<T: ?NoAssoc<Missing = ()>>() {}
@@ -16,6 +16,6 @@ error[E0220]: associated type `Missing` not found for `NoAssoc`
1616
LL | fn noassoc<T: ?NoAssoc<Missing = ()>>() {}
1717
| ^^^^^^^ associated type `Missing` not found
1818

19-
error: aborting due to 1 previous error; 2 warnings emitted
19+
error: aborting due to 3 previous errors
2020

2121
For more information about this error, try `rustc --explain E0220`.

tests/ui/traits/maybe-polarity-pass.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//@ check-pass
2-
31
#![feature(auto_traits)]
42
#![feature(more_maybe_bounds)]
53
#![feature(negative_impls)]
@@ -12,9 +10,9 @@ trait Trait4 where Self: Trait1 {}
1210

1311
fn foo(_: Box<(dyn Trait3 + ?Trait2)>) {}
1412
fn bar<T: ?Sized + ?Trait2 + ?Trait1 + ?Trait4>(_: &T) {}
15-
//~^ WARN relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
16-
//~| WARN relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
17-
//~| WARN relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
13+
//~^ ERROR relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
14+
//~| ERROR relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
15+
//~| ERROR relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
1816

1917
struct S;
2018
impl !Trait2 for S {}
+7-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
2-
--> $DIR/maybe-polarity-pass.rs:14:20
1+
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
2+
--> $DIR/maybe-polarity-pass.rs:12:20
33
|
44
LL | fn bar<T: ?Sized + ?Trait2 + ?Trait1 + ?Trait4>(_: &T) {}
55
| ^^^^^^^
66

7-
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
8-
--> $DIR/maybe-polarity-pass.rs:14:30
7+
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
8+
--> $DIR/maybe-polarity-pass.rs:12:30
99
|
1010
LL | fn bar<T: ?Sized + ?Trait2 + ?Trait1 + ?Trait4>(_: &T) {}
1111
| ^^^^^^^
1212

13-
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
14-
--> $DIR/maybe-polarity-pass.rs:14:40
13+
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
14+
--> $DIR/maybe-polarity-pass.rs:12:40
1515
|
1616
LL | fn bar<T: ?Sized + ?Trait2 + ?Trait1 + ?Trait4>(_: &T) {}
1717
| ^^^^^^^
1818

19-
warning: 3 warnings emitted
19+
error: aborting due to 3 previous errors
2020

tests/ui/traits/maybe-polarity-repeated.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
trait Trait {}
44
fn foo<T: ?Trait + ?Trait>(_: T) {}
55
//~^ ERROR type parameter has more than one relaxed default bound, only one is supported
6-
//~| WARN relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
7-
//~| WARN relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
6+
//~| ERROR relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
7+
//~| ERROR relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
88

99
fn main() {}

tests/ui/traits/maybe-polarity-repeated.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ error[E0203]: type parameter has more than one relaxed default bound, only one i
44
LL | fn foo<T: ?Trait + ?Trait>(_: T) {}
55
| ^^^^^^ ^^^^^^
66

7-
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
7+
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
88
--> $DIR/maybe-polarity-repeated.rs:4:11
99
|
1010
LL | fn foo<T: ?Trait + ?Trait>(_: T) {}
1111
| ^^^^^^
1212

13-
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
13+
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
1414
--> $DIR/maybe-polarity-repeated.rs:4:20
1515
|
1616
LL | fn foo<T: ?Trait + ?Trait>(_: T) {}
1717
| ^^^^^^
1818

19-
error: aborting due to 1 previous error; 2 warnings emitted
19+
error: aborting due to 3 previous errors
2020

2121
For more information about this error, try `rustc --explain E0203`.

tests/ui/unsized/maybe-bounds-where.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ trait Trait<'a> {}
1111

1212
struct S4<T>(T) where for<'a> T: ?Trait<'a>;
1313
//~^ ERROR `?Trait` bounds are only permitted at the point where a type parameter is declared
14-
//~| WARN relaxing a default bound only does something for `?Sized`
14+
//~| ERROR relaxing a default bound only does something for `?Sized`
1515

1616
struct S5<T>(*const T) where T: ?Trait<'static> + ?Sized;
1717
//~^ ERROR type parameter has more than one relaxed default bound
18-
//~| WARN relaxing a default bound only does something for `?Sized`
18+
//~| ERROR relaxing a default bound only does something for `?Sized`
1919

2020
impl<T> S1<T> {
2121
fn f() where T: ?Sized {}

tests/ui/unsized/maybe-bounds-where.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ LL | fn f() where T: ?Sized {}
4343
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
4444
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
4545

46-
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
46+
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
4747
--> $DIR/maybe-bounds-where.rs:12:34
4848
|
4949
LL | struct S4<T>(T) where for<'a> T: ?Trait<'a>;
@@ -58,13 +58,13 @@ LL | struct S5<T>(*const T) where T: ?Trait<'static> + ?Sized;
5858
= help: add `#![feature(more_maybe_bounds)]` to the crate attributes to enable
5959
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
6060

61-
warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
61+
error: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default
6262
--> $DIR/maybe-bounds-where.rs:16:33
6363
|
6464
LL | struct S5<T>(*const T) where T: ?Trait<'static> + ?Sized;
6565
| ^^^^^^^^^^^^^^^
6666

67-
error: aborting due to 6 previous errors; 2 warnings emitted
67+
error: aborting due to 8 previous errors
6868

6969
Some errors have detailed explanations: E0203, E0658.
7070
For more information about an error, try `rustc --explain E0203`.

0 commit comments

Comments
 (0)