Skip to content

Commit 44d27ba

Browse files
committed
Change indirect_structural_match lint to allow-by-default.
This is a way to address the regression aspect of #62614 in the short term without actually fixing the bug. (My thinking is that the bug that this lint detects has gone undetected for this long, it can wait a bit longer until I or someone else has a chance to put in a proper fix that accounts for #62614.)
1 parent 00e0d87 commit 44d27ba

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

src/librustc/lint/builtin.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ declare_lint! {
350350

351351
declare_lint! {
352352
pub INDIRECT_STRUCTURAL_MATCH,
353-
Warn,
353+
// defaulting to allow until rust-lang/rust#62614 is fixed.
354+
Allow,
354355
"pattern with const indirectly referencing non-`#[structural_match]` type"
355356
}
356357

@@ -451,6 +452,7 @@ declare_lint_pass! {
451452
AMBIGUOUS_ASSOCIATED_ITEMS,
452453
NESTED_IMPL_TRAIT,
453454
MUTABLE_BORROW_RESERVATION_CONFLICT,
455+
INDIRECT_STRUCTURAL_MATCH,
454456
]
455457
}
456458

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// rust-lang/rust#62614: we want to allow matching on constants of types that
2+
// have non-structural-match variants, *if* the constant itself does not use
3+
// any such variant.
4+
5+
// NOTE: for now, deliberately leaving the lint `indirect_structural_match` set
6+
// to its default, so that we will not issue a diangostic even if
7+
// rust-lang/rust#62614 remains an open issue.
8+
9+
// run-pass
10+
11+
struct Sum(u32, u32);
12+
13+
impl PartialEq for Sum {
14+
fn eq(&self, other: &Self) -> bool { self.0 + self.1 == other.0 + other.1 }
15+
}
16+
17+
impl Eq for Sum { }
18+
19+
#[derive(PartialEq, Eq)]
20+
enum Eek {
21+
TheConst,
22+
UnusedByTheConst(Sum)
23+
}
24+
25+
const THE_CONST: Eek = Eek::TheConst;
26+
const SUM_THREE: Eek = Eek::UnusedByTheConst(Sum(3,0));
27+
28+
const EEK_ZERO: &[Eek] = &[];
29+
const EEK_ONE: &[Eek] = &[THE_CONST];
30+
31+
pub fn main() {
32+
match Eek::UnusedByTheConst(Sum(1,2)) {
33+
ref sum if sum == &SUM_THREE => { println!("Hello 0"); }
34+
_ => { println!("Gbye"); }
35+
}
36+
37+
match Eek::TheConst {
38+
THE_CONST => { println!("Hello 1"); }
39+
_ => { println!("Gbye"); }
40+
}
41+
42+
43+
match & &Eek::TheConst {
44+
& & THE_CONST => { println!("Hello 2"); }
45+
_ => { println!("Gbye"); }
46+
}
47+
48+
match & & &[][..] {
49+
& & EEK_ZERO => { println!("Hello 3"); }
50+
& & EEK_ONE => { println!("Gbye"); }
51+
_ => { println!("Gbye"); }
52+
}
53+
54+
match & & &[Eek::TheConst][..] {
55+
& & EEK_ZERO => { println!("Gby"); }
56+
& & EEK_ONE => { println!("Hello 4"); }
57+
_ => { println!("Gbye"); }
58+
}
59+
}

0 commit comments

Comments
 (0)