mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 09:14:20 +00:00
c4c22b0d52
``` error[E0277]: the size for values of type `[i32]` cannot be known at compilation time --> f100.rs:2:33 | 2 | let _ = std::mem::size_of::<[i32]>(); | ^^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `[i32]` note: required by an implicit `Sized` bound in `std::mem::size_of` --> /home/gh-estebank/rust/library/core/src/mem/mod.rs:312:22 | 312 | pub const fn size_of<T>() -> usize { | ^ required by the implicit `Sized` requirement on this bound in `size_of` ``` Fix #120178.
142 lines
2.6 KiB
Rust
142 lines
2.6 KiB
Rust
// compile-flags: --edition=2021
|
|
|
|
#![feature(rustc_attrs)]
|
|
|
|
use core::any::Any;
|
|
use core::marker::PhantomData;
|
|
|
|
fn main() {
|
|
test::<MaskedStorage<GenericComp<Pos>>>(make());
|
|
//~^ ERROR evaluate(Binder { value: TraitPredicate(<MaskedStorage<GenericComp<Pos>> as std::marker::Sized>, polarity:Positive), bound_vars: [] }) = Ok(EvaluatedToOk)
|
|
|
|
test::<MaskedStorage<GenericComp2<Pos>>>(make());
|
|
//~^ ERROR evaluate(Binder { value: TraitPredicate(<MaskedStorage<GenericComp2<Pos>> as std::marker::Sized>, polarity:Positive), bound_vars: [] }) = Ok(EvaluatedToOkModuloRegions)
|
|
}
|
|
|
|
#[rustc_evaluate_where_clauses]
|
|
fn test<T: Sized>(_: T) {}
|
|
|
|
fn make<T>() -> T {
|
|
todo!()
|
|
}
|
|
|
|
struct DerefWrap<T>(T);
|
|
|
|
impl<T> core::ops::Deref for DerefWrap<T> {
|
|
type Target = T;
|
|
fn deref(&self) -> &Self::Target {
|
|
&self.0
|
|
}
|
|
}
|
|
|
|
struct Storage<T, D> {
|
|
phantom: PhantomData<(T, D)>,
|
|
}
|
|
|
|
type ReadStorage<T> = Storage<T, DerefWrap<MaskedStorage<T>>>;
|
|
|
|
pub trait Component {
|
|
type Storage;
|
|
}
|
|
|
|
struct VecStorage;
|
|
|
|
struct Pos;
|
|
|
|
impl Component for Pos {
|
|
type Storage = VecStorage;
|
|
}
|
|
|
|
struct GenericComp<T> {
|
|
_t: T,
|
|
}
|
|
|
|
impl<T: 'static> Component for GenericComp<T> {
|
|
type Storage = VecStorage;
|
|
}
|
|
|
|
struct GenericComp2<T> {
|
|
_t: T,
|
|
}
|
|
|
|
impl<T: 'static> Component for GenericComp2<T> where for<'a> &'a bool: 'a {
|
|
type Storage = VecStorage;
|
|
}
|
|
|
|
struct ReadData {
|
|
pos_interpdata: ReadStorage<GenericComp<Pos>>,
|
|
}
|
|
|
|
trait System {
|
|
type SystemData;
|
|
|
|
fn run(data: Self::SystemData, any: Box<dyn Any>);
|
|
}
|
|
|
|
struct Sys;
|
|
|
|
impl System for Sys {
|
|
type SystemData = (ReadData, ReadStorage<Pos>);
|
|
|
|
fn run((data, pos): Self::SystemData, any: Box<dyn Any>) {
|
|
<ReadStorage<GenericComp<Pos>> as SystemData>::setup(any);
|
|
|
|
ParJoin::par_join((&pos, &data.pos_interpdata));
|
|
}
|
|
}
|
|
|
|
trait ParJoin {
|
|
fn par_join(self)
|
|
where
|
|
Self: Sized,
|
|
{
|
|
}
|
|
}
|
|
|
|
impl<'a, T, D> ParJoin for &'a Storage<T, D>
|
|
where
|
|
T: Component,
|
|
D: core::ops::Deref<Target = MaskedStorage<T>>,
|
|
T::Storage: Sync,
|
|
{
|
|
}
|
|
|
|
impl<A, B> ParJoin for (A, B)
|
|
where
|
|
A: ParJoin,
|
|
B: ParJoin,
|
|
{
|
|
}
|
|
|
|
pub trait SystemData {
|
|
fn setup(any: Box<dyn Any>);
|
|
}
|
|
|
|
impl<T: 'static> SystemData for ReadStorage<T>
|
|
where
|
|
T: Component,
|
|
{
|
|
fn setup(any: Box<dyn Any>) {
|
|
let storage: &MaskedStorage<T> = any.downcast_ref().unwrap();
|
|
|
|
<dyn Any as CastFrom<MaskedStorage<T>>>::cast(&storage);
|
|
}
|
|
}
|
|
|
|
pub struct MaskedStorage<T: Component> {
|
|
_inner: T::Storage,
|
|
}
|
|
|
|
pub unsafe trait CastFrom<T> {
|
|
fn cast(t: &T) -> &Self;
|
|
}
|
|
|
|
unsafe impl<T> CastFrom<T> for dyn Any
|
|
where
|
|
T: Any + 'static,
|
|
{
|
|
fn cast(t: &T) -> &Self {
|
|
t
|
|
}
|
|
}
|