Skip to content

Commit d09e658

Browse files
authored
Apply collapsible if to Clippy sources (rust-lang#14451)
This PR enables the new ability to collapse `if` statements containing comments (without losing them) in Clippy sources, excluding tests and lintcheck, where the default behaviour (no collapsing in presence of comments) is preserved. To be applied after rust-lang#14231. When it is applied, rust-lang#14455 will be marked as ready for review, then rust-lang#14228 afterwards. changelog: none r? ghost
2 parents 1893e1e + 6509de3 commit d09e658

File tree

9 files changed

+51
-55
lines changed

9 files changed

+51
-55
lines changed

clippy.toml

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ avoid-breaking-exported-api = false
22

33
check-inconsistent-struct-field-initializers = true
44

5+
lint-commented-code = true
6+
57
[[disallowed-methods]]
68
path = "rustc_lint::context::LintContext::lint"
79
reason = "this function does not add a link to our documentation, please use the `clippy_utils::diagnostics::span_lint*` functions instead"

clippy_lints/src/escape.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,11 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
9393
// find `self` ty for this trait if relevant
9494
if let ItemKind::Trait(_, _, _, _, _, items) = item.kind {
9595
for trait_item in items {
96-
if trait_item.id.owner_id.def_id == fn_def_id {
96+
if trait_item.id.owner_id.def_id == fn_def_id
9797
// be sure we have `self` parameter in this function
98-
if trait_item.kind == (AssocItemKind::Fn { has_self: true }) {
99-
trait_self_ty =
100-
Some(TraitRef::identity(cx.tcx, trait_item.id.owner_id.to_def_id()).self_ty());
101-
}
98+
&& trait_item.kind == (AssocItemKind::Fn { has_self: true })
99+
{
100+
trait_self_ty = Some(TraitRef::identity(cx.tcx, trait_item.id.owner_id.to_def_id()).self_ty());
102101
}
103102
}
104103
}

clippy_lints/src/item_name_repetitions.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -377,22 +377,21 @@ impl ItemNameRepetitions {
377377
"field name starts with the struct's name",
378378
);
379379
}
380-
if field_words.len() > item_name_words.len() {
380+
if field_words.len() > item_name_words.len()
381381
// lint only if the end is not covered by the start
382-
if field_words
382+
&& field_words
383383
.iter()
384384
.rev()
385385
.zip(item_name_words.iter().rev())
386386
.all(|(a, b)| a == b)
387-
{
388-
span_lint_hir(
389-
cx,
390-
STRUCT_FIELD_NAMES,
391-
field.hir_id,
392-
field.span,
393-
"field name ends with the struct's name",
394-
);
395-
}
387+
{
388+
span_lint_hir(
389+
cx,
390+
STRUCT_FIELD_NAMES,
391+
field.hir_id,
392+
field.span,
393+
"field name ends with the struct's name",
394+
);
396395
}
397396
}
398397
}

clippy_lints/src/mem_replace.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,12 @@ impl<'tcx> LateLintPass<'tcx> for MemReplace {
304304
&& let ExprKind::Path(ref func_qpath) = func.kind
305305
&& let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id()
306306
&& cx.tcx.is_diagnostic_item(sym::mem_replace, def_id)
307-
{
308307
// Check that second argument is `Option::None`
309-
if !check_replace_option_with_none(cx, src, dest, expr.span)
310-
&& !check_replace_option_with_some(cx, src, dest, expr.span, self.msrv)
311-
&& !check_replace_with_default(cx, src, dest, expr, self.msrv)
312-
{
313-
check_replace_with_uninit(cx, src, dest, expr.span);
314-
}
308+
&& !check_replace_option_with_none(cx, src, dest, expr.span)
309+
&& !check_replace_option_with_some(cx, src, dest, expr.span, self.msrv)
310+
&& !check_replace_with_default(cx, src, dest, expr, self.msrv)
311+
{
312+
check_replace_with_uninit(cx, src, dest, expr.span);
315313
}
316314
}
317315
}

clippy_lints/src/methods/map_clone.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,17 @@ fn handle_path(
114114
) {
115115
if let Some(path_def_id) = cx.qpath_res(qpath, arg.hir_id).opt_def_id()
116116
&& cx.tcx.lang_items().get(LangItem::CloneFn) == Some(path_def_id)
117-
{
118117
// The `copied` and `cloned` methods are only available on `&T` and `&mut T` in `Option`
119118
// and `Result`.
120-
if let ty::Adt(_, args) = cx.typeck_results().expr_ty(recv).kind()
121-
&& let args = args.as_slice()
122-
&& let Some(ty) = args.iter().find_map(|generic_arg| generic_arg.as_type())
123-
&& let ty::Ref(_, ty, Mutability::Not) = ty.kind()
124-
&& let ty::FnDef(_, lst) = cx.typeck_results().expr_ty(arg).kind()
125-
&& lst.iter().all(|l| l.as_type() == Some(*ty))
126-
&& !should_call_clone_as_function(cx, *ty)
127-
{
128-
lint_path(cx, e.span, recv.span, is_copy(cx, ty.peel_refs()));
129-
}
119+
&& let ty::Adt(_, args) = cx.typeck_results().expr_ty(recv).kind()
120+
&& let args = args.as_slice()
121+
&& let Some(ty) = args.iter().find_map(|generic_arg| generic_arg.as_type())
122+
&& let ty::Ref(_, ty, Mutability::Not) = ty.kind()
123+
&& let ty::FnDef(_, lst) = cx.typeck_results().expr_ty(arg).kind()
124+
&& lst.iter().all(|l| l.as_type() == Some(*ty))
125+
&& !should_call_clone_as_function(cx, *ty)
126+
{
127+
lint_path(cx, e.span, recv.span, is_copy(cx, ty.peel_refs()));
130128
}
131129
}
132130

clippy_lints/src/methods/seek_from_current.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,11 @@ fn arg_is_seek_from_current<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>)
3838
&& let ExprKind::Path(ref path) = f.kind
3939
&& let Some(ctor_call_id) = cx.qpath_res(path, f.hir_id).opt_def_id()
4040
&& is_enum_variant_ctor(cx, sym::SeekFrom, sym!(Current), ctor_call_id)
41-
{
4241
// check if argument of `SeekFrom::Current` is `0`
43-
if let ExprKind::Lit(lit) = arg.kind
44-
&& let LitKind::Int(Pu128(0), LitIntType::Unsuffixed) = lit.node
45-
{
46-
return true;
47-
}
42+
&& let ExprKind::Lit(lit) = arg.kind
43+
&& let LitKind::Int(Pu128(0), LitIntType::Unsuffixed) = lit.node
44+
{
45+
return true;
4846
}
4947

5048
false

clippy_lints/src/mixed_read_write_in_expression.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -327,22 +327,22 @@ impl<'tcx> Visitor<'tcx> for ReadVisitor<'_, 'tcx> {
327327
return;
328328
}
329329

330-
if path_to_local_id(expr, self.var) {
330+
if path_to_local_id(expr, self.var)
331331
// Check that this is a read, not a write.
332-
if !is_in_assignment_position(self.cx, expr) {
333-
span_lint_and_then(
334-
self.cx,
335-
MIXED_READ_WRITE_IN_EXPRESSION,
336-
expr.span,
337-
format!("unsequenced read of `{}`", self.cx.tcx.hir_name(self.var)),
338-
|diag| {
339-
diag.span_note(
340-
self.write_expr.span,
341-
"whether read occurs before this write depends on evaluation order",
342-
);
343-
},
344-
);
345-
}
332+
&& !is_in_assignment_position(self.cx, expr)
333+
{
334+
span_lint_and_then(
335+
self.cx,
336+
MIXED_READ_WRITE_IN_EXPRESSION,
337+
expr.span,
338+
format!("unsequenced read of `{}`", self.cx.tcx.hir_name(self.var)),
339+
|diag| {
340+
diag.span_note(
341+
self.write_expr.span,
342+
"whether read occurs before this write depends on evaluation order",
343+
);
344+
},
345+
);
346346
}
347347
match expr.kind {
348348
// We're about to descend a closure. Since we don't know when (or

lintcheck/ci-config/clippy.toml

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
# to `$PWD/lintcheck/ci-config`.
55

66
avoid-breaking-exported-api = false
7+
lint-commented-code = false

tests/clippy.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
# default config for tests, overrides clippy.toml at the project root
2+
lint-commented-code = false

0 commit comments

Comments
 (0)