Skip to content

Commit dcd0e1d

Browse files
authored
Rollup merge of #88602 - BoxyUwU:tests-uwu-nya, r=lcnr
Add tests for some const generics issues closes #82956 closes #84659 closes #86530 closes #86535 there is also a random test in here about array repeat expressions that I already had on this branch but it seems to fit the theme of this PR so kept it... r? `@lcnr`
2 parents b2d9bcd + 89c6d4f commit dcd0e1d

10 files changed

+203
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#![feature(generic_const_exprs, array_map)]
2+
#![allow(incomplete_features)]
3+
4+
pub struct ConstCheck<const CHECK: bool>;
5+
6+
pub trait True {}
7+
impl True for ConstCheck<true> {}
8+
9+
pub trait OrdesDec {
10+
type Newlen;
11+
type Output;
12+
13+
fn pop(self) -> (Self::Newlen, Self::Output);
14+
}
15+
16+
impl<T, const N: usize> OrdesDec for [T; N]
17+
where
18+
ConstCheck<{N > 1}>: True,
19+
[T; N - 1]: Sized,
20+
{
21+
type Newlen = [T; N - 1];
22+
type Output = T;
23+
24+
fn pop(self) -> (Self::Newlen, Self::Output) {
25+
let mut iter = IntoIter::new(self);
26+
//~^ ERROR: failed to resolve: use of undeclared type `IntoIter`
27+
let end = iter.next_back().unwrap();
28+
let new = [(); N - 1].map(move |()| iter.next().unwrap());
29+
(new, end)
30+
}
31+
}
32+
33+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0433]: failed to resolve: use of undeclared type `IntoIter`
2+
--> $DIR/issue-82956.rs:25:24
3+
|
4+
LL | let mut iter = IntoIter::new(self);
5+
| ^^^^^^^^ not found in this scope
6+
|
7+
help: consider importing one of these items
8+
|
9+
LL | use std::array::IntoIter;
10+
|
11+
LL | use std::collections::binary_heap::IntoIter;
12+
|
13+
LL | use std::collections::btree_map::IntoIter;
14+
|
15+
LL | use std::collections::btree_set::IntoIter;
16+
|
17+
and 8 other candidates
18+
19+
error: aborting due to previous error
20+
21+
For more information about this error, try `rustc --explain E0433`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![allow(incomplete_features)]
2+
#![feature(generic_const_exprs)]
3+
4+
trait Bar<const N: usize> {}
5+
6+
trait Foo<'a> {
7+
const N: usize;
8+
type Baz: Bar<{ Self::N }>;
9+
//~^ ERROR: unconstrained generic constant
10+
}
11+
12+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: unconstrained generic constant
2+
--> $DIR/issue-84659.rs:8:15
3+
|
4+
LL | type Baz: Bar<{ Self::N }>;
5+
| ^^^^^^^^^^^^^^^^
6+
|
7+
= help: try adding a `where` bound using this expression: `where [(); { Self::N }]:`
8+
9+
error: aborting due to previous error
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![feature(generic_const_exprs)]
2+
#![allow(incomplete_features)]
3+
4+
pub trait X {
5+
const Y: usize;
6+
}
7+
8+
fn z<T>(t: T)
9+
where
10+
T: X,
11+
[(); T::Y]: ,
12+
{
13+
}
14+
15+
fn unit_literals() {
16+
z(" ");
17+
//~^ ERROR: the trait bound `&str: X` is not satisfied
18+
}
19+
20+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0277]: the trait bound `&str: X` is not satisfied
2+
--> $DIR/issue-86530.rs:16:7
3+
|
4+
LL | z(" ");
5+
| ^^^ the trait `X` is not implemented for `&str`
6+
|
7+
note: required by a bound in `z`
8+
--> $DIR/issue-86530.rs:10:8
9+
|
10+
LL | fn z<T>(t: T)
11+
| - required by a bound in this
12+
LL | where
13+
LL | T: X,
14+
| ^ required by this bound in `z`
15+
16+
error: aborting due to previous error
17+
18+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// run-pass
2+
#![feature(adt_const_params, generic_const_exprs)]
3+
#![allow(incomplete_features)]
4+
5+
pub trait Foo {
6+
const ASSOC_C: usize;
7+
fn foo() where [(); Self::ASSOC_C]:;
8+
}
9+
10+
struct Bar<const N: &'static ()>;
11+
impl<const N: &'static ()> Foo for Bar<N> {
12+
const ASSOC_C: usize = 3;
13+
14+
fn foo() where [u8; Self::ASSOC_C]: {
15+
let _: [u8; Self::ASSOC_C] = loop {};
16+
}
17+
}
18+
19+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// run-pass
2+
#![feature(adt_const_params, generic_const_exprs)]
3+
#![allow(incomplete_features, unused_variables)]
4+
5+
struct F<const S: &'static str>;
6+
impl<const S: &'static str> X for F<{ S }> {
7+
const W: usize = 3;
8+
9+
fn d(r: &[u8; Self::W]) -> F<{ S }> {
10+
let x: [u8; Self::W] = [0; Self::W];
11+
F
12+
}
13+
}
14+
15+
pub trait X {
16+
const W: usize;
17+
fn d(r: &[u8; Self::W]) -> Self;
18+
}
19+
20+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
trait Trait<const N: usize> {
2+
const Assoc: usize;
3+
}
4+
5+
impl<const N: usize> Trait<N> for () {
6+
const Assoc: usize = 1;
7+
}
8+
9+
10+
pub const fn foo<const N: usize>() where (): Trait<N> {
11+
let bar = [(); <()>::Assoc];
12+
//~^ error: constant expression depends on a generic parameter
13+
}
14+
15+
trait Trait2<const N: usize> {
16+
const Assoc2: usize;
17+
}
18+
19+
impl<const N: usize> Trait2<N> for () {
20+
const Assoc2: usize = N - 1;
21+
}
22+
23+
24+
pub const fn foo2<const N: usize>() where (): Trait2<N> {
25+
let bar2 = [(); <()>::Assoc2];
26+
//~^ error: constant expression depends on a generic parameter
27+
}
28+
29+
fn main() {
30+
foo::<0>();
31+
foo2::<0>();
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: constant expression depends on a generic parameter
2+
--> $DIR/sneaky-array-repeat-expr.rs:11:20
3+
|
4+
LL | let bar = [(); <()>::Assoc];
5+
| ^^^^^^^^^^^
6+
|
7+
= note: this may fail depending on what value the parameter takes
8+
9+
error: constant expression depends on a generic parameter
10+
--> $DIR/sneaky-array-repeat-expr.rs:25:21
11+
|
12+
LL | let bar2 = [(); <()>::Assoc2];
13+
| ^^^^^^^^^^^^
14+
|
15+
= note: this may fail depending on what value the parameter takes
16+
17+
error: aborting due to 2 previous errors
18+

0 commit comments

Comments
 (0)