Skip to content

Commit 9ff34ac

Browse files
committed
actually don't lint for inclusive range
1 parent 2c7cf2c commit 9ff34ac

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

clippy_lints/src/eta_reduction.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,17 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction {
120120
if !is_type_diagnostic_item(cx, callee_ty_unadjusted, sym::Arc);
121121
if !is_type_diagnostic_item(cx, callee_ty_unadjusted, sym::Rc);
122122
if let ty::Closure(_, substs) = *closure_ty.kind();
123+
// Don't lint if this is an inclusive range expression.
124+
// They desugar to a call to `RangeInclusiveNew` which would have odd suggestions. (#10684)
125+
if !matches!(higher::Range::hir(body.value), Some(higher::Range {
126+
start: Some(_),
127+
end: Some(_),
128+
limits: rustc_ast::RangeLimits::Closed
129+
}));
123130
then {
124131
span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure", |diag| {
125132
if let Some(mut snippet) = snippet_opt(cx, callee.span) {
126-
if let Some(higher::Range {
127-
start: Some(_),
128-
end: Some(_),
129-
limits: rustc_ast::RangeLimits::Closed
130-
}) = higher::Range::hir(body.value) {
131-
// `|x,y| x..=y` becomes `|x, y| RangeInclusive::new(x, y)`
132-
snippet = "core::ops::RangeInclusive::new".to_owned();
133-
} else if let Some(fn_mut_id) = cx.tcx.lang_items().fn_mut_trait()
133+
if let Some(fn_mut_id) = cx.tcx.lang_items().fn_mut_trait()
134134
&& let args = cx.tcx.erase_late_bound_regions(substs.as_closure().sig()).inputs()
135135
&& implements_trait(
136136
cx,

tests/ui/eta.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn main() {
5151
fn test<T>(x: impl Fn(usize, usize) -> T) -> T {
5252
x(1, 2)
5353
}
54-
test(core::ops::RangeInclusive::new);
54+
test(|start, end| start..=end);
5555
}
5656

5757
trait TestTrait {

tests/ui/eta.stderr

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ error: redundant closure
3030
LL | let e = Some(1u8).map(|a| generic(a));
3131
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `generic`
3232

33-
error: redundant closure
34-
--> $DIR/eta.rs:54:10
35-
|
36-
LL | test(|start, end| start..=end);
37-
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `core::ops::RangeInclusive::new`
38-
3933
error: redundant closure
4034
--> $DIR/eta.rs:93:51
4135
|
@@ -164,5 +158,5 @@ error: redundant closure
164158
LL | dyn_opt.map(|d| d.method_on_dyn());
165159
| ^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<dyn TestTrait>::method_on_dyn`
166160

167-
error: aborting due to 27 previous errors
161+
error: aborting due to 26 previous errors
168162

0 commit comments

Comments
 (0)