Skip to content

HRTB: the trait Fn<(&_,), &_> is not implemented for the type fn(&'a u8) -> &'a u8 #19126

@japaric

Description

@japaric

This came up while trying to move Option to unboxed closures.

src/libstd/path/mod.rs:335:25: 335:49 error: the trait `core::ops::Fn<(&[u8],), core::option::Option<_>>` is not implemented for the type `fn(&'a [u8]) -> core::option::Option<&'a str>`
src/libstd/path/mod.rs:335         self.filename().and_then(str::from_utf8)

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

hrtb.rs:7:5: 7:8 error: the trait `core::ops::Fn<(&_,), &_>` is not implemented for the type `fn(&'a u8) -> &'a u8`
hrtb.rs:7     foo(id);
              ^~~
hrtb.rs:7:5: 7:8 note: the trait `core::ops::Fn` must be implemented because it is required by `foo`
hrtb.rs:7     foo(id);
              ^~~
error: aborting due to previous error

Version

#19113 + #18868 on top of bfaa7bc

cc @aturon blocks #14798
cc @nikomatsakis

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions