Skip to content

fn(&u8) -> &u8 doesn't implement FnOnce(T) -> T: ReInfer(ReSkolemized(.. error message #19127

Closed
@japaric

Description

@japaric

Small variation of #19126

STR

#![feature(unboxed_closures)]

fn foo<T, F: FnOnce(T) -> T>(f: F) {}
fn id<'a>(input: &'a u8) -> &'a u8 { input }

fn main() {
    foo(id);
}

Output

reskolemized.rs:7:5: 7:8 error: cannot infer an appropriate lifetime due to conflicting requirements
reskolemized.rs:7     foo(id);
                      ^~~
note: first, the lifetime cannot outlive lifetime ReInfer(ReSkolemized(1, BrNamed(DefId { krate: 0, node: 31 }, "'a"(71))))...
reskolemized.rs:7:5: 7:8 note: ...so that trait type parameters matches those specified on the impl (expected `core::ops::Fn<(&u8,), &u8>`, found `core::ops::Fn<(&u8,), &u8>`)
reskolemized.rs:7     foo(id);
                      ^~~
reskolemized.rs:7:5: 7:8 note: but, the lifetime must be valid for the expression at 7:4...
reskolemized.rs:7     foo(id);
                      ^~~
reskolemized.rs:7:5: 7:8 note: ...so that type parameter instantiated with `&u8`, will meet its declared lifetime bounds.
reskolemized.rs:7     foo(id);
                      ^~~
error: aborting due to previous error

Version

#19113 + #18868 on top of bfaa7bc

Not sure if this should work or not, but the error message could be improved.

cc @nikomatsakis

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions