Skip to content

Commit 355e23e

Browse files
Rollup merge of rust-lang#100452 - ouz-a:issue-93242, r=jackh726
Fake capture closures if typeck results are empty This ICE happens because `closure_min_captures` is empty, the reason it's empty is with the 2021 edition `enable_precise_capture` is set to true, which makes it so that we can't fake capture any information because that result of the `unwrap` is none hence the ICE. Other solution is editing [maybe_read_scrutinee](https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_typeck/expr_use_visitor.rs.html#453-463) to this since empty slice contains no sub patterns. Fixes rust-lang#93242 ```rust PatKind::Slice(_, ref slice, _) => { if slice.is_none(){ need_to_be_read = true; } } // instead of PatKind::Or(_) | PatKind::Box(_) | PatKind::Slice(..) | PatKind::Ref(..) | PatKind::Wild => {} ```
2 parents 8b001e6 + 8b984e5 commit 355e23e

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

compiler/rustc_hir_typeck/src/upvar.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
231231

232232
// We now fake capture information for all variables that are mentioned within the closure
233233
// We do this after handling migrations so that min_captures computes before
234-
if !enable_precise_capture(self.tcx, span) {
234+
if !enable_precise_capture(self.tcx, span)
235+
// (ouz-a) #93242 - ICE happens because closure_min_captures is empty with
236+
// 2021 edition, because it sets `enable_precise_capture` to true, which won't allow us
237+
// fake capture information this check sidesteps that and avoids the ICE.
238+
|| (infer_kind == None && self.typeck_results.borrow().closure_min_captures.is_empty())
239+
{
235240
let mut capture_information: InferredCaptureInformation<'tcx> = Default::default();
236241

237242
if let Some(upvars) = self.tcx.upvars_mentioned(closure_def_id) {

src/test/ui/closures/issue-93242.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// check-pass
2+
// edition:2021
3+
4+
pub fn something(path: &[usize]) -> impl Fn() -> usize + '_ {
5+
move || match path {
6+
[] => 0,
7+
_ => 1,
8+
}
9+
}
10+
11+
fn main(){}

0 commit comments

Comments
 (0)