Skip to content

Commit

Permalink
Add test for evaluate_obligation: Ok(EvaluatedToOkModuloRegions) ICE
Browse files Browse the repository at this point in the history
Adds the minimial repro test case from rust-lang#85360. The fix for rust-lang#85360 was
supposed to be rust-lang#85868 however the repro was resolved in the 2021-07-05
nightly while rust-lang#85360 didn't land until 2021-09-03. The reason for that
is d34a3a4 **also** resolves that
issue.

To test if rust-lang#85868 actually fixes rust-lang#85360, I reverted
d34a3a4 and found that rust-lang#85868 does
indeed resolve rust-lang#85360.

With that question resolved, add a test case to our incremental test
suite for the original Ok(EvaluatedToOkModuloRegions) ICE.

Thanks to @lqd for helping track this down!
  • Loading branch information
wesleywiser authored and Mark-Simulacrum committed Jan 5, 2022
1 parent ce3d508 commit fa59cdb
Showing 1 changed file with 117 additions and 0 deletions.
117 changes: 117 additions & 0 deletions src/test/incremental/issue-85360-eval-obligation-ice.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// revisions:cfail1 cfail2
// compile-flags: --crate-type=lib --edition=2021
// build-pass

use core::any::Any;
use core::marker::PhantomData;

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 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
}
}

0 comments on commit fa59cdb

Please sign in to comment.