Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fake capture closures if typeck results are empty #100452

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion compiler/rustc_hir_typeck/src/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/closures/issue-93242.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// check-pass
// edition:2021

pub fn something(path: &[usize]) -> impl Fn() -> usize + '_ {
move || match path {
[] => 0,
_ => 1,
}
}

fn main(){}
2 changes: 1 addition & 1 deletion src/tools/clippy/tests/ui/redundant_clone.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ fn clone_then_move_cloned() {
fn foo<F: Fn()>(_: &Alpha, _: F) {}
let x = Alpha;
// ok, data is moved while the clone is in use.
foo(&x, move || {
foo(&x.clone(), move || {
let _ = x;
});

Expand Down
14 changes: 1 addition & 13 deletions src/tools/clippy/tests/ui/redundant_clone.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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