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
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}
I tried this code:
I expected to see this happen: compiles
Instead, this happened:
Other examples with comments:
Meta
rustc --version --verbose
:Backtrace
The text was updated successfully, but these errors were encountered: