-
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.
Rollup merge of #93977 - compiler-errors:sized-generic-metadata, r=we…
…sleywiser Type params and assoc types have unit metadata if they are sized Extend the logic in `Pointee` projection to ensure that we can satisfy `<T as Pointee>::Metadata = ()` if `T: Sized`. cc: `@SimonSapin` and #93959
- Loading branch information
Showing
5 changed files
with
134 additions
and
15 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
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,22 @@ | ||
// edition:2018 | ||
|
||
#![feature(ptr_metadata)] | ||
#![feature(type_alias_impl_trait)] | ||
|
||
type Opaque = impl std::fmt::Debug + ?Sized; | ||
|
||
fn opaque() -> &'static Opaque { | ||
&[1] as &[i32] | ||
} | ||
|
||
fn a<T: ?Sized>() { | ||
is_thin::<T>(); | ||
//~^ ERROR type mismatch resolving `<T as Pointee>::Metadata == ()` | ||
|
||
is_thin::<Opaque>(); | ||
//~^ ERROR type mismatch resolving `<impl Debug + ?Sized as Pointee>::Metadata == ()` | ||
} | ||
|
||
fn is_thin<T: std::ptr::Pointee<Metadata = ()> + ?Sized>() {} | ||
|
||
fn main() {} |
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,40 @@ | ||
error[E0271]: type mismatch resolving `<T as Pointee>::Metadata == ()` | ||
--> $DIR/pointee-tail-is-generic-errors.rs:13:5 | ||
| | ||
LL | is_thin::<T>(); | ||
| ^^^^^^^^^^^^ expected `()`, found associated type | ||
| | ||
= note: expected unit type `()` | ||
found associated type `<T as Pointee>::Metadata` | ||
= help: consider constraining the associated type `<T as Pointee>::Metadata` to `()` | ||
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html | ||
note: required by a bound in `is_thin` | ||
--> $DIR/pointee-tail-is-generic-errors.rs:20:33 | ||
| | ||
LL | fn is_thin<T: std::ptr::Pointee<Metadata = ()> + ?Sized>() {} | ||
| ^^^^^^^^^^^^^ required by this bound in `is_thin` | ||
|
||
error[E0271]: type mismatch resolving `<impl Debug + ?Sized as Pointee>::Metadata == ()` | ||
--> $DIR/pointee-tail-is-generic-errors.rs:16:5 | ||
| | ||
LL | type Opaque = impl std::fmt::Debug + ?Sized; | ||
| ----------------------------- the found opaque type | ||
... | ||
LL | is_thin::<Opaque>(); | ||
| ^^^^^^^^^^^^^^^^^ expected `()`, found associated type | ||
| | ||
= note: expected unit type `()` | ||
found associated type `<impl Debug + ?Sized as Pointee>::Metadata` | ||
note: required by a bound in `is_thin` | ||
--> $DIR/pointee-tail-is-generic-errors.rs:20:33 | ||
| | ||
LL | fn is_thin<T: std::ptr::Pointee<Metadata = ()> + ?Sized>() {} | ||
| ^^^^^^^^^^^^^ required by this bound in `is_thin` | ||
help: consider constraining the associated type `<impl Debug + ?Sized as Pointee>::Metadata` to `()` | ||
| | ||
LL | type Opaque = impl std::fmt::Debug<Metadata = ()> + ?Sized; | ||
| +++++++++++++++ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0271`. |
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,29 @@ | ||
// check-pass | ||
// edition:2018 | ||
|
||
#![feature(ptr_metadata)] | ||
#![feature(type_alias_impl_trait)] | ||
|
||
type Opaque = impl std::future::Future; | ||
|
||
fn opaque() -> Opaque { | ||
async {} | ||
} | ||
|
||
fn a<T>() { | ||
// type parameter T is known to be sized | ||
is_thin::<T>(); | ||
// tail of ADT (which is a type param) is known to be sized | ||
is_thin::<std::cell::Cell<T>>(); | ||
// opaque type is known to be sized | ||
is_thin::<Opaque>(); | ||
} | ||
|
||
fn a2<T: Iterator>() { | ||
// associated type is known to be sized | ||
is_thin::<T::Item>(); | ||
} | ||
|
||
fn is_thin<T: std::ptr::Pointee<Metadata = ()>>() {} | ||
|
||
fn main() {} |