-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lukas Markeffsky
committed
Jan 27, 2024
1 parent
f5e53ec
commit e580ae6
Showing
5 changed files
with
53 additions
and
16 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
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,34 @@ | ||
#![feature(ptr_metadata)] | ||
|
||
use std::ptr::{self, Pointee}; | ||
|
||
fn cast_same_meta<T: ?Sized, U: ?Sized>(ptr: *const T) -> *const U | ||
where | ||
T: Pointee<Metadata = <U as Pointee>::Metadata>, | ||
{ | ||
let (thin, meta) = ptr.to_raw_parts(); | ||
ptr::from_raw_parts(thin, meta) | ||
} | ||
|
||
trait Project { | ||
type Assoc: ?Sized; | ||
} | ||
|
||
struct WrapperProject<T: ?Sized + Project>(T::Assoc); | ||
|
||
// In this example, `WrapperProject<&'a T>` is `Sized` modulo regions, but `?Sized` | ||
// considering regions. | ||
// Because normalization does not consider regions, `WrapperProject<&'a T>::Metadata` | ||
// is normalized to `()` instead of `<&'a T as Project>::Assoc::Metadata` and requires | ||
// `WrapperProject<&'a T>: Sized` and therefore `'a: 'static`. | ||
fn sized_modulo_regions<'a, T: ?Sized + 'static>( | ||
ptr: *const (), | ||
) -> *const WrapperProject<&'a T> | ||
where | ||
for<'b> &'b T: Project, | ||
WrapperProject<&'static T>: Sized, | ||
{ | ||
cast_same_meta(ptr) //~ ERROR lifetime may not live long enough | ||
} | ||
|
||
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,15 @@ | ||
error: lifetime may not live long enough | ||
--> $DIR/pointee-normalize-modulo-regions.rs:31:5 | ||
| | ||
LL | fn sized_modulo_regions<'a, T: ?Sized + 'static>( | ||
| -- lifetime `'a` defined here | ||
... | ||
LL | cast_same_meta(ptr) | ||
| ^^^^^^^^^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static` | ||
| | ||
= note: requirement occurs because of the type `WrapperProject<&T>`, which makes the generic argument `&T` invariant | ||
= note: the struct `WrapperProject<T>` is invariant over the parameter `T` | ||
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance | ||
|
||
error: aborting due to 1 previous error | ||
|