Skip to content

Variance issue with higher kinded lifetimes #28279

@ebfull

Description

@ebfull
fn test() -> *mut for<'a> Fn(&'a usize) { // change to *const and it'll work
    if let Some(_) = Some(1) { // not sure why I have to do this
        loop{}
    } else {
        loop{}
    }
}

fn main() {}
<anon>:2:5: 6:6 error: cannot infer an appropriate lifetime for lifetime parameter 'a in generic type due to conflicting requirements
<anon>:2     if let Some(_) = Some(1) { // not sure why I have to do this
<anon>:3         loop{}
<anon>:4     } else {
<anon>:5         loop{}
<anon>:6     }
note: in expansion of if let expansion
<anon>:2:5: 6:6 note: expansion site
note: first, the lifetime cannot outlive lifetime ReSkolemized(0, BrNamed(0:7, 'a(61)))...
<anon>:2:5: 6:6 note: ...so that types are compatible (expected `for<'a> core::ops::Fn(&'a usize) + 'static`, found `core::ops::Fn(&usize) + 'static`)
<anon>:2     if let Some(_) = Some(1) { // not sure why I have to do this
<anon>:3         loop{}
<anon>:4     } else {
<anon>:5         loop{}
<anon>:6     }
note: in expansion of if let expansion
<anon>:2:5: 6:6 note: expansion site
<anon>:2:5: 6:6 note: but, the lifetime must be valid for the if let at 2:4...
<anon>:2     if let Some(_) = Some(1) { // not sure why I have to do this
<anon>:3         loop{}
<anon>:4     } else {
<anon>:5         loop{}
<anon>:6     }
note: in expansion of if let expansion
<anon>:2:5: 6:6 note: expansion site
<anon>:2:5: 6:6 note: ...so type `*mut core::ops::Fn(&usize)` of expression is valid during the expression
<anon>:2     if let Some(_) = Some(1) { // not sure why I have to do this
<anon>:3         loop{}
<anon>:4     } else {
<anon>:5         loop{}
<anon>:6     }
note: in expansion of if let expansion
<anon>:2:5: 6:6 note: expansion site
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'assertion failed: !ty.needs_infer()', ../src/librustc_typeck/lib.rs:155

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions