-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #87250 - robojumper:87199-sized-relaxation, r=nikomatsakis
Fix implicit Sized relaxation when attempting to relax other, unsupported trait Fixes #87199. Do note that this bug fix causes code like the `ref_arg::<[i32]>(&[5]);` line in the test case in combination with an affected function to no longer compile.
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Regression test for issue #87199, where attempting to relax a bound | ||
// other than the only supported `?Sized` would still cause the compiler | ||
// to assume that the `Sized` bound was relaxed. | ||
|
||
// check-fail | ||
|
||
// Check that these function definitions only emit warnings, not errors | ||
fn arg<T: ?Send>(_: T) {} | ||
//~^ warning: default bound relaxed for a type parameter, but this does nothing | ||
fn ref_arg<T: ?Send>(_: &T) {} | ||
//~^ warning: default bound relaxed for a type parameter, but this does nothing | ||
fn ret() -> impl Iterator<Item = ()> + ?Send { std::iter::empty() } | ||
//~^ warning: default bound relaxed for a type parameter, but this does nothing | ||
|
||
// Check that there's no `?Sized` relaxation! | ||
fn main() { | ||
ref_arg::<i32>(&5); | ||
ref_arg::<[i32]>(&[5]); | ||
//~^ the size for values of type `[i32]` cannot be known | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
warning: default bound relaxed for a type parameter, but this does nothing because the given bound is not a default; only `?Sized` is supported | ||
--> $DIR/issue-87199.rs:8:8 | ||
| | ||
LL | fn arg<T: ?Send>(_: T) {} | ||
| ^ | ||
|
||
warning: default bound relaxed for a type parameter, but this does nothing because the given bound is not a default; only `?Sized` is supported | ||
--> $DIR/issue-87199.rs:10:12 | ||
| | ||
LL | fn ref_arg<T: ?Send>(_: &T) {} | ||
| ^ | ||
|
||
warning: default bound relaxed for a type parameter, but this does nothing because the given bound is not a default; only `?Sized` is supported | ||
--> $DIR/issue-87199.rs:12:13 | ||
| | ||
LL | fn ret() -> impl Iterator<Item = ()> + ?Send { std::iter::empty() } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0277]: the size for values of type `[i32]` cannot be known at compilation time | ||
--> $DIR/issue-87199.rs:18:22 | ||
| | ||
LL | fn ref_arg<T: ?Send>(_: &T) {} | ||
| - required by this bound in `ref_arg` | ||
... | ||
LL | ref_arg::<[i32]>(&[5]); | ||
| ^^^^ doesn't have a size known at compile-time | ||
| | ||
= help: the trait `Sized` is not implemented for `[i32]` | ||
help: consider relaxing the implicit `Sized` restriction | ||
| | ||
LL | fn ref_arg<T: ?Send + ?Sized>(_: &T) {} | ||
| ^^^^^^^^ | ||
|
||
error: aborting due to previous error; 3 warnings emitted | ||
|
||
For more information about this error, try `rustc --explain E0277`. |