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

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

Closed
japaric opened this issue Nov 20, 2014 · 4 comments

Comments

@japaric
Copy link
Member

japaric commented Nov 20, 2014

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

@nikomatsakis
Copy link
Contributor

Hmm, yes, the existing semi-hokey impls for fn are not going to work with higher-ranked trait bounds. I think we need to move those impls into the compiler.

@reem
Copy link
Contributor

reem commented Nov 24, 2014

Hitting this in railgun when trying to use fn with lifetimes in place of Fns.

@japaric
Copy link
Member Author

japaric commented Nov 25, 2014

@nikomatsakis Any chance this could get fixed soon-ish? Once this gets fixed, we can start rolling the unboxed closure feature in several parts of the standard library!

@nikomatsakis
Copy link
Contributor

See PR #19449

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants