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
This differs from the behavior of Box, Arc, Rc, and &.
foo.rs:
use std::sync::atomic::AtomicPtr;structFoo<'a>(&'ai32);fnbar<'a>(x:AtomicPtr<Foo<'static>>) -> AtomicPtr<Foo<'a>>{
x
}fnmain(){}
Compiler output with rustc 1.5.0-nightly (4826f9625 2015-10-21):
expected `core::sync::atomic::AtomicPtr<Foo<'a>>`,
found `core::sync::atomic::AtomicPtr<Foo<'static>>`
(lifetime mismatch) [E0308]
foo.rs:6 x
^
foo.rs:6:5: 6:6 help: run `rustc --explain E0308` to see a detailed explanation
foo.rs:5:62: 7:2 note: the lifetime 'a as defined on the block at 5:61...
foo.rs:5 fn bar<'a>(x: AtomicPtr<Foo<'static>>) -> AtomicPtr<Foo<'a>> {
foo.rs:6 x
foo.rs:7 }
note: ...does not necessarily outlive the static lifetime
This stems from the use of UnsafeCell<*mut T> in AtomicPtr's definition instead of UnsafeCell<*const T>.
I think though that in this case it's "correct", right? AtomicPtr has interior mutability so if you have AtomicPtr<Foo<'static>> but were able to put a Foo<'a> inside it, that would be bad I think? With Box, Arc, Rc, and & there's no interior mutability which is why I think it's ok to not be invariant.
It turns out that the use of *mut T doesn't matter, as UnsafeCell itself ensures invariance in order to permit interior mutability, which is basically what @alexcrichton is saying here.
This differs from the behavior of
Box
,Arc
,Rc
, and&
.foo.rs
:Compiler output with
rustc 1.5.0-nightly (4826f9625 2015-10-21)
:This stems from the use of
UnsafeCell<*mut T>
inAtomicPtr
's definition instead ofUnsafeCell<*const T>
.CC #29037.
The text was updated successfully, but these errors were encountered: