about summary refs log tree commit diff
diff options
context:
space:
mode:
authory21 <30553356+y21@users.noreply.github.com>2023-06-08 00:34:23 +0200
committery21 <30553356+y21@users.noreply.github.com>2023-06-08 00:34:23 +0200
commit9ff34acf211c1b2aa7b4a282b2dd38927e137169 (patch)
treef209a521580aaf61dcaa24e411bd2173b847859f
parent2c7cf2cfa113e28e82854574eb1227d7c001d84c (diff)
downloadrust-9ff34acf211c1b2aa7b4a282b2dd38927e137169.tar.gz
rust-9ff34acf211c1b2aa7b4a282b2dd38927e137169.zip
actually don't lint for inclusive range
-rw-r--r--clippy_lints/src/eta_reduction.rs16
-rw-r--r--tests/ui/eta.fixed2
-rw-r--r--tests/ui/eta.stderr8
3 files changed, 10 insertions, 16 deletions
diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs
index fcbf0898890..58e62d1f3d3 100644
--- a/clippy_lints/src/eta_reduction.rs
+++ b/clippy_lints/src/eta_reduction.rs
@@ -120,17 +120,17 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction {
             if !is_type_diagnostic_item(cx, callee_ty_unadjusted, sym::Arc);
             if !is_type_diagnostic_item(cx, callee_ty_unadjusted, sym::Rc);
             if let ty::Closure(_, substs) = *closure_ty.kind();
+            // Don't lint if this is an inclusive range expression.
+            // They desugar to a call to `RangeInclusiveNew` which would have odd suggestions. (#10684)
+            if !matches!(higher::Range::hir(body.value), Some(higher::Range {
+                start: Some(_),
+                end: Some(_),
+                limits: rustc_ast::RangeLimits::Closed
+            }));
             then {
                 span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure", |diag| {
                     if let Some(mut snippet) = snippet_opt(cx, callee.span) {
-                        if let Some(higher::Range {
-                            start: Some(_),
-                            end: Some(_),
-                            limits: rustc_ast::RangeLimits::Closed
-                        }) = higher::Range::hir(body.value) {
-                            // `|x,y| x..=y` becomes `|x, y| RangeInclusive::new(x, y)`
-                            snippet = "core::ops::RangeInclusive::new".to_owned();
-                        } else if let Some(fn_mut_id) = cx.tcx.lang_items().fn_mut_trait()
+                        if let Some(fn_mut_id) = cx.tcx.lang_items().fn_mut_trait()
                             && let args = cx.tcx.erase_late_bound_regions(substs.as_closure().sig()).inputs()
                             && implements_trait(
                                    cx,
diff --git a/tests/ui/eta.fixed b/tests/ui/eta.fixed
index 934deb66362..31a94cb10e8 100644
--- a/tests/ui/eta.fixed
+++ b/tests/ui/eta.fixed
@@ -51,7 +51,7 @@ fn main() {
     fn test<T>(x: impl Fn(usize, usize) -> T) -> T {
         x(1, 2)
     }
-    test(core::ops::RangeInclusive::new);
+    test(|start, end| start..=end);
 }
 
 trait TestTrait {
diff --git a/tests/ui/eta.stderr b/tests/ui/eta.stderr
index 1f5db2d5129..19be5fc7389 100644
--- a/tests/ui/eta.stderr
+++ b/tests/ui/eta.stderr
@@ -31,12 +31,6 @@ LL |     let e = Some(1u8).map(|a| generic(a));
    |                           ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `generic`
 
 error: redundant closure
-  --> $DIR/eta.rs:54:10
-   |
-LL |     test(|start, end| start..=end);
-   |          ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `core::ops::RangeInclusive::new`
-
-error: redundant closure
   --> $DIR/eta.rs:93:51
    |
 LL |     let e = Some(TestStruct { some_ref: &i }).map(|a| a.foo());
@@ -164,5 +158,5 @@ error: redundant closure
 LL |     dyn_opt.map(|d| d.method_on_dyn());
    |                 ^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `<dyn TestTrait>::method_on_dyn`
 
-error: aborting due to 27 previous errors
+error: aborting due to 26 previous errors