Closed
Description
I have no idea what is going on in this piece of code:
#![feature(never_type)]
use std::marker::PhantomData;
pub trait Machine<'a, 'mir, 'tcx>: Sized {
type MemoryKinds: ::std::fmt::Debug + Copy + Eq;
const MUT_STATIC_KIND: Option<Self::MemoryKinds>;
}
pub struct CompileTimeEvaluator<'a, 'mir, 'tcx: 'a+'mir> {
pub _data: PhantomData<(&'a (), &'mir (), &'tcx ())>,
}
impl<'a, 'mir, 'tcx: 'a + 'mir> Machine<'a, 'mir, 'tcx>
for CompileTimeEvaluator<'a, 'mir, 'tcx>
{
type MemoryKinds = !;
const MUT_STATIC_KIND: Option<!> = None;
}
when it fails to compile saying
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'tcx` due to conflicting requirements
--> src/lib.rs:19:5
|
19 | const MUT_STATIC_KIND: Option<!> = None;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: first, the lifetime cannot outlive the lifetime 'tcx as defined on the impl at 14:16...
--> src/lib.rs:14:16
|
14 | impl<'a, 'mir, 'tcx: 'a + 'mir> Machine<'a, 'mir, 'tcx>
| ^^^^
note: ...but the lifetime must also be valid for the lifetime 'a as defined on the impl at 14:6...
--> src/lib.rs:14:6
|
14 | impl<'a, 'mir, 'tcx: 'a + 'mir> Machine<'a, 'mir, 'tcx>
| ^^
= note: ...so that the types are compatible:
expected Machine<'a, 'mir, 'tcx>
found Machine<'_, '_, '_>
error: aborting due to previous error
I would expect the code to be accepted. How can something of type Option<!>
have problems inferring a lifetime?!? The error is entirely not helpful.
Curiously, if I remove the 'a + 'mir
bound on 'tcx
in the impl
, this compiles. Removing a bound that's already implied by the type itself should not make a difference, right?