Skip to content

Commit f5fe425

Browse files
committed
Auto merge of #83364 - sexxi-goose:fix-83176, r=nikomatsakis
2229 migration: Don't try resolve regions before writeback In the analysis use `resolve_vars_if_possible` instead of `fully_resolve`, because we might not have performed regionck yet. Fixes: #83176 r? `@nikomatsakis`
2 parents 2e012ce + 74d7731 commit f5fe425

File tree

4 files changed

+29
-19
lines changed

4 files changed

+29
-19
lines changed

compiler/rustc_typeck/src/check/upvar.rs

+2-17
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
//! then mean that all later passes would have to check for these figments
3131
//! and report an error, and it just seems like more mess in the end.)
3232
33-
use super::writeback::Resolver;
3433
use super::FnCtxt;
3534

3635
use crate::expr_use_visitor as euv;
@@ -42,7 +41,6 @@ use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
4241
use rustc_infer::infer::UpvarRegion;
4342
use rustc_middle::hir::place::{Place, PlaceBase, PlaceWithHirId, Projection, ProjectionKind};
4443
use rustc_middle::mir::FakeReadCause;
45-
use rustc_middle::ty::fold::TypeFoldable;
4644
use rustc_middle::ty::{self, Ty, TyCtxt, TypeckResults, UpvarSubsts};
4745
use rustc_session::lint;
4846
use rustc_span::sym;
@@ -167,7 +165,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
167165

168166
let closure_hir_id = self.tcx.hir().local_def_id_to_hir_id(local_def_id);
169167
if should_do_migration_analysis(self.tcx, closure_hir_id) {
170-
self.perform_2229_migration_anaysis(closure_def_id, capture_clause, span, body);
168+
self.perform_2229_migration_anaysis(closure_def_id, capture_clause, span);
171169
}
172170

173171
// We now fake capture information for all variables that are mentioned within the closure
@@ -467,13 +465,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
467465
closure_def_id: DefId,
468466
capture_clause: hir::CaptureBy,
469467
span: Span,
470-
body: &'tcx hir::Body<'tcx>,
471468
) {
472469
let need_migrations = self.compute_2229_migrations(
473470
closure_def_id,
474471
span,
475472
capture_clause,
476-
body,
477473
self.typeck_results.borrow().closure_min_captures.get(&closure_def_id),
478474
);
479475

@@ -511,19 +507,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
511507
closure_def_id: DefId,
512508
closure_span: Span,
513509
closure_clause: hir::CaptureBy,
514-
body: &'tcx hir::Body<'tcx>,
515510
min_captures: Option<&ty::RootVariableMinCaptureList<'tcx>>,
516511
) -> Vec<hir::HirId> {
517-
fn resolve_ty<T: TypeFoldable<'tcx>>(
518-
fcx: &FnCtxt<'_, 'tcx>,
519-
span: Span,
520-
body: &'tcx hir::Body<'tcx>,
521-
ty: T,
522-
) -> T {
523-
let mut resolver = Resolver::new(fcx, &span, body);
524-
ty.fold_with(&mut resolver)
525-
}
526-
527512
let upvars = if let Some(upvars) = self.tcx.upvars_mentioned(closure_def_id) {
528513
upvars
529514
} else {
@@ -533,7 +518,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
533518
let mut need_migrations = Vec::new();
534519

535520
for (&var_hir_id, _) in upvars.iter() {
536-
let ty = resolve_ty(self, closure_span, body, self.node_ty(var_hir_id));
521+
let ty = self.infcx.resolve_vars_if_possible(self.node_ty(var_hir_id));
537522

538523
if !ty.needs_drop(self.tcx, self.tcx.param_env(closure_def_id.expect_local())) {
539524
continue;

compiler/rustc_typeck/src/check/writeback.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ impl Locatable for hir::HirId {
675675

676676
/// The Resolver. This is the type folding engine that detects
677677
/// unresolved types and so forth.
678-
crate struct Resolver<'cx, 'tcx> {
678+
struct Resolver<'cx, 'tcx> {
679679
tcx: TyCtxt<'tcx>,
680680
infcx: &'cx InferCtxt<'cx, 'tcx>,
681681
span: &'cx dyn Locatable,
@@ -686,7 +686,7 @@ crate struct Resolver<'cx, 'tcx> {
686686
}
687687

688688
impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
689-
crate fn new(
689+
fn new(
690690
fcx: &'cx FnCtxt<'cx, 'tcx>,
691691
span: &'cx dyn Locatable,
692692
body: &'tcx hir::Body<'tcx>,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// run-pass
2+
3+
#![warn(disjoint_capture_drop_reorder)]
4+
5+
fn main() {
6+
if let a = "" {
7+
//~^ WARNING: irrefutable `if let` pattern
8+
drop(|_: ()| drop(a));
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
warning: irrefutable `if let` pattern
2+
--> $DIR/issue-78720.rs:6:5
3+
|
4+
LL | / if let a = "" {
5+
LL | |
6+
LL | | drop(|_: ()| drop(a));
7+
LL | | }
8+
| |_____^
9+
|
10+
= note: `#[warn(irrefutable_let_patterns)]` on by default
11+
= note: this pattern will always match, so the `if let` is useless
12+
= help: consider replacing the `if let` with a `let`
13+
14+
warning: 1 warning emitted
15+

0 commit comments

Comments
 (0)