Skip to content

Commit e5565b1

Browse files
committed
Add incremental tests.
1 parent a395d2a commit e5565b1

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// revisions: rpass1 rpass2 rpass3
2+
// compile-flags: -Zincremental-ignore-spans
3+
#![feature(generic_associated_types)]
4+
5+
// This test unsures that with_opt_const_param returns the
6+
// def_id of the N param in the Foo::Assoc GAT.
7+
8+
trait Foo {
9+
type Assoc<const N: usize>;
10+
fn foo(
11+
&self,
12+
) -> Self::Assoc<{ if cfg!(rpass2) { 3 } else { 2 } }>;
13+
}
14+
15+
impl Foo for () {
16+
type Assoc<const N: usize> = [(); N];
17+
fn foo(
18+
&self,
19+
) -> Self::Assoc<{ if cfg!(rpass2) { 3 } else { 2 } }> {
20+
[(); { if cfg!(rpass2) { 3 } else { 2 } }]
21+
}
22+
}
23+
24+
fn main() {
25+
assert_eq!(
26+
().foo(),
27+
[(); { if cfg!(rpass2) { 3 } else { 2 } }]
28+
);
29+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// revisions: rpass1 rpass2 rpass3
2+
// compile-flags: -Zincremental-ignore-spans
3+
4+
enum Foo<const N: usize> {
5+
Variant,
6+
Variant2(),
7+
Variant3 {},
8+
}
9+
10+
impl Foo<1> {
11+
fn foo<const N: usize>(&self) -> [(); N] { [(); N] }
12+
}
13+
14+
impl Foo<2> {
15+
fn foo<const N: u32>(self) -> usize { N as usize }
16+
}
17+
18+
struct Bar<const N: usize>;
19+
struct Bar2<const N: usize>();
20+
struct Bar3<const N: usize> {}
21+
22+
#[cfg(rpass1)]
23+
struct ChangingStruct<const N: usize>;
24+
25+
#[cfg(any(rpass2, rpass3))]
26+
struct ChangingStruct<const N: u32>;
27+
28+
struct S;
29+
30+
impl S {
31+
#[cfg(rpass1)]
32+
fn changing_method<const N: usize>(self) {}
33+
34+
#[cfg(any(rpass2, rpass3))]
35+
fn changing_method<const N: u32>(self) {}
36+
}
37+
38+
// We want to verify that all goes well when the value of the const argument change.
39+
// To avoid modifying `main`'s HIR, we use a separate constant, and use `{ FOO_ARG + 1 }`
40+
// inside the body to keep having an `AnonConst` to compute.
41+
const FOO_ARG: usize = if cfg!(rpass2) { 1 } else { 0 };
42+
43+
fn main() {
44+
let foo = Foo::Variant::<{ FOO_ARG + 1 }>;
45+
foo.foo::<{ if cfg!(rpass3) { 3 } else { 4 } }>();
46+
47+
let foo = Foo::Variant2::<{ FOO_ARG + 1 }>();
48+
foo.foo::<{ if cfg!(rpass3) { 3 } else { 4 } }>();
49+
50+
let foo = Foo::Variant3::<{ FOO_ARG + 1 }> {};
51+
foo.foo::<{ if cfg!(rpass3) { 3 } else { 4 } }>();
52+
53+
let foo = Foo::<{ FOO_ARG + 1 }>::Variant;
54+
foo.foo::<{ if cfg!(rpass3) { 3 } else { 4 } }>();
55+
56+
let foo = Foo::<{ FOO_ARG + 1 }>::Variant2();
57+
foo.foo::<{ if cfg!(rpass3) { 3 } else { 4 } }>();
58+
59+
let foo = Foo::<{ FOO_ARG + 1 }>::Variant3 {};
60+
foo.foo::<{ if cfg!(rpass3) { 3 } else { 4 } }>();
61+
62+
let _ = Bar::<{ FOO_ARG + 1 }>;
63+
let _ = Bar2::<{ FOO_ARG + 1 }>();
64+
let _ = Bar3::<{ FOO_ARG + 1 }> {};
65+
66+
let _ = ChangingStruct::<{ 5 }>;
67+
let _ = S.changing_method::<{ 5 }>();
68+
}

0 commit comments

Comments
 (0)