Skip to content

Instantly share code, notes, and snippets.

@raldone01
Last active June 25, 2022 20:54
Show Gist options
  • Save raldone01/ccc931df6ab924e56bc3655bbbc51f5f to your computer and use it in GitHub Desktop.
Save raldone01/ccc931df6ab924e56bc3655bbbc51f5f to your computer and use it in GitHub Desktop.
Rustc: Consider restricting Self: Sized, Self: Sized,
struct Victim<'a, T: Perpetrator + ?Sized>
where
Self: Sized, // Oh no it didn't work
Self: Sized, // Mhh still not good
Self: Sized, // Help me rustc
Self: Sized, // Please stop
{
value: u8,
perp: &'a T,
}
trait VictimTrait {
type Ret;
fn get(self) -> Self::Ret;
}
// Actual fix is here
impl<'a, T: Perpetrator /*+ ?Sized*/> VictimTrait for Victim<'a, T> {
type Ret = u8;
fn get(self) -> Self::Ret {
self.value
}
}
trait Perpetrator {
fn getter<'a>(&'a self) -> Victim<'a, Self> {
Victim {
value: 0,
perp: self,
}
}
fn trigger(&self) {
self.getter().get();
}
}
fn main() {
println!("Hello, world!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment