Last active
June 25, 2022 20:54
-
-
Save raldone01/ccc931df6ab924e56bc3655bbbc51f5f to your computer and use it in GitHub Desktop.
Rustc: Consider restricting Self: Sized, Self: Sized,
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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