Skip to content

Commit 4e7c9e6

Browse files
committed
Reject impl Trait bounds in various places where we unconditionally warned since 1.0
1 parent 5e55679 commit 4e7c9e6

21 files changed

+86
-62
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
103103
continue;
104104
}
105105
// There was a `?Trait` bound, but it was not `?Sized`; warn.
106-
self.dcx().span_warn(
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",
Lines changed: 5 additions & 6 deletions
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(...)]`!
Lines changed: 4 additions & 4 deletions
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

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

Lines changed: 5 additions & 5 deletions
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`.
Lines changed: 11 additions & 0 deletions
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() {}
Lines changed: 16 additions & 0 deletions
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

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

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

Lines changed: 4 additions & 4 deletions
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() {

0 commit comments

Comments
 (0)