Skip to content

Commit b4c948b

Browse files
committed
WIP experimental commit while reviewing rust-lang#54820
1 parent 24eddc4 commit b4c948b

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/librustc_lint/unused.rs

+17-16
Original file line numberDiff line numberDiff line change
@@ -280,15 +280,12 @@ impl UnusedParens {
280280
}
281281

282282
fn check_unused_parens_pat(&self,
283-
cx: &EarlyContext,
284-
value: &ast::Pat,
285-
msg: &str,
286-
struct_lit_needs_parens: bool) {
283+
cx: &EarlyContext,
284+
value: &ast::Pat,
285+
msg: &str) {
287286
if let ast::PatKind::Paren(_) = value.node {
288-
if !struct_lit_needs_parens {
289-
let pattern = pprust::pat_to_string(value);
290-
Self::remove_outer_parens(cx, value.span, &pattern, msg)
291-
}
287+
let pattern = pprust::pat_to_string(value);
288+
Self::remove_outer_parens(cx, value.span, &pattern, msg)
292289
}
293290
}
294291

@@ -378,14 +375,18 @@ impl EarlyLintPass for UnusedParens {
378375

379376
fn check_pat(&mut self, cx: &EarlyContext, p: &ast::Pat) {
380377
use ast::PatKind::*;
381-
let (value, msg, struct_lit_needs_parens) = match p.node {
382-
Ident(.., Some(ref pat)) => (pat, "optional subpattern", false),
383-
Ref(ref pat, _) => (pat, "reference pattern", false),
384-
Slice(_, Some(ref pat), _) => (pat, "optional position pattern", false),
385-
Paren(_) => (p, "pattern", false),
386-
_ => return,
387-
};
388-
self.check_unused_parens_pat(cx, &value, msg, struct_lit_needs_parens);
378+
if let Paren(_) = p.node {
379+
self.check_unused_parens_pat(cx, p, "pattern");
380+
} else {
381+
// separate match to smooth over P<Pat> vs. Pat typeck infelicities
382+
let (value, msg) = match p.node {
383+
Ident(.., Some(ref pat)) => (pat, "optional subpattern"),
384+
Ref(ref pat, _) => (pat, "reference pattern"),
385+
Slice(_, Some(ref pat), _) => (pat, "optional position pattern"),
386+
_ => { return; }
387+
};
388+
self.check_unused_parens_pat(cx, &value, msg);
389+
}
389390
}
390391

391392
fn check_stmt(&mut self, cx: &EarlyContext, s: &ast::Stmt) {

0 commit comments

Comments
 (0)