about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2021-12-07 11:04:57 +0100
committerGitHub <noreply@github.com>2021-12-07 11:04:57 +0100
commit42d0f8351aafa58755c44f49358675da208c4d51 (patch)
treec167c5d250974d34bfc3872ca434505fe1bf1652 /src/test
parentf84a734a8ea3fdd9abe0217797d7a07f31bb8ee8 (diff)
parent6fe13f62c1e73e6d102ce3673ad31d7195169560 (diff)
downloadrust-42d0f8351aafa58755c44f49358675da208c4d51.tar.gz
rust-42d0f8351aafa58755c44f49358675da208c4d51.zip
Rollup merge of #91065 - wesleywiser:add_incr_test, r=jackh726
Add test for evaluate_obligation: Ok(EvaluatedToOkModuloRegions) ICE

Adds the minimial repro test case from #85360. The fix for #85360 was
supposed to be #85868 however the repro was resolved in the 2021-07-05
nightly while #85868 didn't land until 2021-09-03. The reason for that
is d34a3a401b4e44f289a4d5bf53da83367cbb6aa7 **also** resolves that
issue.

To test if #85868 actually fixes #85360, I reverted
d34a3a401b4e44f289a4d5bf53da83367cbb6aa7 and found that #85868 does
indeed resolve #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!
Diffstat (limited to 'src/test')
-rw-r--r--src/test/incremental/issue-85360-eval-obligation-ice.rs118
-rw-r--r--src/test/ui/traits/issue-85360-eval-obligation-ice.rs143
-rw-r--r--src/test/ui/traits/issue-85360-eval-obligation-ice.stderr38
3 files changed, 299 insertions, 0 deletions
diff --git a/src/test/incremental/issue-85360-eval-obligation-ice.rs b/src/test/incremental/issue-85360-eval-obligation-ice.rs
new file mode 100644
index 00000000000..1796c9d197c
--- /dev/null
+++ b/src/test/incremental/issue-85360-eval-obligation-ice.rs
@@ -0,0 +1,118 @@
+// revisions:cfail1 cfail2
+//[cfail1] compile-flags: --crate-type=lib --edition=2021 -Zassert-incr-state=not-loaded
+//[cfail2] compile-flags: --crate-type=lib --edition=2021 -Zassert-incr-state=loaded
+// 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
+    }
+}
diff --git a/src/test/ui/traits/issue-85360-eval-obligation-ice.rs b/src/test/ui/traits/issue-85360-eval-obligation-ice.rs
new file mode 100644
index 00000000000..19131684a48
--- /dev/null
+++ b/src/test/ui/traits/issue-85360-eval-obligation-ice.rs
@@ -0,0 +1,143 @@
+// 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(TraitPredicate(<MaskedStorage<GenericComp<Pos>> as std::marker::Sized>, polarity:Positive), [])) = Ok(EvaluatedToOk)
+    //~| ERROR evaluate(Binder(TraitPredicate(<MaskedStorage<GenericComp<Pos>> as std::marker::Sized>, polarity:Positive), [])) = Ok(EvaluatedToOk)
+
+    test::<MaskedStorage<GenericComp2<Pos>>>(make());
+    //~^ ERROR evaluate(Binder(TraitPredicate(<MaskedStorage<GenericComp2<Pos>> as std::marker::Sized>, polarity:Positive), [])) = Ok(EvaluatedToOkModuloRegions)
+    //~| ERROR evaluate(Binder(TraitPredicate(<MaskedStorage<GenericComp2<Pos>> as std::marker::Sized>, polarity:Positive), [])) = 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
+    }
+}
diff --git a/src/test/ui/traits/issue-85360-eval-obligation-ice.stderr b/src/test/ui/traits/issue-85360-eval-obligation-ice.stderr
new file mode 100644
index 00000000000..ebf977dd680
--- /dev/null
+++ b/src/test/ui/traits/issue-85360-eval-obligation-ice.stderr
@@ -0,0 +1,38 @@
+error: evaluate(Binder(TraitPredicate(<MaskedStorage<GenericComp<Pos>> as std::marker::Sized>, polarity:Positive), [])) = Ok(EvaluatedToOk)
+  --> $DIR/issue-85360-eval-obligation-ice.rs:9:5
+   |
+LL |     test::<MaskedStorage<GenericComp<Pos>>>(make());
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn test<T: Sized>(_: T) {}
+   |         - predicate
+
+error: evaluate(Binder(TraitPredicate(<MaskedStorage<GenericComp<Pos>> as std::marker::Sized>, polarity:Positive), [])) = Ok(EvaluatedToOk)
+  --> $DIR/issue-85360-eval-obligation-ice.rs:9:5
+   |
+LL |     test::<MaskedStorage<GenericComp<Pos>>>(make());
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn test<T: Sized>(_: T) {}
+   |            ----- predicate
+
+error: evaluate(Binder(TraitPredicate(<MaskedStorage<GenericComp2<Pos>> as std::marker::Sized>, polarity:Positive), [])) = Ok(EvaluatedToOkModuloRegions)
+  --> $DIR/issue-85360-eval-obligation-ice.rs:13:5
+   |
+LL |     test::<MaskedStorage<GenericComp2<Pos>>>(make());
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn test<T: Sized>(_: T) {}
+   |         - predicate
+
+error: evaluate(Binder(TraitPredicate(<MaskedStorage<GenericComp2<Pos>> as std::marker::Sized>, polarity:Positive), [])) = Ok(EvaluatedToOkModuloRegions)
+  --> $DIR/issue-85360-eval-obligation-ice.rs:13:5
+   |
+LL |     test::<MaskedStorage<GenericComp2<Pos>>>(make());
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn test<T: Sized>(_: T) {}
+   |            ----- predicate
+
+error: aborting due to 4 previous errors
+