Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Structs with undefined/universal lifetimes (not higher-ranked)
Hey folks,
consider this code:
use std::marker::PhantomData;
struct HelperContainer<'helper, T> {
field: T,
_marker: PhantomData<&'helper ()>,
}
fn buildHelper<'helper, T>(v: T) -> HelperContainer<'helper, impl Sized + use<'helper, T>> {
HelperContainer {
field: v,
_marker: PhantomData,
}
}
fn main() {
let x = buildHelper("abc");
}
This compiles but I think it shouldn't or am I wrong? The reason why I think that is because the lifetime 'helper
in buildHelper
doesn't depend on the input - it can be everything. Nevertheless it gets captures in the RPIT which stands for an actual field in the container.
Regards
keks
1 post - 1 participant
🏷️ Rust_feed