Skip to content

Commit eadfd89

Browse files
authored
Rollup merge of rust-lang#91678 - b-naber:tests-for-postpone-const-eval, r=jackh726
Add tests fixed by rust-lang#90023 The following issues were fixed by rust-lang#90023 Fixes rust-lang#79674 Fixes rust-lang#83765 Fixes rust-lang#86033 Fixes rust-lang#90318 Fixes rust-lang#88468 The following issues were duplicates of rust-lang#90654 Fixes rust-lang#86850 Fixes rust-lang#89022 r? ```@jackh726```
2 parents 0614348 + c7f80fc commit eadfd89

File tree

8 files changed

+387
-0
lines changed

8 files changed

+387
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#![feature(const_fn_trait_bound, generic_const_exprs)]
2+
#![allow(incomplete_features)]
3+
4+
trait MiniTypeId {
5+
const TYPE_ID: u64;
6+
}
7+
8+
impl<T> MiniTypeId for T {
9+
const TYPE_ID: u64 = 0;
10+
}
11+
12+
enum Lift<const V: bool> {}
13+
14+
trait IsFalse {}
15+
impl IsFalse for Lift<false> {}
16+
17+
const fn is_same_type<T: MiniTypeId, U: MiniTypeId>() -> bool {
18+
T::TYPE_ID == U::TYPE_ID
19+
}
20+
21+
fn requires_distinct<A, B>(_a: A, _b: B) where
22+
A: MiniTypeId, B: MiniTypeId,
23+
Lift<{is_same_type::<A, B>()}>: IsFalse {}
24+
25+
fn main() {
26+
requires_distinct("str", 12);
27+
//~^ ERROR mismatched types
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-79674.rs:26:5
3+
|
4+
LL | requires_distinct("str", 12);
5+
| ^^^^^^^^^^^^^^^^^ expected `true`, found `false`
6+
|
7+
= note: expected type `true`
8+
found type `false`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0308`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#![feature(generic_const_exprs)]
2+
#![allow(incomplete_features)]
3+
4+
trait TensorDimension {
5+
const DIM : usize;
6+
const ISSCALAR : bool = Self::DIM == 0;
7+
fn is_scalar(&self) -> bool {Self::ISSCALAR}
8+
}
9+
10+
trait TensorSize : TensorDimension {
11+
fn size(&self) -> [usize;Self::DIM];
12+
fn inbounds(&self,index : [usize;Self::DIM]) -> bool {
13+
index.iter().zip(self.size().iter()).all(|(i,s)| i < s)
14+
}
15+
}
16+
17+
18+
trait Broadcastable: TensorSize + Sized {
19+
type Element;
20+
fn bget(&self, index:[usize;Self::DIM]) -> Option<Self::Element>;
21+
fn lazy_updim<const NEWDIM : usize>(&self, size : [usize;NEWDIM] ) ->
22+
LazyUpdim<Self,{Self::DIM},NEWDIM>
23+
{
24+
assert!(NEWDIM >= Self::DIM,
25+
"Updimmed tensor cannot have fewer indices than the initial one.");
26+
LazyUpdim {size,reference:&self}
27+
}
28+
fn bmap<T,F :Fn(Self::Element) -> T>(&self,foo : F) -> BMap<T,Self,F,{Self::DIM}>{
29+
BMap {reference:self,closure : foo}
30+
}
31+
}
32+
33+
34+
struct LazyUpdim<'a,T : Broadcastable,const OLDDIM : usize, const DIM : usize> {
35+
size : [usize;DIM],
36+
reference : &'a T
37+
}
38+
39+
impl<'a,T : Broadcastable,const DIM : usize> TensorDimension for LazyUpdim<'a,T,{T::DIM},DIM> {
40+
const DIM : usize = DIM;
41+
}
42+
43+
impl<'a,T : Broadcastable,const DIM : usize> TensorSize for LazyUpdim<'a,T,{T::DIM},DIM> {
44+
fn size(&self) -> [usize;DIM] {self.size}
45+
//~^ ERROR method not compatible with trait
46+
}
47+
48+
impl<'a,T : Broadcastable,const DIM : usize> Broadcastable for LazyUpdim<'a,T,{T::DIM},DIM>
49+
{
50+
type Element = T::Element;
51+
fn bget(&self,index:[usize;DIM]) -> Option<Self::Element> {
52+
//~^ ERROR method not compatible with trait
53+
assert!(DIM >= T::DIM);
54+
if !self.inbounds(index) {return None}
55+
//~^ ERROR unconstrained generic constant
56+
//~| ERROR mismatched types
57+
let size = self.size();
58+
//~^ ERROR unconstrained generic constant
59+
let newindex : [usize;T::DIM] = Default::default();
60+
//~^ ERROR the trait bound `[usize; _]: Default` is not satisfied
61+
self.reference.bget(newindex)
62+
}
63+
}
64+
65+
struct BMap<'a,R, T : Broadcastable, F : Fn(T::Element) -> R , const DIM: usize> {
66+
reference : &'a T,
67+
closure : F
68+
}
69+
70+
impl<'a,R, T : Broadcastable, F : Fn(T::Element) -> R,
71+
const DIM: usize> TensorDimension for BMap<'a,R,T,F,DIM> {
72+
73+
const DIM : usize = DIM;
74+
}
75+
impl<'a,R, T : Broadcastable, F : Fn(T::Element) -> R ,
76+
const DIM: usize> TensorSize for BMap<'a,R,T,F,DIM> {
77+
78+
fn size(&self) -> [usize;DIM] {self.reference.size()}
79+
//~^ ERROR unconstrained generic constant
80+
//~| ERROR mismatched types
81+
//~| ERROR method not compatible with trait
82+
}
83+
84+
impl<'a,R, T : Broadcastable, F : Fn(T::Element) -> R ,
85+
const DIM: usize> Broadcastable for BMap<'a,R,T,F,DIM> {
86+
87+
type Element = R;
88+
fn bget(&self,index:[usize;DIM]) -> Option<Self::Element> {
89+
//~^ ERROR method not compatible with trait
90+
self.reference.bget(index).map(&self.closure)
91+
//~^ ERROR unconstrained generic constant
92+
//~| ERROR mismatched types
93+
}
94+
}
95+
96+
impl<T> TensorDimension for Vec<T> {
97+
const DIM : usize = 1;
98+
}
99+
impl<T> TensorSize for Vec<T> {
100+
fn size(&self) -> [usize;1] {[self.len()]}
101+
}
102+
impl<T: Clone> Broadcastable for Vec<T> {
103+
type Element = T;
104+
fn bget(& self,index : [usize;1]) -> Option<T> {
105+
self.get(index[0]).cloned()
106+
}
107+
}
108+
109+
fn main() {
110+
let v = vec![1,2,3];
111+
let bv = v.lazy_updim([3,4]);
112+
let bbv = bv.bmap(|x| x*x);
113+
114+
println!("The size of v is {:?}",bbv.bget([0,2]).expect("Out of bounds."));
115+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
error[E0308]: method not compatible with trait
2+
--> $DIR/issue-83765.rs:44:5
3+
|
4+
LL | fn size(&self) -> [usize;DIM] {self.size}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Self::DIM`, found `DIM`
6+
|
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`
123+
|
124+
= note: expected type `Self::DIM`
125+
found type `DIM`
126+
127+
error: aborting due to 12 previous errors
128+
129+
Some errors have detailed explanations: E0277, E0308.
130+
For more information about an error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// check-pass
2+
3+
#![feature(generic_const_exprs)]
4+
#![allow(incomplete_features)]
5+
6+
pub trait IsTrue<const T: bool> {}
7+
impl IsTrue<true> for () {}
8+
9+
pub trait IsZST {}
10+
11+
impl<T> IsZST for T
12+
where
13+
(): IsTrue<{ std::mem::size_of::<T>() == 0 }>
14+
{}
15+
16+
fn _func() -> impl IsZST {
17+
|| {}
18+
}
19+
20+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// check-pass
2+
3+
#![allow(incomplete_features)]
4+
#![feature(generic_const_exprs)]
5+
6+
pub struct Assert<const COND: bool>();
7+
pub trait IsTrue {}
8+
impl IsTrue for Assert<true> {}
9+
10+
pub trait IsNotZST {}
11+
impl<T> IsNotZST for T where Assert<{ std::mem::size_of::<T>() > 0 }>: IsTrue {}
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#![feature(const_type_id)]
2+
#![feature(generic_const_exprs)]
3+
#![feature(core_intrinsics)]
4+
#![allow(incomplete_features)]
5+
6+
use std::any::TypeId;
7+
8+
struct If<const B: bool>;
9+
pub trait True {}
10+
impl True for If<true> {}
11+
12+
fn consume<T: 'static>(_val: T)
13+
where
14+
If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
15+
//~^ ERROR: overly complex generic constant
16+
//~| ERROR: calls in constants are limited to constant functions
17+
{
18+
}
19+
20+
fn test<T: 'static>()
21+
where
22+
If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
23+
//~^ ERROR: overly complex generic constant
24+
//~| ERROR: calls in constants are limited to constant functions
25+
{
26+
}
27+
28+
fn main() {
29+
let a = ();
30+
consume(0i32);
31+
consume(a);
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
error: overly complex generic constant
2+
--> $DIR/issue-90318.rs:14:8
3+
|
4+
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
5+
| ^^-----------------^^^^^^^^^^^^^^^^^^^^^^^^
6+
| |
7+
| borrowing is not supported in generic constants
8+
|
9+
= help: consider moving this anonymous constant into a `const` function
10+
= note: this operation may be supported in the future
11+
12+
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
13+
--> $DIR/issue-90318.rs:14:10
14+
|
15+
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
18+
error: overly complex generic constant
19+
--> $DIR/issue-90318.rs:22:8
20+
|
21+
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
22+
| ^^-----------------^^^^^^^^^^^^^^^^^^^^^^^^
23+
| |
24+
| borrowing is not supported in generic constants
25+
|
26+
= help: consider moving this anonymous constant into a `const` function
27+
= note: this operation may be supported in the future
28+
29+
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
30+
--> $DIR/issue-90318.rs:22:10
31+
|
32+
LL | If<{ TypeId::of::<T>() != TypeId::of::<()>() }>: True,
33+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
34+
35+
error: aborting due to 4 previous errors
36+
37+
For more information about this error, try `rustc --explain E0015`.

0 commit comments

Comments
 (0)