merge the accepted-structural-match tests into one
This commit is contained in:
parent
45d01b8131
commit
e00df17abd
@ -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), };
|
||||
}
|
@ -63,4 +63,18 @@ enum CLike { One = 1, #[allow(dead_code)] Two = 2, }
|
||||
|
||||
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), };
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user