Skip to content

ptr-ptr cast does not work well with lifetimes (lifetime widening) #27214

Description

@arielb1

STR

fn foo<'a>(v: *const &'a ()) {
    let v: *const &'static () = v as *const &'static ();
}

fn main() {}

Expected result

cast will be successful

Actual Result

<anon>:2:33: 2:34 error: mismatched types:
 expected `*const &'static ()`,
    found `*const &'a ()`
(lifetime mismatch) [E0308]
<anon>:2     let v: *const &'static () = v as *const &'static ();
                                         ^
<anon>:2:33: 2:34 help: see the detailed explanation for E0308
<anon>:1:30: 3:2 note: the lifetime 'a as defined on the block at 1:29...
<anon>:1 fn foo<'a>(v: *const &'a ()) {
<anon>:2     let v: *const &'static () = v as *const &'static ();
<anon>:3 }
note: ...does not necessarily outlive the static lifetime
error: aborting due to previous error
playpen: application terminated with error code 101

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-coercionsArea: implicit and explicit `expr as Type` coercionsA-lifetimesArea: Lifetimes / regionsA-raw-pointersArea: raw pointers, MaybeUninit, NonNullA-type-systemArea: Type systemC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions