mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Enable unused_parens for match arms
This commit is contained in:
parent
c9e134e1b6
commit
8dd44f1af4
@ -377,7 +377,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
|
||||
|
||||
fn print_string(&mut self, st: &str, style: ast::StrStyle) {
|
||||
let st = match style {
|
||||
ast::StrStyle::Cooked => (format!("\"{}\"", st.escape_debug())),
|
||||
ast::StrStyle::Cooked => format!("\"{}\"", st.escape_debug()),
|
||||
ast::StrStyle::Raw(n) => {
|
||||
format!("r{delim}\"{string}\"{delim}", delim = "#".repeat(n as usize), string = st)
|
||||
}
|
||||
|
@ -839,7 +839,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
|
||||
hir::Node::Expr(hir::Expr {
|
||||
kind: hir::ExprKind::Closure(&hir::Closure { fn_decl_span, .. }),
|
||||
..
|
||||
}) => (tcx.sess.source_map().end_point(fn_decl_span)),
|
||||
}) => tcx.sess.source_map().end_point(fn_decl_span),
|
||||
_ => self.body.span,
|
||||
};
|
||||
|
||||
|
@ -396,6 +396,7 @@ enum UnusedDelimsCtx {
|
||||
LetScrutineeExpr,
|
||||
ArrayLenExpr,
|
||||
AnonConst,
|
||||
MatchArmExpr,
|
||||
}
|
||||
|
||||
impl From<UnusedDelimsCtx> for &'static str {
|
||||
@ -414,6 +415,7 @@ impl From<UnusedDelimsCtx> for &'static str {
|
||||
UnusedDelimsCtx::BlockRetValue => "block return value",
|
||||
UnusedDelimsCtx::LetScrutineeExpr => "`let` scrutinee expression",
|
||||
UnusedDelimsCtx::ArrayLenExpr | UnusedDelimsCtx::AnonConst => "const expression",
|
||||
UnusedDelimsCtx::MatchArmExpr => "match arm expression",
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -805,6 +807,18 @@ impl EarlyLintPass for UnusedParens {
|
||||
}
|
||||
return;
|
||||
}
|
||||
ExprKind::Match(ref _expr, ref arm) => {
|
||||
for a in arm {
|
||||
self.check_unused_delims_expr(
|
||||
cx,
|
||||
&a.body,
|
||||
UnusedDelimsCtx::MatchArmExpr,
|
||||
false,
|
||||
None,
|
||||
None,
|
||||
);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
|
@ -617,7 +617,7 @@ impl SplitVarLenSlice {
|
||||
// The only admissible fixed-length slice is one of the array size. Whether `max_slice`
|
||||
// is fixed-length or variable-length, it will be the only relevant slice to output
|
||||
// here.
|
||||
Some(_) => (0..0), // empty range
|
||||
Some(_) => 0..0, // empty range
|
||||
// We cover all arities in the range `(self.arity..infinity)`. We split that range into
|
||||
// two: lengths smaller than `max_slice.arity()` are treated independently as
|
||||
// fixed-lengths slices, and lengths above are captured by `max_slice`.
|
||||
|
9
src/test/ui/lint/unused/issue-92751.rs
Normal file
9
src/test/ui/lint/unused/issue-92751.rs
Normal file
@ -0,0 +1,9 @@
|
||||
#[deny(unused)]
|
||||
pub fn broken(x: Option<()>) -> i32 {
|
||||
match x {
|
||||
Some(()) => (1), //~ ERROR unnecessary parentheses around match arm expression
|
||||
None => (2), //~ ERROR unnecessary parentheses around match arm expression
|
||||
}
|
||||
}
|
||||
|
||||
fn main() { }
|
32
src/test/ui/lint/unused/issue-92751.stderr
Normal file
32
src/test/ui/lint/unused/issue-92751.stderr
Normal file
@ -0,0 +1,32 @@
|
||||
error: unnecessary parentheses around match arm expression
|
||||
--> $DIR/issue-92751.rs:4:21
|
||||
|
|
||||
LL | Some(()) => (1),
|
||||
| ^ ^
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/issue-92751.rs:1:8
|
||||
|
|
||||
LL | #[deny(unused)]
|
||||
| ^^^^^^
|
||||
= note: `#[deny(unused_parens)]` implied by `#[deny(unused)]`
|
||||
help: remove these parentheses
|
||||
|
|
||||
LL - Some(()) => (1),
|
||||
LL + Some(()) => 1,
|
||||
|
|
||||
|
||||
error: unnecessary parentheses around match arm expression
|
||||
--> $DIR/issue-92751.rs:5:17
|
||||
|
|
||||
LL | None => (2),
|
||||
| ^ ^
|
||||
|
|
||||
help: remove these parentheses
|
||||
|
|
||||
LL - None => (2),
|
||||
LL + None => 2,
|
||||
|
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
Loading…
Reference in New Issue
Block a user