Skip to content

Commit 4156473

Browse files
committed
Add test for unsupported bound relaxation with incorrect behavior
1 parent 3ab6b60 commit 4156473

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

src/test/ui/issues/issue-87199.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Regression test for issue #87199, where attempting to relax a bound
2+
// other than the only supported `?Sized` would still cause the compiler
3+
// to assume that the `Sized` bound was relaxed.
4+
5+
// check-fail
6+
7+
// Check that these function definitions only emit warnings, not errors
8+
fn arg<T: ?Send>(_: T) {}
9+
//~^ warning: default bound relaxed for a type parameter, but this does nothing
10+
//~^^ the size for values of type `T`
11+
fn ref_arg<T: ?Send>(_: &T) {}
12+
//~^ warning: default bound relaxed for a type parameter, but this does nothing
13+
fn ret() -> impl Iterator<Item = ()> + ?Send { std::iter::empty() }
14+
//~^ warning: default bound relaxed for a type parameter, but this does nothing
15+
//~^^ the size for values of type `impl Iterator+?Sized` cannot be known
16+
17+
// Check that there's no `?Sized` relaxation!
18+
fn main() {
19+
ref_arg::<i32>(&5);
20+
ref_arg::<[i32]>(&[5]);
21+
}

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
warning: default bound relaxed for a type parameter, but this does nothing because the given bound is not a default; only `?Sized` is supported
2+
--> $DIR/issue-87199.rs:8:8
3+
|
4+
LL | fn arg<T: ?Send>(_: T) {}
5+
| ^
6+
7+
warning: default bound relaxed for a type parameter, but this does nothing because the given bound is not a default; only `?Sized` is supported
8+
--> $DIR/issue-87199.rs:11:12
9+
|
10+
LL | fn ref_arg<T: ?Send>(_: &T) {}
11+
| ^
12+
13+
warning: default bound relaxed for a type parameter, but this does nothing because the given bound is not a default; only `?Sized` is supported
14+
--> $DIR/issue-87199.rs:13:13
15+
|
16+
LL | fn ret() -> impl Iterator<Item = ()> + ?Send { std::iter::empty() }
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18+
19+
error[E0277]: the size for values of type `impl Iterator+?Sized` cannot be known at compilation time
20+
--> $DIR/issue-87199.rs:13:13
21+
|
22+
LL | fn ret() -> impl Iterator<Item = ()> + ?Send { std::iter::empty() }
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
24+
|
25+
= help: the trait `Sized` is not implemented for `impl Iterator+?Sized`
26+
= note: the return type of a function must have a statically known size
27+
28+
error[E0277]: the size for values of type `T` cannot be known at compilation time
29+
--> $DIR/issue-87199.rs:8:18
30+
|
31+
LL | fn arg<T: ?Send>(_: T) {}
32+
| - ^ doesn't have a size known at compile-time
33+
| |
34+
| this type parameter needs to be `std::marker::Sized`
35+
|
36+
= help: unsized fn params are gated as an unstable feature
37+
help: function arguments must have a statically known size, borrowed types always have a known size
38+
|
39+
LL | fn arg<T: ?Send>(_: &T) {}
40+
| ^
41+
42+
error: aborting due to 2 previous errors; 3 warnings emitted
43+
44+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)