-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
BikeshedIntrinsicFrom
permits lifetime extension
#129097
Comments
@rustbot claim |
It looks like this was just never implemented when support for references was added, rather than this being a case of a subtle bug. I've begun to address this on a branch by modifying I'm emitting outlives obligations in two places. First, where we handle This should be sufficient. The other kinds of obligations emitted by the For some reason, it's not. I've also added these obligations at a top level in This is sufficient for catching 'top level' lifetime extensions; e.g.: fn extend<'a>(src: &'a u8) -> &'static u8 {
transmute(src) // error, yay!
}
fn transmute<Src, Dst>(src: Src) -> Dst
where
Dst: BikeshedIntrinsicFrom<Src>,
{
unsafe { core::intrinsics::transmute_unchecked(src) }
} ...but not nested lifetime extensions, like: fn extend_nested<'a>(src: (&'a u8, u8)) -> (&'static u8, u8) {
transmute(src) // no error :(
} |
Modifies `BikeshedIntrinsicFrom` to forbid lifetime extensions on references. This static check can be opted out of with the `Assume::lifetimes` flag. Fixes rust-lang#129097
Modifies `BikeshedIntrinsicFrom` to forbid lifetime extensions on references. This static check can be opted out of with the `Assume::lifetimes` flag. Fixes rust-lang#129097
Modifies `BikeshedIntrinsicFrom` to forbid lifetime extensions on references. This static check can be opted out of with the `Assume::lifetimes` flag. Fixes rust-lang#129097
Modifies `BikeshedIntrinsicFrom` to forbid lifetime extensions on references. This static check can be opted out of with the `Assume::lifetimes` flag. Fixes rust-lang#129097
Modifies `BikeshedIntrinsicFrom` to forbid lifetime extensions on references. This static check can be opted out of with the `Assume::lifetimes` flag. Fixes rust-lang#129097
…piler-errors safe transmute: check lifetimes Modifies `BikeshedIntrinsicFrom` to forbid lifetime extensions on references. This static check can be opted out of with the `Assume::lifetimes` flag. Fixes rust-lang#129097 Tracking Issue: rust-lang#99571 r? `@compiler-errors`
Rollup merge of rust-lang#129217 - jswrenn:transmute-lifetimes, r=compiler-errors safe transmute: check lifetimes Modifies `BikeshedIntrinsicFrom` to forbid lifetime extensions on references. This static check can be opted out of with the `Assume::lifetimes` flag. Fixes rust-lang#129097 Tracking Issue: rust-lang#99571 r? `@compiler-errors`
I tried this code:
I expected to see this to fail with a compilation error. Instead it succeeded.
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: