You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use std::any::TypeId;/// The type does not have any free lifetimes.////// Necessary as `TypeId` cannot distinguish between/// `&'a str` and `&'static str` and we must not cast/// between these types.unsafetraitNoFreeLifetimes:'static{}unsafeimpl<T:NoFreeLifetimes>NoFreeLifetimesforVec<T>{}unsafeimplNoFreeLifetimesforu32{}unsafeimplNoFreeLifetimesforString{}fntry_downcast_ref<'a,S,T:NoFreeLifetimes>(x:&S) -> Option<&T>{ifnon_static_type_id::<S>() == non_static_type_id::<T>(){Some(unsafe{&*(x as*constS).cast()})}else{None}}fnnon_static_type_id<T>() -> TypeId{type_id_of_val(|| ())}fntype_id_of_val<T:'static>(_:T) -> TypeId{TypeId::of::<T>()}fnfoo<T>(x:&T){ifletSome(s) = try_downcast_ref::<_,String>(x){println!("{s}");}elseifletSome(v) = try_downcast_ref::<_,Vec<u32>>(x){println!("{v:?}");}else{println!("unknown");}}fnmain(){foo(&String::from("hello"));foo(&"unknown");foo(&vec![1u32]);foo(&vec![1i32]);}
relies on an implementation detail of rustc for soundness, would need to either be a blessed part of std or requires strong regression tests. Please do not use this in production :3
The idea is that closures inherit the type parameters of the current body without considering them for outlives constraints.
The text was updated successfully, but these errors were encountered:
relies on an implementation detail of rustc for soundness, would need to either be a blessed part of std or requires strong regression tests. Please do not use this in production :3
The idea is that closures inherit the type parameters of the current body without considering them for outlives constraints.
The text was updated successfully, but these errors were encountered: