Skip to content

Commit 6cf3409

Browse files
committed
add/update tests
1 parent 3b9de6b commit 6cf3409

File tree

4 files changed

+50
-137
lines changed

4 files changed

+50
-137
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// build-pass
2+
3+
#![feature(generic_const_exprs)]
4+
//~^ WARNING the feature `generic_const_exprs` is incomplete
5+
6+
trait Generic {
7+
const ASSOC: usize;
8+
}
9+
10+
impl Generic for u8 {
11+
const ASSOC: usize = 17;
12+
}
13+
impl Generic for u16 {
14+
const ASSOC: usize = 13;
15+
}
16+
17+
18+
fn uses_assoc_type<T: Generic, const N: usize>() -> [u8; N + T::ASSOC] {
19+
[0; N + T::ASSOC]
20+
}
21+
22+
fn only_generic_n<const N: usize>() -> [u8; N + 13] {
23+
uses_assoc_type::<u16, N>()
24+
}
25+
26+
fn main() {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/eval-try-unify.rs:3:12
3+
|
4+
LL | #![feature(generic_const_exprs)]
5+
| ^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
= note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
9+
10+
warning: 1 warning emitted
11+

src/test/ui/const-generics/issues/issue-83765.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
trait TensorDimension {
55
const DIM : usize;
6+
//~^ ERROR cycle detected when resolving instance `<LazyUpdim<T, {T::DIM}, DIM>
67
const ISSCALAR : bool = Self::DIM == 0;
78
fn is_scalar(&self) -> bool {Self::ISSCALAR}
89
}
@@ -42,22 +43,16 @@ impl<'a,T : Broadcastable,const DIM : usize> TensorDimension for LazyUpdim<'a,T,
4243

4344
impl<'a,T : Broadcastable,const DIM : usize> TensorSize for LazyUpdim<'a,T,{T::DIM},DIM> {
4445
fn size(&self) -> [usize;DIM] {self.size}
45-
//~^ ERROR method not compatible with trait
4646
}
4747

4848
impl<'a,T : Broadcastable,const DIM : usize> Broadcastable for LazyUpdim<'a,T,{T::DIM},DIM>
4949
{
5050
type Element = T::Element;
5151
fn bget(&self,index:[usize;DIM]) -> Option<Self::Element> {
52-
//~^ ERROR method not compatible with trait
5352
assert!(DIM >= T::DIM);
5453
if !self.inbounds(index) {return None}
55-
//~^ ERROR unconstrained generic constant
56-
//~| ERROR mismatched types
5754
let size = self.size();
58-
//~^ ERROR unconstrained generic constant
5955
let newindex : [usize;T::DIM] = Default::default();
60-
//~^ ERROR the trait bound `[usize; _]: Default` is not satisfied
6156
self.reference.bget(newindex)
6257
}
6358
}
@@ -76,20 +71,14 @@ impl<'a,R, T : Broadcastable, F : Fn(T::Element) -> R ,
7671
const DIM: usize> TensorSize for BMap<'a,R,T,F,DIM> {
7772

7873
fn size(&self) -> [usize;DIM] {self.reference.size()}
79-
//~^ ERROR unconstrained generic constant
80-
//~| ERROR mismatched types
81-
//~| ERROR method not compatible with trait
8274
}
8375

8476
impl<'a,R, T : Broadcastable, F : Fn(T::Element) -> R ,
8577
const DIM: usize> Broadcastable for BMap<'a,R,T,F,DIM> {
8678

8779
type Element = R;
8880
fn bget(&self,index:[usize;DIM]) -> Option<Self::Element> {
89-
//~^ ERROR method not compatible with trait
9081
self.reference.bget(index).map(&self.closure)
91-
//~^ ERROR unconstrained generic constant
92-
//~| ERROR mismatched types
9382
}
9483
}
9584

Lines changed: 12 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,17 @@
1-
error[E0308]: method not compatible with trait
2-
--> $DIR/issue-83765.rs:44:5
1+
error[E0391]: cycle detected when resolving instance `<LazyUpdim<T, {T::DIM}, DIM> as TensorDimension>::DIM`
2+
--> $DIR/issue-83765.rs:5:5
33
|
4-
LL | fn size(&self) -> [usize;DIM] {self.size}
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Self::DIM`, found `DIM`
4+
LL | const DIM : usize;
5+
| ^^^^^^^^^^^^^^^^^^
66
|
7-
= note: expected type `Self::DIM`
8-
found type `DIM`
9-
10-
error[E0308]: method not compatible with trait
11-
--> $DIR/issue-83765.rs:51:5
12-
|
13-
LL | fn bget(&self,index:[usize;DIM]) -> Option<Self::Element> {
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Self::DIM`, found `DIM`
15-
|
16-
= note: expected type `Self::DIM`
17-
found type `DIM`
18-
19-
error[E0308]: method not compatible with trait
20-
--> $DIR/issue-83765.rs:78:5
21-
|
22-
LL | fn size(&self) -> [usize;DIM] {self.reference.size()}
23-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Self::DIM`, found `DIM`
24-
|
25-
= note: expected type `Self::DIM`
26-
found type `DIM`
27-
28-
error[E0308]: method not compatible with trait
29-
--> $DIR/issue-83765.rs:88:5
30-
|
31-
LL | fn bget(&self,index:[usize;DIM]) -> Option<Self::Element> {
32-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Self::DIM`, found `DIM`
33-
|
34-
= note: expected type `Self::DIM`
35-
found type `DIM`
36-
37-
error: unconstrained generic constant
38-
--> $DIR/issue-83765.rs:54:18
39-
|
40-
LL | if !self.inbounds(index) {return None}
41-
| ^^^^^^^^
42-
|
43-
= help: try adding a `where` bound using this expression: `where [(); Self::DIM]:`
44-
note: required by a bound in `TensorSize::inbounds`
45-
--> $DIR/issue-83765.rs:12:38
46-
|
47-
LL | fn inbounds(&self,index : [usize;Self::DIM]) -> bool {
48-
| ^^^^^^^^^ required by this bound in `TensorSize::inbounds`
49-
50-
error[E0308]: mismatched types
51-
--> $DIR/issue-83765.rs:54:27
52-
|
53-
LL | if !self.inbounds(index) {return None}
54-
| ^^^^^ expected `Self::DIM`, found `DIM`
55-
|
56-
= note: expected type `Self::DIM`
57-
found type `DIM`
58-
59-
error: unconstrained generic constant
60-
--> $DIR/issue-83765.rs:57:25
61-
|
62-
LL | let size = self.size();
63-
| ^^^^
64-
|
65-
= help: try adding a `where` bound using this expression: `where [(); Self::DIM]:`
66-
note: required by a bound in `TensorSize::size`
67-
--> $DIR/issue-83765.rs:11:30
68-
|
69-
LL | fn size(&self) -> [usize;Self::DIM];
70-
| ^^^^^^^^^ required by this bound in `TensorSize::size`
71-
72-
error[E0277]: the trait bound `[usize; _]: Default` is not satisfied
73-
--> $DIR/issue-83765.rs:59:41
74-
|
75-
LL | let newindex : [usize;T::DIM] = Default::default();
76-
| ^^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `[usize; _]`
77-
|
78-
help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement
79-
|
80-
LL | impl<'a,T : Broadcastable,const DIM : usize> Broadcastable for LazyUpdim<'a,T,{T::DIM},DIM> where [usize; _]: Default
81-
| +++++++++++++++++++++++++
82-
83-
error: unconstrained generic constant
84-
--> $DIR/issue-83765.rs:78:51
85-
|
86-
LL | fn size(&self) -> [usize;DIM] {self.reference.size()}
87-
| ^^^^
88-
|
89-
= help: try adding a `where` bound using this expression: `where [(); Self::DIM]:`
90-
note: required by a bound in `TensorSize::size`
91-
--> $DIR/issue-83765.rs:11:30
92-
|
93-
LL | fn size(&self) -> [usize;Self::DIM];
94-
| ^^^^^^^^^ required by this bound in `TensorSize::size`
95-
96-
error[E0308]: mismatched types
97-
--> $DIR/issue-83765.rs:78:36
98-
|
99-
LL | fn size(&self) -> [usize;DIM] {self.reference.size()}
100-
| ^^^^^^^^^^^^^^^^^^^^^ expected `DIM`, found `Self::DIM`
101-
|
102-
= note: expected type `DIM`
103-
found type `Self::DIM`
104-
105-
error: unconstrained generic constant
106-
--> $DIR/issue-83765.rs:90:24
107-
|
108-
LL | self.reference.bget(index).map(&self.closure)
109-
| ^^^^
110-
|
111-
= help: try adding a `where` bound using this expression: `where [(); Self::DIM]:`
112-
note: required by a bound in `Broadcastable::bget`
113-
--> $DIR/issue-83765.rs:20:33
114-
|
115-
LL | fn bget(&self, index:[usize;Self::DIM]) -> Option<Self::Element>;
116-
| ^^^^^^^^^ required by this bound in `Broadcastable::bget`
117-
118-
error[E0308]: mismatched types
119-
--> $DIR/issue-83765.rs:90:29
120-
|
121-
LL | self.reference.bget(index).map(&self.closure)
122-
| ^^^^^ expected `Self::DIM`, found `DIM`
7+
note: ...which requires checking if `TensorDimension` fulfills its obligations...
8+
--> $DIR/issue-83765.rs:4:1
1239
|
124-
= note: expected type `Self::DIM`
125-
found type `DIM`
10+
LL | trait TensorDimension {
11+
| ^^^^^^^^^^^^^^^^^^^^^
12+
= note: ...which again requires resolving instance `<LazyUpdim<T, {T::DIM}, DIM> as TensorDimension>::DIM`, completing the cycle
13+
= note: cycle used when normalizing `<LazyUpdim<T, {T::DIM}, DIM> as TensorDimension>::DIM`
12614

127-
error: aborting due to 12 previous errors
15+
error: aborting due to previous error
12816

129-
Some errors have detailed explanations: E0277, E0308.
130-
For more information about an error, try `rustc --explain E0277`.
17+
For more information about this error, try `rustc --explain E0391`.

0 commit comments

Comments
 (0)