diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
commit | 9835e2ae736235810b4ea1c162ca5e65c547e770 (patch) | |
tree | 3fcebf40ed70e581d776a8a4c65923e8ec20e026 /tests/incremental/const-generics | |
parent | Releasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff) | |
download | rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip |
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/incremental/const-generics')
-rw-r--r-- | tests/incremental/const-generics/change-const-param-gat.rs | 29 | ||||
-rw-r--r-- | tests/incremental/const-generics/change-const-param-type.rs | 68 |
2 files changed, 97 insertions, 0 deletions
diff --git a/tests/incremental/const-generics/change-const-param-gat.rs b/tests/incremental/const-generics/change-const-param-gat.rs new file mode 100644 index 000000000..f1449d568 --- /dev/null +++ b/tests/incremental/const-generics/change-const-param-gat.rs @@ -0,0 +1,29 @@ +// revisions: rpass1 rpass2 rpass3 +// compile-flags: -Zincremental-ignore-spans +#![feature(generic_associated_types)] + +// This test unsures that with_opt_const_param returns the +// def_id of the N param in the Foo::Assoc GAT. + +trait Foo { + type Assoc<const N: usize>; + fn foo( + &self, + ) -> Self::Assoc<{ if cfg!(rpass2) { 3 } else { 2 } }>; +} + +impl Foo for () { + type Assoc<const N: usize> = [(); N]; + fn foo( + &self, + ) -> Self::Assoc<{ if cfg!(rpass2) { 3 } else { 2 } }> { + [(); { if cfg!(rpass2) { 3 } else { 2 } }] + } +} + +fn main() { + assert_eq!( + ().foo(), + [(); { if cfg!(rpass2) { 3 } else { 2 } }] + ); +} diff --git a/tests/incremental/const-generics/change-const-param-type.rs b/tests/incremental/const-generics/change-const-param-type.rs new file mode 100644 index 000000000..1aac1bc7d --- /dev/null +++ b/tests/incremental/const-generics/change-const-param-type.rs @@ -0,0 +1,68 @@ +// revisions: rpass1 rpass2 rpass3 +// compile-flags: -Zincremental-ignore-spans + +enum Foo<const N: usize> { + Variant, + Variant2(), + Variant3 {}, +} + +impl Foo<1> { + fn foo<const N: usize>(&self) -> [(); N] { [(); N] } +} + +impl Foo<2> { + fn foo<const N: u32>(self) -> usize { N as usize } +} + +struct Bar<const N: usize>; +struct Bar2<const N: usize>(); +struct Bar3<const N: usize> {} + +#[cfg(rpass1)] +struct ChangingStruct<const N: usize>; + +#[cfg(any(rpass2, rpass3))] +struct ChangingStruct<const N: u32>; + +struct S; + +impl S { + #[cfg(rpass1)] + fn changing_method<const N: usize>(self) {} + + #[cfg(any(rpass2, rpass3))] + fn changing_method<const N: u32>(self) {} +} + +// We want to verify that all goes well when the value of the const argument change. +// To avoid modifying `main`'s HIR, we use a separate constant, and use `{ FOO_ARG + 1 }` +// inside the body to keep having an `AnonConst` to compute. +const FOO_ARG: usize = if cfg!(rpass2) { 1 } else { 0 }; + +fn main() { + let foo = Foo::Variant::<{ FOO_ARG + 1 }>; + foo.foo::<{ if cfg!(rpass3) { 3 } else { 4 } }>(); + + let foo = Foo::Variant2::<{ FOO_ARG + 1 }>(); + foo.foo::<{ if cfg!(rpass3) { 3 } else { 4 } }>(); + + let foo = Foo::Variant3::<{ FOO_ARG + 1 }> {}; + foo.foo::<{ if cfg!(rpass3) { 3 } else { 4 } }>(); + + let foo = Foo::<{ FOO_ARG + 1 }>::Variant; + foo.foo::<{ if cfg!(rpass3) { 3 } else { 4 } }>(); + + let foo = Foo::<{ FOO_ARG + 1 }>::Variant2(); + foo.foo::<{ if cfg!(rpass3) { 3 } else { 4 } }>(); + + let foo = Foo::<{ FOO_ARG + 1 }>::Variant3 {}; + foo.foo::<{ if cfg!(rpass3) { 3 } else { 4 } }>(); + + let _ = Bar::<{ FOO_ARG + 1 }>; + let _ = Bar2::<{ FOO_ARG + 1 }>(); + let _ = Bar3::<{ FOO_ARG + 1 }> {}; + + let _ = ChangingStruct::<{ 5 }>; + let _ = S.changing_method::<{ 5 }>(); +} |