add/update tests

This commit is contained in:
b-naber 2022-03-21 18:46:20 +01:00
parent 3b9de6b087
commit 6cf3409e16
4 changed files with 51 additions and 138 deletions

View file

@ -0,0 +1,26 @@
// build-pass
#![feature(generic_const_exprs)]
//~^ WARNING the feature `generic_const_exprs` is incomplete
trait Generic {
const ASSOC: usize;
}
impl Generic for u8 {
const ASSOC: usize = 17;
}
impl Generic for u16 {
const ASSOC: usize = 13;
}
fn uses_assoc_type<T: Generic, const N: usize>() -> [u8; N + T::ASSOC] {
[0; N + T::ASSOC]
}
fn only_generic_n<const N: usize>() -> [u8; N + 13] {
uses_assoc_type::<u16, N>()
}
fn main() {}

View file

@ -0,0 +1,11 @@
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/eval-try-unify.rs:3:12
|
LL | #![feature(generic_const_exprs)]
| ^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
warning: 1 warning emitted

View file

@ -3,6 +3,7 @@
trait TensorDimension {
const DIM : usize;
//~^ ERROR cycle detected when resolving instance `<LazyUpdim<T, {T::DIM}, DIM>
const ISSCALAR : bool = Self::DIM == 0;
fn is_scalar(&self) -> bool {Self::ISSCALAR}
}
@ -42,22 +43,16 @@ impl<'a,T : Broadcastable,const DIM : usize> TensorDimension for LazyUpdim<'a,T,
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)
}
}
@ -76,9 +71,6 @@ 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 ,
@ -86,10 +78,7 @@ impl<'a,R, T : Broadcastable, F : Fn(T::Element) -> R ,
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
}
}

View file

@ -1,130 +1,17 @@
error[E0308]: method not compatible with trait
--> $DIR/issue-83765.rs:44:5
error[E0391]: cycle detected when resolving instance `<LazyUpdim<T, {T::DIM}, DIM> as TensorDimension>::DIM`
--> $DIR/issue-83765.rs:5:5
|
LL | fn size(&self) -> [usize;DIM] {self.size}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Self::DIM`, found `DIM`
LL | const DIM : usize;
| ^^^^^^^^^^^^^^^^^^
|
= note: expected type `Self::DIM`
found type `DIM`
note: ...which requires checking if `TensorDimension` fulfills its obligations...
--> $DIR/issue-83765.rs:4:1
|
LL | trait TensorDimension {
| ^^^^^^^^^^^^^^^^^^^^^
= note: ...which again requires resolving instance `<LazyUpdim<T, {T::DIM}, DIM> as TensorDimension>::DIM`, completing the cycle
= note: cycle used when normalizing `<LazyUpdim<T, {T::DIM}, DIM> as TensorDimension>::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: aborting due to previous error
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`.
For more information about this error, try `rustc --explain E0391`.