diff options
| author | Jonas Schievink <jonasschievink@gmail.com> | 2021-01-24 22:10:06 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-24 22:10:06 +0100 |
| commit | 04ddf42218dca9f73edb38919d1dd9caae9b691e (patch) | |
| tree | d16b7bccb1a8a36c18c4865bea87700d438ac155 | |
| parent | ee4461a996dba7a1c7064fdc04934e9b7f01f7f3 (diff) | |
| parent | 99a1dea1b7727885d2660bae665cff165fb86a50 (diff) | |
Rollup merge of #81310 - tmiasko:in-pattern, r=petrochenkov
Do not mark unit variants as used when in path pattern Record that we are processing a pattern so that code responsible for handling path resolution can correctly decide whether to mark it as used or not. Closes #76788.
| -rw-r--r-- | compiler/rustc_passes/src/dead.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/lint/dead-code/const-and-self.rs | 21 | ||||
| -rw-r--r-- | src/test/ui/lint/dead-code/const-and-self.stderr | 20 |
3 files changed, 41 insertions, 2 deletions
diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index 80a24c90421..3b1b53553d5 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -290,6 +290,7 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> { } fn visit_pat(&mut self, pat: &'tcx hir::Pat<'tcx>) { + self.in_pat = true; match pat.kind { PatKind::Struct(ref path, ref fields, _) => { let res = self.typeck_results().qpath_res(path, pat.hir_id); @@ -302,7 +303,6 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> { _ => (), } - self.in_pat = true; intravisit::walk_pat(self, pat); self.in_pat = false; } diff --git a/src/test/ui/lint/dead-code/const-and-self.rs b/src/test/ui/lint/dead-code/const-and-self.rs index 1a7b3f43cda..0bcdd6edf0d 100644 --- a/src/test/ui/lint/dead-code/const-and-self.rs +++ b/src/test/ui/lint/dead-code/const-and-self.rs @@ -1,6 +1,6 @@ // check-pass -#![deny(dead_code)] +#![warn(dead_code)] const TLC: usize = 4; @@ -28,8 +28,27 @@ impl Foo<Y> for X { } } +enum E { + A, + B, //~ WARN variant is never constructed: `B` + C, //~ WARN variant is never constructed: `C` +} + +type F = E; + +impl E { + fn check(&self) -> bool { + match self { + Self::A => true, + Self::B => false, + F::C => false, + } + } +} + fn main() { let s = [0,1,2,3]; s.doit(); X::foo(); + E::A.check(); } diff --git a/src/test/ui/lint/dead-code/const-and-self.stderr b/src/test/ui/lint/dead-code/const-and-self.stderr new file mode 100644 index 00000000000..c0e406189e8 --- /dev/null +++ b/src/test/ui/lint/dead-code/const-and-self.stderr @@ -0,0 +1,20 @@ +warning: variant is never constructed: `B` + --> $DIR/const-and-self.rs:33:5 + | +LL | B, + | ^ + | +note: the lint level is defined here + --> $DIR/const-and-self.rs:3:9 + | +LL | #![warn(dead_code)] + | ^^^^^^^^^ + +warning: variant is never constructed: `C` + --> $DIR/const-and-self.rs:34:5 + | +LL | C, + | ^ + +warning: 2 warnings emitted + |
