From 572c83f199476276a3fcdeee05038ad35d5d6ddb Mon Sep 17 00:00:00 2001 From: ouz-a Date: Thu, 11 Aug 2022 15:40:23 +0300 Subject: [PATCH 1/2] fake capture if min_captures empty --- compiler/rustc_hir_typeck/src/upvar.rs | 7 ++++++- src/test/ui/closures/issue-93242.rs | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/closures/issue-93242.rs diff --git a/compiler/rustc_hir_typeck/src/upvar.rs b/compiler/rustc_hir_typeck/src/upvar.rs index 4dea40829f622..3aa8c56138de6 100644 --- a/compiler/rustc_hir_typeck/src/upvar.rs +++ b/compiler/rustc_hir_typeck/src/upvar.rs @@ -231,7 +231,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // We now fake capture information for all variables that are mentioned within the closure // We do this after handling migrations so that min_captures computes before - if !enable_precise_capture(self.tcx, span) { + if !enable_precise_capture(self.tcx, span) + // (ouz-a) #93242 - ICE happens because closure_min_captures is empty with + // 2021 edition, because it sets `enable_precise_capture` to true, which won't allow us + // fake capture information this check sidesteps that and avoids the ICE. + || (infer_kind == None && self.typeck_results.borrow().closure_min_captures.is_empty()) + { let mut capture_information: InferredCaptureInformation<'tcx> = Default::default(); if let Some(upvars) = self.tcx.upvars_mentioned(closure_def_id) { diff --git a/src/test/ui/closures/issue-93242.rs b/src/test/ui/closures/issue-93242.rs new file mode 100644 index 0000000000000..56f8b0a477935 --- /dev/null +++ b/src/test/ui/closures/issue-93242.rs @@ -0,0 +1,11 @@ +// check-pass +// edition:2021 + +pub fn something(path: &[usize]) -> impl Fn() -> usize + '_ { + move || match path { + [] => 0, + _ => 1, + } +} + +fn main(){} From 95eaa3d2f4cc641ad61f85cfef5a5b36705777e8 Mon Sep 17 00:00:00 2001 From: ouz-a Date: Tue, 1 Nov 2022 01:19:11 +0300 Subject: [PATCH 2/2] bless test --- src/tools/clippy/tests/ui/redundant_clone.fixed | 2 +- src/tools/clippy/tests/ui/redundant_clone.stderr | 14 +------------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/tools/clippy/tests/ui/redundant_clone.fixed b/src/tools/clippy/tests/ui/redundant_clone.fixed index 00b427450935d..f26ee7051e6cb 100644 --- a/src/tools/clippy/tests/ui/redundant_clone.fixed +++ b/src/tools/clippy/tests/ui/redundant_clone.fixed @@ -201,7 +201,7 @@ fn clone_then_move_cloned() { fn foo(_: &Alpha, _: F) {} let x = Alpha; // ok, data is moved while the clone is in use. - foo(&x, move || { + foo(&x.clone(), move || { let _ = x; }); diff --git a/src/tools/clippy/tests/ui/redundant_clone.stderr b/src/tools/clippy/tests/ui/redundant_clone.stderr index 782590034d051..c93720003e5ca 100644 --- a/src/tools/clippy/tests/ui/redundant_clone.stderr +++ b/src/tools/clippy/tests/ui/redundant_clone.stderr @@ -167,17 +167,5 @@ note: cloned value is neither consumed nor mutated LL | let y = x.clone().join("matthias"); | ^^^^^^^^^ -error: redundant clone - --> $DIR/redundant_clone.rs:204:11 - | -LL | foo(&x.clone(), move || { - | ^^^^^^^^ help: remove this - | -note: this value is dropped without further use - --> $DIR/redundant_clone.rs:204:10 - | -LL | foo(&x.clone(), move || { - | ^ - -error: aborting due to 15 previous errors +error: aborting due to 14 previous errors