Skip to content

Commit 93db9e7

Browse files
committed
Remove uncessary parens in closure body with unused lint
1 parent e43d139 commit 93db9e7

File tree

15 files changed

+160
-27
lines changed

15 files changed

+160
-27
lines changed

compiler/rustc_errors/src/emitter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3526,7 +3526,7 @@ pub fn is_case_difference(sm: &SourceMap, suggested: &str, sp: Span) -> bool {
35263526
// All the chars that differ in capitalization are confusable (above):
35273527
let confusable = iter::zip(found.chars(), suggested.chars())
35283528
.filter(|(f, s)| f != s)
3529-
.all(|(f, s)| (ascii_confusables.contains(&f) || ascii_confusables.contains(&s)));
3529+
.all(|(f, s)| ascii_confusables.contains(&f) || ascii_confusables.contains(&s));
35303530
confusable && found.to_lowercase() == suggested.to_lowercase()
35313531
// FIXME: We sometimes suggest the same thing we already have, which is a
35323532
// bug, but be defensive against that here.

compiler/rustc_lint/src/unused.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::iter;
22

33
use rustc_ast::util::{classify, parser};
4-
use rustc_ast::{self as ast, ExprKind, HasAttrs as _, StmtKind};
4+
use rustc_ast::{self as ast, ExprKind, FnRetTy, HasAttrs as _, StmtKind};
55
use rustc_attr_data_structures::{AttributeKind, find_attr};
66
use rustc_data_structures::fx::FxHashMap;
77
use rustc_errors::{MultiSpan, pluralize};
@@ -599,6 +599,7 @@ enum UnusedDelimsCtx {
599599
AnonConst,
600600
MatchArmExpr,
601601
IndexExpr,
602+
ClosureBody,
602603
}
603604

604605
impl From<UnusedDelimsCtx> for &'static str {
@@ -620,6 +621,7 @@ impl From<UnusedDelimsCtx> for &'static str {
620621
UnusedDelimsCtx::ArrayLenExpr | UnusedDelimsCtx::AnonConst => "const expression",
621622
UnusedDelimsCtx::MatchArmExpr => "match arm expression",
622623
UnusedDelimsCtx::IndexExpr => "index expression",
624+
UnusedDelimsCtx::ClosureBody => "closure body",
623625
}
624626
}
625627
}
@@ -919,6 +921,11 @@ trait UnusedDelimLint {
919921
let (args_to_check, ctx) = match *call_or_other {
920922
Call(_, ref args) => (&args[..], UnusedDelimsCtx::FunctionArg),
921923
MethodCall(ref call) => (&call.args[..], UnusedDelimsCtx::MethodArg),
924+
Closure(ref closure)
925+
if matches!(closure.fn_decl.output, FnRetTy::Default(_)) =>
926+
{
927+
(&[closure.body.clone()][..], UnusedDelimsCtx::ClosureBody)
928+
}
922929
// actual catch-all arm
923930
_ => {
924931
return;
@@ -1508,6 +1515,7 @@ impl UnusedDelimLint for UnusedBraces {
15081515
&& (ctx != UnusedDelimsCtx::AnonConst
15091516
|| (matches!(expr.kind, ast::ExprKind::Lit(_))
15101517
&& !expr.span.from_expansion()))
1518+
&& ctx != UnusedDelimsCtx::ClosureBody
15111519
&& !cx.sess().source_map().is_multiline(value.span)
15121520
&& value.attrs.is_empty()
15131521
&& !value.span.from_expansion()

compiler/rustc_parse/src/parser/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2206,7 +2206,7 @@ impl<'a> Parser<'a> {
22062206

22072207
if self.look_ahead(1, |t| *t == token::Bang) && self.look_ahead(2, |t| t.is_ident()) {
22082208
return IsMacroRulesItem::Yes { has_bang: true };
2209-
} else if self.look_ahead(1, |t| (t.is_ident())) {
2209+
} else if self.look_ahead(1, |t| t.is_ident()) {
22102210
// macro_rules foo
22112211
self.dcx().emit_err(errors::MacroRulesMissingBang {
22122212
span: macro_rules_span,

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
328328
let module_did = mod_prefix.as_ref().and_then(Res::mod_def_id);
329329

330330
let mod_prefix =
331-
mod_prefix.map_or_else(String::new, |res| (format!("{} ", res.descr())));
332-
331+
mod_prefix.map_or_else(String::new, |res| format!("{} ", res.descr()));
333332
(mod_prefix, format!("`{}`", Segment::names_to_string(mod_path)), module_did, None)
334333
};
335334

library/core/src/unicode/unicode_data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ unsafe fn skip_search<const SOR: usize, const OFFSETS: usize>(
8282
let needle = needle as u32;
8383

8484
let last_idx =
85-
match short_offset_runs.binary_search_by_key(&(needle << 11), |header| (header.0 << 11)) {
85+
match short_offset_runs.binary_search_by_key(&(needle << 11), |header| header.0 << 11) {
8686
Ok(idx) => idx + 1,
8787
Err(idx) => idx,
8888
};

src/tools/clippy/clippy_lints/src/unused_async.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync {
169169
let iter = self
170170
.unused_async_fns
171171
.iter()
172-
.filter(|UnusedAsyncFn { def_id, .. }| (!self.async_fns_as_value.contains(def_id)));
172+
.filter(|UnusedAsyncFn { def_id, .. }| !self.async_fns_as_value.contains(def_id));
173173

174174
for fun in iter {
175175
span_lint_hir_and_then(

src/tools/clippy/clippy_utils/src/ty/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ impl AdtVariantInfo {
889889
.enumerate()
890890
.map(|(i, f)| (i, approx_ty_size(cx, f.ty(cx.tcx, subst))))
891891
.collect::<Vec<_>>();
892-
fields_size.sort_by(|(_, a_size), (_, b_size)| (a_size.cmp(b_size)));
892+
fields_size.sort_by(|(_, a_size), (_, b_size)| a_size.cmp(b_size));
893893

894894
Self {
895895
ind: i,
@@ -898,7 +898,7 @@ impl AdtVariantInfo {
898898
}
899899
})
900900
.collect::<Vec<_>>();
901-
variants_size.sort_by(|a, b| (b.size.cmp(&a.size)));
901+
variants_size.sort_by(|a, b| b.size.cmp(&a.size));
902902
variants_size
903903
}
904904
}

src/tools/compiletest/src/runtest.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,6 +1777,12 @@ impl<'test> TestCx<'test> {
17771777
// Allow tests to use internal features.
17781778
rustc.args(&["-A", "internal_features"]);
17791779

1780+
// Allow tests to have unused parens and braces.
1781+
// Add #![deny(unused_parens, unused_braces)] to the test file if you want to
1782+
// test that these lints are working.
1783+
rustc.args(&["-A", "unused_parens"]);
1784+
rustc.args(&["-A", "unused_braces"]);
1785+
17801786
if self.props.force_host {
17811787
self.maybe_add_external_args(&mut rustc, &self.config.host_rustcflags);
17821788
if !is_rustdoc {

src/tools/test-float-parse/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ fn launch_tests(tests: &mut [TestInfo], cfg: &Config) -> Duration {
340340
for test in tests.iter_mut() {
341341
test.progress = Some(ui::Progress::new(test, &mut all_progress_bars));
342342
ui::set_panic_hook(&all_progress_bars);
343-
((test.launch)(test, cfg));
343+
(test.launch)(test, cfg);
344344
}
345345

346346
start.elapsed()

src/tools/unicode-table-generator/src/range_search.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ unsafe fn skip_search<const SOR: usize, const OFFSETS: usize>(
8080
let needle = needle as u32;
8181

8282
let last_idx =
83-
match short_offset_runs.binary_search_by_key(&(needle << 11), |header| (header.0 << 11)) {
83+
match short_offset_runs.binary_search_by_key(&(needle << 11), |header| header.0 << 11) {
8484
Ok(idx) => idx + 1,
8585
Err(idx) => idx,
8686
};

0 commit comments

Comments
 (0)