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-10 22:41:22 +0100
committerGitHub <noreply@github.com>2021-12-10 22:41:22 +0100
commitd6e941778abfb11b4a35fce47c09c68ffab04e5b (patch)
tree2850b3b8f8c24af713f23bdd775e82a08f747c28 /src/test
parent0aa41bea970785d7a13bbce48720cf920a8c3a56 (diff)
parentc7f80fc0727017a8ad45c37747805facbbb68a72 (diff)
downloadrust-d6e941778abfb11b4a35fce47c09c68ffab04e5b.tar.gz
rust-d6e941778abfb11b4a35fce47c09c68ffab04e5b.zip
Rollup merge of #91678 - b-naber:tests-for-postpone-const-eval, r=jackh726
Add tests fixed by #90023

The following issues were fixed by https://github.com/rust-lang/rust/pull/90023

Fixes https://github.com/rust-lang/rust/issues/79674
Fixes https://github.com/rust-lang/rust/issues/83765
Fixes https://github.com/rust-lang/rust/issues/86033
Fixes https://github.com/rust-lang/rust/issues/90318
Fixes https://github.com/rust-lang/rust/issues/88468

The following issues were duplicates of https://github.com/rust-lang/rust/issues/90654

Fixes https://github.com/rust-lang/rust/issues/86850
Fixes https://github.com/rust-lang/rust/issues/89022

r? ````@jackh726````
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/const-generics/issues/issue-79674.rs28
-rw-r--r--src/test/ui/const-generics/issues/issue-79674.stderr12
-rw-r--r--src/test/ui/const-generics/issues/issue-83765.rs115
-rw-r--r--src/test/ui/const-generics/issues/issue-83765.stderr130
-rw-r--r--src/test/ui/const-generics/issues/issue-86033.rs20
-rw-r--r--src/test/ui/const-generics/issues/issue-88468.rs13
-rw-r--r--src/test/ui/const-generics/issues/issue-90318.rs32
-rw-r--r--src/test/ui/const-generics/issues/issue-90318.stderr37
8 files changed, 387 insertions, 0 deletions
diff --git a/src/test/ui/const-generics/issues/issue-79674.rs b/src/test/ui/const-generics/issues/issue-79674.rs
new file mode 100644
index 00000000000..2f196533dd8
--- /dev/null
+++ b/src/test/ui/const-generics/issues/issue-79674.rs
@@ -0,0 +1,28 @@
+#![feature(const_fn_trait_bound, generic_const_exprs)]
+#![allow(incomplete_features)]
+
+trait MiniTypeId {
+    const TYPE_ID: u64;
+}
+
+impl<T> MiniTypeId for T {
+    const TYPE_ID: u64 = 0;
+}
+
+enum Lift<const V: bool> {}
+
+trait IsFalse {}
+impl IsFalse for Lift<false> {}
+
+const fn is_same_type<T: MiniTypeId, U: MiniTypeId>() -> bool {
+    T::TYPE_ID == U::TYPE_ID
+}
+
+fn requires_distinct<A, B>(_a: A, _b: B) where
+    A: MiniTypeId, B: MiniTypeId,
+    Lift<{is_same_type::<A, B>()}>: IsFalse {}
+
+fn main() {
+    requires_distinct("str", 12);
+    //~^ ERROR mismatched types
+}
diff --git a/src/test/ui/const-generics/issues/issue-79674.stderr b/src/test/ui/const-generics/issues/issue-79674.stderr
new file mode 100644
index 00000000000..8c029289cbb
--- /dev/null
+++ b/src/test/ui/const-generics/issues/issue-79674.stderr
@@ -0,0 +1,12 @@
+error[E0308]: mismatched types
+  --> $DIR/issue-79674.rs:26:5
+   |
+LL |     requires_distinct("str", 12);
+   |     ^^^^^^^^^^^^^^^^^ expected `true`, found `false`
+   |
+   = note: expected type `true`
+              found type `false`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/const-generics/issues/issue-83765.rs b/src/test/ui/const-generics/issues/issue-83765.rs
new file mode 100644
index 00000000000..68536348d38
--- /dev/null
+++ b/src/test/ui/const-generics/issues/issue-83765.rs
@@ -0,0 +1,115 @@
+#![feature(generic_const_exprs)]
+#![allow(incomplete_features)]
+
+trait TensorDimension {
+    const DIM : usize;
+    const ISSCALAR : bool = Self::DIM == 0;
+    fn is_scalar(&self) -> bool {Self::ISSCALAR}
+}
+
+trait TensorSize : TensorDimension {
+    fn size(&self) -> [usize;Self::DIM];
+    fn inbounds(&self,index : [usize;Self::DIM]) -> bool {
+        index.iter().zip(self.size().iter()).all(|(i,s)| i < s)
+    }
+}
+
+
+trait Broadcastable: TensorSize + Sized {
+    type Element;
+    fn bget(&self, index:[usize;Self::DIM]) -> Option<Self::Element>;
+    fn lazy_updim<const NEWDIM : usize>(&self, size : [usize;NEWDIM] ) ->
+       LazyUpdim<Self,{Self::DIM},NEWDIM>
+    {
+        assert!(NEWDIM >= Self::DIM,
+            "Updimmed tensor cannot have fewer indices than the initial one.");
+        LazyUpdim {size,reference:&self}
+    }
+    fn bmap<T,F :Fn(Self::Element) -> T>(&self,foo : F) -> BMap<T,Self,F,{Self::DIM}>{
+        BMap {reference:self,closure : foo}
+    }
+}
+
+
+struct LazyUpdim<'a,T : Broadcastable,const OLDDIM : usize, const DIM : usize> {
+    size : [usize;DIM],
+    reference : &'a T
+}
+
+impl<'a,T : Broadcastable,const DIM : usize> TensorDimension for LazyUpdim<'a,T,{T::DIM},DIM> {
+    const DIM : usize = DIM;
+}
+
+impl<'a,T : Broadcastable,const DIM : usize> TensorSize for LazyUpdim<'a,T,{T::DIM},DIM> {
+    fn size(&self) -> [usize;DIM] {self.size}
+    //~^ ERROR method not compatible with trait
+}
+
+impl<'a,T : Broadcastable,const DIM : usize>  Broadcastable for LazyUpdim<'a,T,{T::DIM},DIM>
+{
+    type Element = T::Element;
+    fn bget(&self,index:[usize;DIM]) -> Option<Self::Element> {
+      //~^ ERROR method not compatible with trait
+        assert!(DIM >= T::DIM);
+        if !self.inbounds(index) {return None}
+        //~^ ERROR unconstrained generic constant
+        //~| ERROR mismatched types
+        let size = self.size();
+        //~^ ERROR unconstrained generic constant
+        let newindex : [usize;T::DIM] = Default::default();
+        //~^ ERROR the trait bound `[usize; _]: Default` is not satisfied
+        self.reference.bget(newindex)
+    }
+}
+
+struct BMap<'a,R, T : Broadcastable, F :  Fn(T::Element) -> R  , const DIM: usize> {
+    reference : &'a T,
+    closure : F
+}
+
+impl<'a,R, T : Broadcastable, F :  Fn(T::Element) -> R,
+     const DIM: usize> TensorDimension for BMap<'a,R,T,F,DIM> {
+
+    const DIM : usize = DIM;
+}
+impl<'a,R, T : Broadcastable, F :  Fn(T::Element) -> R  ,
+      const DIM: usize> TensorSize for BMap<'a,R,T,F,DIM> {
+
+    fn size(&self) -> [usize;DIM] {self.reference.size()}
+    //~^ ERROR unconstrained generic constant
+    //~| ERROR mismatched types
+    //~| ERROR method not compatible with trait
+}
+
+impl<'a,R, T : Broadcastable, F :  Fn(T::Element) -> R  ,
+  const DIM: usize> Broadcastable for BMap<'a,R,T,F,DIM> {
+
+    type Element = R;
+    fn bget(&self,index:[usize;DIM]) -> Option<Self::Element> {
+      //~^ ERROR method not compatible with trait
+        self.reference.bget(index).map(&self.closure)
+        //~^ ERROR unconstrained generic constant
+        //~| ERROR mismatched types
+    }
+}
+
+impl<T> TensorDimension for Vec<T> {
+    const DIM : usize = 1;
+}
+impl<T> TensorSize for Vec<T> {
+    fn size(&self) -> [usize;1] {[self.len()]}
+}
+impl<T: Clone> Broadcastable for Vec<T> {
+    type Element = T;
+    fn bget(& self,index : [usize;1]) -> Option<T> {
+        self.get(index[0]).cloned()
+    }
+}
+
+fn main() {
+    let v = vec![1,2,3];
+    let bv = v.lazy_updim([3,4]);
+    let bbv = bv.bmap(|x| x*x);
+
+    println!("The size of v is {:?}",bbv.bget([0,2]).expect("Out of bounds."));
+}
diff --git a/src/test/ui/const-generics/issues/issue-83765.stderr b/src/test/ui/const-generics/issues/issue-83765.stderr
new file mode 100644
index 00000000000..a49f850717f
--- /dev/null
+++ b/src/test/ui/const-generics/issues/issue-83765.stderr
@@ -0,0 +1,130 @@
+error[E0308]: method not compatible with trait
+  --> $DIR/issue-83765.rs:44:5
+   |
+LL |     fn size(&self) -> [usize;DIM] {self.size}
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Self::DIM`, found `DIM`
+   |
+   = note: expected type `Self::DIM`
+              found type `DIM`
+
+error[E0308]: method not compatible with trait
+  --> $DIR/issue-83765.rs:51:5
+   |
+LL |     fn bget(&self,index:[usize;DIM]) -> Option<Self::Element> {
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Self::DIM`, found `DIM`
+   |
+   = note: expected type `Self::DIM`
+              found type `DIM`
+
+error[E0308]: method not compatible with trait
+  --> $DIR/issue-83765.rs:78:5
+   |
+LL |     fn size(&self) -> [usize;DIM] {self.reference.size()}
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Self::DIM`, found `DIM`
+   |
+   = note: expected type `Self::DIM`
+              found type `DIM`
+
+error[E0308]: method not compatible with trait
+  --> $DIR/issue-83765.rs:88:5
+   |
+LL |     fn bget(&self,index:[usize;DIM]) -> Option<Self::Element> {
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Self::DIM`, found `DIM`
+   |
+   = note: expected type `Self::DIM`
+              found type `DIM`
+
+error: unconstrained generic constant
+  --> $DIR/issue-83765.rs:54:18
+   |
+LL |         if !self.inbounds(index) {return None}
+   |                  ^^^^^^^^
+   |
+   = help: try adding a `where` bound using this expression: `where [(); Self::DIM]:`
+note: required by a bound in `TensorSize::inbounds`
+  --> $DIR/issue-83765.rs:12:38
+   |
+LL |     fn inbounds(&self,index : [usize;Self::DIM]) -> bool {
+   |                                      ^^^^^^^^^ required by this bound in `TensorSize::inbounds`
+
+error[E0308]: mismatched types
+  --> $DIR/issue-83765.rs:54:27
+   |
+LL |         if !self.inbounds(index) {return None}
+   |                           ^^^^^ expected `Self::DIM`, found `DIM`
+   |
+   = note: expected type `Self::DIM`
+              found type `DIM`
+
+error: unconstrained generic constant
+  --> $DIR/issue-83765.rs:57:25
+   |
+LL |         let size = self.size();
+   |                         ^^^^
+   |
+   = help: try adding a `where` bound using this expression: `where [(); Self::DIM]:`
+note: required by a bound in `TensorSize::size`
+  --> $DIR/issue-83765.rs:11:30
+   |
+LL |     fn size(&self) -> [usize;Self::DIM];
+   |                              ^^^^^^^^^ required by this bound in `TensorSize::size`
+
+error[E0277]: the trait bound `[usize; _]: Default` is not satisfied
+  --> $DIR/issue-83765.rs:59:41
+   |
+LL |         let newindex : [usize;T::DIM] = Default::default();
+   |                                         ^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `[usize; _]`
+   |
+help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement
+   |
+LL | impl<'a,T : Broadcastable,const DIM : usize>  Broadcastable for LazyUpdim<'a,T,{T::DIM},DIM> where [usize; _]: Default
+   |                                                                                              +++++++++++++++++++++++++
+
+error: unconstrained generic constant
+  --> $DIR/issue-83765.rs:78:51
+   |
+LL |     fn size(&self) -> [usize;DIM] {self.reference.size()}
+   |                                                   ^^^^
+   |
+   = help: try adding a `where` bound using this expression: `where [(); Self::DIM]:`
+note: required by a bound in `TensorSize::size`
+  --> $DIR/issue-83765.rs:11:30
+   |
+LL |     fn size(&self) -> [usize;Self::DIM];
+   |                              ^^^^^^^^^ required by this bound in `TensorSize::size`
+
+error[E0308]: mismatched types
+  --> $DIR/issue-83765.rs:78:36
+   |
+LL |     fn size(&self) -> [usize;DIM] {self.reference.size()}
+   |                                    ^^^^^^^^^^^^^^^^^^^^^ expected `DIM`, found `Self::DIM`
+   |
+   = note: expected type `DIM`
+              found type `Self::DIM`
+
+error: unconstrained generic constant
+  --> $DIR/issue-83765.rs:90:24
+   |
+LL |         self.reference.bget(index).map(&self.closure)
+   |                        ^^^^
+   |
+   = help: try adding a `where` bound using this expression: `where [(); Self::DIM]:`
+note: required by a bound in `Broadcastable::bget`
+  --> $DIR/issue-83765.rs:20:33
+   |
+LL |     fn bget(&self, index:[usize;Self::DIM]) -> Option<Self::Element>;
+   |                                 ^^^^^^^^^ required by this bound in `Broadcastable::bget`
+
+error[E0308]: mismatched types
+  --> $DIR/issue-83765.rs:90:29
+   |
+LL |         self.reference.bget(index).map(&self.closure)
+   |                             ^^^^^ expected `Self::DIM`, found `DIM`
+   |
+   = note: expected type `Self::DIM`
+              found type `DIM`
+
+error: aborting due to 12 previous errors
+
+Some errors have detailed explanations: E0277, E0308.
+For more information about an error, try `rustc --explain E0277`.
diff --git a/src/test/ui/const-generics/issues/issue-86033.rs b/src/test/ui/const-generics/issues/issue-86033.rs
new file mode 100644
index 00000000000..cf08f722fbb
--- /dev/null
+++ b/src/test/ui/const-generics/issues/issue-86033.rs
@@ -0,0 +1,20 @@
+// check-pass
+
+#![feature(generic_const_exprs)]
+#![allow(incomplete_features)]
+
+pub trait IsTrue<const T: bool> {}
+impl IsTrue<true> for () {}
+
+pub trait IsZST {}
+
+impl<T> IsZST for T
+where
+    (): IsTrue<{ std::mem::size_of::<T>() == 0 }>
+{}
+
+fn _func() -> impl IsZST {
+    || {}
+}
+
+fn main() {}
diff --git a/src/test/ui/const-generics/issues/issue-88468.rs b/src/test/ui/const-generics/issues/issue-88468.rs
new file mode 100644
index 00000000000..914047236ab
--- /dev/null
+++ b/src/test/ui/const-generics/issues/issue-88468.rs
@@ -0,0 +1,13 @@
+// check-pass
+
+#![allow(incomplete_features)]
+#![feature(generic_const_exprs)]
+
+pub struct Assert<const COND: bool>();
+pub trait IsTrue {}
+impl IsTrue for Assert<true> {}
+
+pub trait IsNotZST {}
+impl<T> IsNotZST for T where Assert<{ std::mem::size_of::<T>() > 0 }>: IsTrue {}
+
+fn main() {}
diff --git a/src/test/ui/const-generics/issues/issue-90318.rs b/src/test/ui/const-generics/issues/issue-90318.rs
new file mode 100644
index 00000000000..0c640a5ef71
--- /dev/null
+++ b/src/test/ui/const-generics/issues/issue-90318.rs
@@ -0,0 +1,32 @@
+#![feature(const_type_id)]
+#![feature(generic_const_exprs)]
+#![feature(core_intrinsics)]
+#![allow(incomplete_features)]
+
+use std::any::TypeId;
+
+struct If<const B: bool>;
+pub trait True {}
+impl True for If<true> {}
+
+fn consume<T: 'static>(_val: T)
+where
+    If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
+    //~^ ERROR: overly complex generic constant
+    //~| ERROR: calls in constants are limited to constant functions
+{
+}
+
+fn test<T: 'static>()
+where
+    If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
+    //~^ ERROR: overly complex generic constant
+    //~| ERROR: calls in constants are limited to constant functions
+{
+}
+
+fn main() {
+    let a = ();
+    consume(0i32);
+    consume(a);
+}
diff --git a/src/test/ui/const-generics/issues/issue-90318.stderr b/src/test/ui/const-generics/issues/issue-90318.stderr
new file mode 100644
index 00000000000..2b8afe2ef09
--- /dev/null
+++ b/src/test/ui/const-generics/issues/issue-90318.stderr
@@ -0,0 +1,37 @@
+error: overly complex generic constant
+  --> $DIR/issue-90318.rs:14:8
+   |
+LL |     If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
+   |        ^^-----------------^^^^^^^^^^^^^^^^^^^^^^^^
+   |          |
+   |          borrowing is not supported in generic constants
+   |
+   = help: consider moving this anonymous constant into a `const` function
+   = note: this operation may be supported in the future
+
+error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
+  --> $DIR/issue-90318.rs:14:10
+   |
+LL |     If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
+   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: overly complex generic constant
+  --> $DIR/issue-90318.rs:22:8
+   |
+LL |     If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
+   |        ^^-----------------^^^^^^^^^^^^^^^^^^^^^^^^
+   |          |
+   |          borrowing is not supported in generic constants
+   |
+   = help: consider moving this anonymous constant into a `const` function
+   = note: this operation may be supported in the future
+
+error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
+  --> $DIR/issue-90318.rs:22:10
+   |
+LL |     If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
+   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0015`.