You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Trait implementation solving fails for a closure #138805
structFoo<A,B>(A,B);#[allow(non_camel_case_types, dead_code)]traitFn_require_outlives_in_method<A,B>{// a for<'a> alternative that is type checked// at the call sitefncall<'a>(self,value:&'aA) -> &'aB;}// impl the trait for FnOnce(&A) -> &Bimpl<A,B,F:for<'a>FnOnce(&'aA) -> &'aB/* where A: 'a, B: 'a (trivial bounds) */>Fn_require_outlives_in_method<A,B>forF{#[inline(always)]fncall<'a>(self,value:&'aA) -> &'aB{self(value)}}impl<A,B>Foo<A,B>{fnnew(_value:A,_callback:implFn_require_outlives_in_method<A,B>) -> Self{todo!()}}fncheck_fn_once_impl_universal_over_lifetime_a(_:implfor<'a>FnOnce(&'ai32) -> &'ai32){}fnmain(){Foo::new(0, |e| e);}
I expected to see this happen: compiles
Instead, this happened:
error: implementation of `FnOnce` is not general enough
--> src/main.rs:28:5
|
28 | Foo::new(0, |e| e);
| ^^^^^^^^ implementation of `FnOnce` is not general enough
|
= note: closure with signature `fn(&'2 i32) -> &i32` must implement `FnOnce<(&'1 i32,)>`, for any lifetime `'1`...
= note: ...but it actually implements `FnOnce<(&'2 i32,)>`, for some specific lifetime `'2`
Other examples with comments:
fncheck_fn_once_impl_universal_over_lifetime_a(_:implfor<'a>FnOnce(&'ai32) -> &'ai32){}fnmain(){fntest(e:&i32) -> &i32{ e }// Foo::new(0, |e| e); // fails to compile (not general enough)// Foo::<i32, i32>::new(0, |e| e); // fails to compile (not general enough)check_fn_once_impl_universal_over_lifetime_a(|e| e);// okFoo::new(0,for<'a> |e:&'ai32| -> &'ai32{ e });// ok (experimental)Foo::new(0, test);// ok}
Activity