Skip to content
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

Variance issue with higher kinded lifetimes #28279

Closed
ebfull opened this issue Sep 7, 2015 · 1 comment
Closed

Variance issue with higher kinded lifetimes #28279

ebfull opened this issue Sep 7, 2015 · 1 comment
Labels
A-lifetimes Area: Lifetimes / regions

Comments

@ebfull
Copy link
Contributor

ebfull commented Sep 7, 2015

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

@huonw huonw added the A-lifetimes Area: Lifetimes / regions label Sep 7, 2015
@arielb1
Copy link
Contributor

arielb1 commented Sep 7, 2015

Seems like some terrible LUB failure:

common_supertype(
    *mut for<'a> core::ops::Fn(&'a usize),
    *mut for<'a> core::ops::Fn(&'a usize) + 'static
) = *mut core::ops::Fn(&usize)

cc @nikomatsakis

bors added a commit that referenced this issue Sep 22, 2015
Fixes #28279.

Currently

`common_supertype(*mut for<'a> Fn(&'a usize), *mut for<'a> Fn(&'a usize) + 'static)`

equals `*mut Fn(&usize)` which seems to be caused by `higher_ranked_sub()` allowing region variables to escape the comparison. This prevents inference from working properly with stuff like `Rc<Fn(&T)>`.

r? @nikomatsakis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions
Projects
None yet
Development

No branches or pull requests

3 participants