Skip to content

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

Closed

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

Activity

  1. ghost added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    on Dec 12, 2014
  2. ghost added
    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
    on Dec 12, 2014
  3. added 3 commits that reference this issue on Dec 12, 2014
    20cbbff
    c59b9b7
  4. added 2 commits that reference this issue on Feb 17, 2025
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-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