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
Regression in interaction between lifetime parameter and defaulted type parameter #49344
The mpi crate contains (approximately) the following code that used to work before nightly-2018-03-02:
use std::cell::Cell;use std::marker::PhantomData;pubstructRequest<'a,S:Scope<'a> = StaticScope>{scope:S,phantom:PhantomData<Cell<&'a()>>,}pubunsafetraitScope<'a>{/// Registers a request with the scope.fnregister(&self);/// Unregisters a request from the scope.unsafefnunregister(&self);}pubstructStaticScope;unsafeimplScope<'static>forStaticScope{fnregister(&self){}unsafefnunregister(&self){}}
The newest nightly compiler that successfully compiles this is:
Oops, it seems I completely forgot to paste the resulting error message:
error[E0308]: mismatched types
--> src/lib.rs:4:1
|
4 | / pub struct Request<'a, S: Scope<'a> = StaticScope> {
5 | | scope: S,
6 | | phantom: PhantomData<Cell<&'a ()>>,
7 | | }
| |_^ lifetime mismatch
|
= note: expected type `Scope<'a>`
found type `Scope<'static>`
note: the lifetime 'a as defined on the struct at 4:1...
--> src/lib.rs:4:1
|
4 | pub struct Request<'a, S: Scope<'a> = StaticScope> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: ...does not necessarily outlive the static lifetime
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
error: Could not compile `rsmpi-request-lifetime-issue`.
To learn more, run the command again with --verbose.
Sorry about that. As mentioned in the original issue the problem can be worked around by not having the type parameter S default to StaticScope and instead always specify both parameters explicitly, e.g. Request<'static, StaticScope>
cc @leodasvacas -- I think was something of an unexpected interaction, do you agree? I think we are probably checking that the default value (StaticScope) meets the bounds Scope<'a>, but we shouldn't be, because it talks about 'a.
Activity
bsteinb commentedon Mar 28, 2018
Oops, it seems I completely forgot to paste the resulting error message:
Sorry about that. As mentioned in the original issue the problem can be worked around by not having the type parameter
Sdefault toStaticScopeand instead always specify both parameters explicitly, e.g.Request<'static, StaticScope>nikomatsakis commentedon Apr 5, 2018
I'm guessing this is caused by #46785 but I'm not sure yet
nikomatsakis commentedon Apr 5, 2018
cc @leodasvacas -- I think was something of an unexpected interaction, do you agree? I think we are probably checking that the default value (
StaticScope) meets the boundsScope<'a>, but we shouldn't be, because it talks about'a.nikomatsakis commentedon Apr 5, 2018
triage: P-high
leoyvens commentedon Apr 5, 2018
Yes it's a bug in that PR, we should not be doing this check in predicates with lifetimes, I'll work on a fix.
Fix rust-lang#49344
Auto merge of #49704 - leodasvacas:fix-#49344, r=nikomatsakis
Fix rust-lang#49344
Auto merge of #49843 - leodasvacas:backport-fix-#49344, r=nikomatsakis