-
Notifications
You must be signed in to change notification settings - Fork 154
Open
Description
I could not get the following code to compile with SmallVec
(I heavily simplified the code):
use std::borrow::Cow;
pub struct SmallVec<T> {
data: *mut T,
}
pub struct Example<'a>(SmallVec<[Cow<'a, str>; 2]>);
impl<'a> Example<'a> {
pub fn into_owned(self) -> Example<'static> { unimplemented!() }
}
fn transform<'a>(input: Example<'a>) -> Example<'a> {
input.into_owned()
}
fn main() {}
error[E0308]: mismatched types
--> src/main.rs:14:5
|
14 | input.into_owned()
| ^^^^^^^^^^^^^^^^^^ lifetime mismatch
|
= note: expected struct `Example<'a>`
found struct `Example<'static>`
note: the lifetime `'a` as defined on the function body at 13:14...
--> src/main.rs:13:14
|
13 | fn transform<'a>(input: Example<'a>) -> Example<'a> {
| ^^
= note: ...does not necessarily outlive the static lifetime
error: aborting due to previous error
which does compile when you replace SmallVec
with Vec
.
This works with Vec
, because internally the pointer is wrapped in Unique<T>
:
whereas SmallVec
contains a raw pointer:
Line 370 in a541e2d
Heap((*mut A::Item, usize)), |
This issue can be solved by changing *mut A::Item
to Option<NonNull<A::Item>>
, because NonNull
implements the CoerceUnsized
trait.
This might be related to #146
Metadata
Metadata
Assignees
Labels
No labels