TGViewer
Блог* Блог* @dereference_pointer_there · 1.98K subscribers
Post #11587 278
#prog #rust #suckassstory

github.com/rust-lang/rust/issues/164250

use std::sync::Mutex;
static KEPT: Mutex<Vec<Box<dyn std::any::Any + Send>>> =
Mutex::new(Vec::new());

struct Q<T: 'static + Send>(Option<T>);

impl<T: 'static + Send> Drop for Q<T> {
fn drop(&mut self) {
if let Some(t) = self.0.take() {
KEPT.lock().unwrap().push(Box::new(t));
}
}
}

fn main() {
{
let l = String::from("hello world, this is long enough");
let mut q = Q(None);
q.0 = Some(&l);
}
let _z = String::from("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
let k = KEPT.lock().unwrap();
println!("{}", k[0].downcast_ref::<&'static String>().unwrap());
}


I expected to see this happen: program is not accepted
Instead, this happened: program compiles and prints XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX. With asan, the program will crash with a AddressSanitizer: stack-use-after-scope
GitHub struct's lifetime requirements can be bypassed via covariant field assignment · Issue #164250 · rust-lang/rust In the following code: use std::sync::Mutex; static KEPT: Mutex<Vec<Box<dyn std::any::Any + Send>>> = Mutex::new(Vec::new()); struct Q<T: 'static + Send>(Option<T>...
  • 😭 4
  • 🔥 1
More from @dereference_pointer_there
  1. Oct 12, 2026Post #11586
  2. Oct 12, 2026Блинчики могут помочь возбудить девушку.
  3. Oct 12, 2026Число совершивших террористические преступления детей выросло вдвое https://www.rbc.ru/soc…
  4. Oct 11, 2026Не пытайтесь
  5. Oct 11, 2026#prog #ml #meme
  6. Oct 11, 2026#meme
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →