Skip to content

Bounds in Higher-Ranked Lifetimes in trait objects don't seem to work #23051

@arielb1

Description

@arielb1
use std::marker::CovariantLifetime as CLT;
fn does_not_compile<'b>(y: CLT<'b>) -> Box<for<'s:'b> Fn() -> CLT<'s>> {
    Box::new(move ||y)
}
fn does_compile<'b, 's:'b>(y: CLT<'b>) -> Box<Fn() -> CLT<'s>> {
    Box::new(move ||y)
}
fn main() {}

Error:

<anon>:3:21: 3:22 error: mismatched types:
 expected `core::marker::CovariantLifetime<'s>`,
    found `core::marker::CovariantLifetime<'b>`
(lifetime mismatch) [E0308]
<anon>:3     Box::new(move ||y)
                             ^
<anon>:3:21: 3:22 note: the lifetime 's as defined on the block at 3:20...
<anon>:3     Box::new(move ||y)
                             ^
<anon>:2:72: 4:2 note: ...does not necessarily outlive the lifetime 'b as defined on the block at 2:71
<anon>:2 fn does_not_compile<'b>(y: CLT<'b>) -> Box<for<'s:'b> Fn() -> CLT<'s>> {
<anon>:3     Box::new(move ||y)
<anon>:4 }
error: aborting due to previous error
playpen: application terminated with error code 101

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions