diff options
| author | Ralf Jung <post@ralfj.de> | 2024-01-28 10:03:02 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2024-02-05 20:36:11 +0100 |
| commit | e00df17abd6eabfead30dce439592b1902fd0acd (patch) | |
| tree | c93d1fc9e4f65bf955c1633f666f8c30895cb210 | |
| parent | 45d01b81311b0888530cd9a394b62d6af04bd972 (diff) | |
| download | rust-e00df17abd6eabfead30dce439592b1902fd0acd.tar.gz rust-e00df17abd6eabfead30dce439592b1902fd0acd.zip | |
merge the accepted-structural-match tests into one
| -rw-r--r-- | tests/ui/consts/const_in_pattern/accept_corner_cases.rs | 34 | ||||
| -rw-r--r-- | tests/ui/consts/const_in_pattern/accept_structural.rs | 14 |
2 files changed, 14 insertions, 34 deletions
diff --git a/tests/ui/consts/const_in_pattern/accept_corner_cases.rs b/tests/ui/consts/const_in_pattern/accept_corner_cases.rs deleted file mode 100644 index d5b3908f354..00000000000 --- a/tests/ui/consts/const_in_pattern/accept_corner_cases.rs +++ /dev/null @@ -1,34 +0,0 @@ -// run-pass - -// This test is checking our logic for structural match checking by enumerating -// the different kinds of const expressions. This test is collecting cases where -// we have accepted the const expression as a pattern in the past and wish to -// continue doing so. - -// The specific corner cases we are exploring here are instances where the -// const-evaluator computes a value that *does* meet the conditions for -// structural-match, but the const expression itself has abstractions (like -// calls to const functions) that may fit better with a type-based analysis -// rather than a commitment to a specific value. - -#![warn(indirect_structural_match)] - -#[derive(Copy, Clone, Debug)] -struct NoDerive(#[allow(dead_code)] u32); - -// This impl makes `NoDerive` irreflexive. -impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } } -impl Eq for NoDerive { } - -fn main() { - const INDEX: Option<NoDerive> = [None, Some(NoDerive(10))][0]; - match None { Some(_) => panic!("whoops"), INDEX => dbg!(INDEX), }; - - const fn build() -> Option<NoDerive> { None } - const CALL: Option<NoDerive> = build(); - match None { Some(_) => panic!("whoops"), CALL => dbg!(CALL), }; - - impl NoDerive { const fn none() -> Option<NoDerive> { None } } - const METHOD_CALL: Option<NoDerive> = NoDerive::none(); - match None { Some(_) => panic!("whoops"), METHOD_CALL => dbg!(METHOD_CALL), }; -} diff --git a/tests/ui/consts/const_in_pattern/accept_structural.rs b/tests/ui/consts/const_in_pattern/accept_structural.rs index 1f56f581c02..69b4e75c622 100644 --- a/tests/ui/consts/const_in_pattern/accept_structural.rs +++ b/tests/ui/consts/const_in_pattern/accept_structural.rs @@ -63,4 +63,18 @@ fn main() { const ADDR_OF: &OND = &None; match &None { ADDR_OF => dbg!(ADDR_OF), _ => panic!("whoops"), }; + + // These ones are more subtle: the final value is fine, but statically analyzing the expression + // that computes the value would likely (incorrectly) have us conclude that this may match on + // values that do not have structural equality. + const INDEX: Option<NoDerive> = [None, Some(NoDerive(10))][0]; + match None { Some(_) => panic!("whoops"), INDEX => dbg!(INDEX), }; + + const fn build() -> Option<NoDerive> { None } + const CALL: Option<NoDerive> = build(); + match None { Some(_) => panic!("whoops"), CALL => dbg!(CALL), }; + + impl NoDerive { const fn none() -> Option<NoDerive> { None } } + const METHOD_CALL: Option<NoDerive> = NoDerive::none(); + match None { Some(_) => panic!("whoops"), METHOD_CALL => dbg!(METHOD_CALL), }; } |
