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 MiniTypeId for T { + const TYPE_ID: u64 = 0; +} + +enum Lift {} + +trait IsFalse {} +impl IsFalse for Lift {} + +const fn is_same_type() -> bool { + T::TYPE_ID == U::TYPE_ID +} + +fn requires_distinct(_a: A, _b: B) where + A: MiniTypeId, B: MiniTypeId, + Lift<{is_same_type::()}>: 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; + fn lazy_updim(&self, size : [usize;NEWDIM] ) -> + LazyUpdim + { + assert!(NEWDIM >= Self::DIM, + "Updimmed tensor cannot have fewer indices than the initial one."); + LazyUpdim {size,reference:&self} + } + fn bmap T>(&self,foo : F) -> BMap{ + 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 { + //~^ 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 { + //~^ ERROR method not compatible with trait + self.reference.bget(index).map(&self.closure) + //~^ ERROR unconstrained generic constant + //~| ERROR mismatched types + } +} + +impl TensorDimension for Vec { + const DIM : usize = 1; +} +impl TensorSize for Vec { + fn size(&self) -> [usize;1] {[self.len()]} +} +impl Broadcastable for Vec { + type Element = T; + fn bget(& self,index : [usize;1]) -> Option { + 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 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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; + | ^^^^^^^^^ 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 {} +impl IsTrue for () {} + +pub trait IsZST {} + +impl IsZST for T +where + (): IsTrue<{ std::mem::size_of::() == 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(); +pub trait IsTrue {} +impl IsTrue for Assert {} + +pub trait IsNotZST {} +impl IsNotZST for T where Assert<{ std::mem::size_of::() > 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; +pub trait True {} +impl True for If {} + +fn consume(_val: T) +where + If<{ TypeId::of::() != TypeId::of::<()>() }>: True, + //~^ ERROR: overly complex generic constant + //~| ERROR: calls in constants are limited to constant functions +{ +} + +fn test() +where + If<{ TypeId::of::() != 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::() != 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::() != TypeId::of::<()>() }>: True, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: overly complex generic constant + --> $DIR/issue-90318.rs:22:8 + | +LL | If<{ TypeId::of::() != 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::() != TypeId::of::<()>() }>: True, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0015`.