-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Prefer built-in sized impls (and only sized impls) for rigid types always #138176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,21 @@ | ||
//@ check-pass | ||
//@ revisions: current next | ||
//@ ignore-compare-mode-next-solver (explicit revisions) | ||
//@[next] compile-flags: -Znext-solver | ||
|
||
struct W<T: ?Sized>(T); | ||
|
||
fn is_sized<T: Sized>(x: *const T) {} | ||
|
||
fn dummy<T: ?Sized>() -> *const T { todo!() } | ||
|
||
fn non_param_where_bound<T: ?Sized>() | ||
where | ||
W<T>: Sized, | ||
{ | ||
let x: *const W<_> = dummy(); | ||
is_sized::<W<_>>(x); | ||
let _: *const W<T> = x; | ||
} | ||
|
||
fn main() {} |
This file contains hidden or 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,9 @@ | ||
error[E0282]: type annotations needed | ||
--> $DIR/incomplete-infer-via-sized-wc.rs:15:5 | ||
| | ||
LL | is_sized::<MaybeSized<_>>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `is_sized` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0282`. |
This file contains hidden or 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,9 @@ | ||
error[E0282]: type annotations needed | ||
--> $DIR/incomplete-infer-via-sized-wc.rs:15:5 | ||
| | ||
LL | is_sized::<MaybeSized<_>>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `is_sized` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0282`. |
This file contains hidden or 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,19 @@ | ||
//@ revisions: current next | ||
//@ ignore-compare-mode-next-solver (explicit revisions) | ||
//@[next] compile-flags: -Znext-solver | ||
|
||
// Exercises change in <https://github.com/rust-lang/rust/pull/138176>. | ||
|
||
struct MaybeSized<T: ?Sized>(T); | ||
|
||
fn is_sized<T: Sized>() -> Box<T> { todo!() } | ||
|
||
fn foo<T: ?Sized>() | ||
where | ||
MaybeSized<T>: Sized, | ||
{ | ||
is_sized::<MaybeSized<_>>(); | ||
//~^ ERROR type annotations needed | ||
Comment on lines
+15
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just noting explicitly here that at least part of the point of the crater run was to check that nobody was relying on this inference behavior. |
||
} | ||
|
||
fn main() {} |
28 changes: 28 additions & 0 deletions
28
tests/ui/traits/lifetime-incomplete-prefer-sized-builtin-over-wc-2.rs
This file contains hidden or 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,28 @@ | ||
//@ check-pass | ||
//@ revisions: current next | ||
//@ ignore-compare-mode-next-solver (explicit revisions) | ||
//@[next] compile-flags: -Znext-solver | ||
|
||
// Exercises change in <https://github.com/rust-lang/rust/pull/138176>. | ||
|
||
trait Trait<T>: Sized {} | ||
impl<T> Trait<T> for T {} | ||
|
||
fn is_sized<T: Sized>() {} | ||
|
||
fn normal_ref<'a, 'b, T>() | ||
where | ||
&'a u32: Trait<T>, | ||
{ | ||
is_sized::<&'b u32>(); | ||
} | ||
|
||
struct MyRef<'a, U: ?Sized = ()>(&'a u32, U); | ||
fn my_ref<'a, 'b, T>() | ||
where | ||
MyRef<'a>: Trait<T>, | ||
{ | ||
is_sized::<MyRef<'b>>(); | ||
} | ||
|
||
fn main() {} |
27 changes: 27 additions & 0 deletions
27
tests/ui/traits/lifetime-incomplete-prefer-sized-builtin-over-wc.current.stderr
This file contains hidden or 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,27 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/lifetime-incomplete-prefer-sized-builtin-over-wc.rs:13:23 | ||
| | ||
LL | (MyType<'a, T>,): Sized, | ||
| ^^^^^ lifetime mismatch | ||
| | ||
= note: expected trait `<MyType<'a, T> as Sized>` | ||
found trait `<MyType<'static, T> as Sized>` | ||
note: the lifetime `'a` as defined here... | ||
--> $DIR/lifetime-incomplete-prefer-sized-builtin-over-wc.rs:11:8 | ||
| | ||
LL | fn foo<'a, T: ?Sized>() | ||
| ^^ | ||
= note: ...does not necessarily outlive the static lifetime | ||
|
||
error: lifetime may not live long enough | ||
--> $DIR/lifetime-incomplete-prefer-sized-builtin-over-wc.rs:22:5 | ||
| | ||
LL | fn foo<'a, T: ?Sized>() | ||
| -- lifetime `'a` defined here | ||
... | ||
LL | is_sized::<(MyType<'a, T>,)>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
25 changes: 25 additions & 0 deletions
25
tests/ui/traits/lifetime-incomplete-prefer-sized-builtin-over-wc.next.stderr
This file contains hidden or 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,25 @@ | ||
error[E0478]: lifetime bound not satisfied | ||
--> $DIR/lifetime-incomplete-prefer-sized-builtin-over-wc.rs:13:23 | ||
| | ||
LL | (MyType<'a, T>,): Sized, | ||
| ^^^^^ | ||
| | ||
note: lifetime parameter instantiated with the lifetime `'a` as defined here | ||
--> $DIR/lifetime-incomplete-prefer-sized-builtin-over-wc.rs:11:8 | ||
| | ||
LL | fn foo<'a, T: ?Sized>() | ||
| ^^ | ||
= note: but lifetime parameter must outlive the static lifetime | ||
|
||
error: lifetime may not live long enough | ||
--> $DIR/lifetime-incomplete-prefer-sized-builtin-over-wc.rs:22:5 | ||
| | ||
LL | fn foo<'a, T: ?Sized>() | ||
| -- lifetime `'a` defined here | ||
... | ||
LL | is_sized::<(MyType<'a, T>,)>(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0478`. |
26 changes: 26 additions & 0 deletions
26
tests/ui/traits/lifetime-incomplete-prefer-sized-builtin-over-wc.rs
This file contains hidden or 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,26 @@ | ||
//@ revisions: current next | ||
//@ ignore-compare-mode-next-solver (explicit revisions) | ||
//@[next] compile-flags: -Znext-solver | ||
|
||
// Exercises change in <https://github.com/rust-lang/rust/pull/138176>. | ||
|
||
struct MyType<'a, T: ?Sized>(&'a (), T); | ||
|
||
fn is_sized<T>() {} | ||
|
||
fn foo<'a, T: ?Sized>() | ||
where | ||
(MyType<'a, T>,): Sized, | ||
//[current]~^ ERROR mismatched types | ||
//[next]~^^ ERROR lifetime bound not satisfied | ||
MyType<'static, T>: Sized, | ||
{ | ||
// Preferring the builtin `Sized` impl of tuples | ||
// requires proving `MyType<'a, T>: Sized` which | ||
// can only be proven by using the where-clause, | ||
// adding an unnecessary `'static` constraint. | ||
is_sized::<(MyType<'a, T>,)>(); | ||
//~^ ERROR lifetime may not live long enough | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.