Skip to content

Commit 4f4b716

Browse files
authored
Rollup merge of #72544 - sexxi-goose:upvars_mentioned, r=matthewjasper
librustc_middle: Rename upvars query to upvars_mentioned As part of supporting RFC 2229, we will be capturing all the Places that were mentioned in the closure. This commit modifies the name of the upvars query to upvars_mentioned. r? @nikomatsakis @blitzerr @matthewjasper
2 parents 14941cf + c3edb15 commit 4f4b716

File tree

13 files changed

+41
-34
lines changed

13 files changed

+41
-34
lines changed

src/librustc_middle/arena.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ macro_rules! arena_types {
6161
[few] privacy_access_levels: rustc_middle::middle::privacy::AccessLevels,
6262
[few] foreign_module: rustc_middle::middle::cstore::ForeignModule,
6363
[few] foreign_modules: Vec<rustc_middle::middle::cstore::ForeignModule>,
64-
[] upvars: rustc_data_structures::fx::FxIndexMap<rustc_hir::HirId, rustc_hir::Upvar>,
64+
[] upvars_mentioned: rustc_data_structures::fx::FxIndexMap<rustc_hir::HirId, rustc_hir::Upvar>,
6565
[] object_safety_violations: rustc_middle::traits::ObjectSafetyViolation,
6666
[] codegen_unit: rustc_middle::mir::mono::CodegenUnit<$tcx>,
6767
[] attribute: rustc_ast::ast::Attribute,

src/librustc_middle/mir/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2439,7 +2439,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
24392439
};
24402440
let mut struct_fmt = fmt.debug_struct(&name);
24412441

2442-
if let Some(upvars) = tcx.upvars(def_id) {
2442+
if let Some(upvars) = tcx.upvars_mentioned(def_id) {
24432443
for (&var_id, place) in upvars.keys().zip(places) {
24442444
let var_name = tcx.hir().name(var_id);
24452445
struct_fmt.field(&var_name.as_str(), place);
@@ -2458,7 +2458,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
24582458
let name = format!("[generator@{:?}]", tcx.hir().span(hir_id));
24592459
let mut struct_fmt = fmt.debug_struct(&name);
24602460

2461-
if let Some(upvars) = tcx.upvars(def_id) {
2461+
if let Some(upvars) = tcx.upvars_mentioned(def_id) {
24622462
for (&var_id, place) in upvars.keys().zip(places) {
24632463
let var_name = tcx.hir().name(var_id);
24642464
struct_fmt.field(&var_name.as_str(), place);

src/librustc_middle/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ rustc_queries! {
10401040
desc { "generating a postorder list of CrateNums" }
10411041
}
10421042

1043-
query upvars(_: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
1043+
query upvars_mentioned(_: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
10441044
eval_always
10451045
}
10461046
query maybe_unused_trait_import(def_id: LocalDefId) -> bool {

src/librustc_middle/ty/print/pretty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ pub trait PrettyPrinter<'tcx>:
610610
let mut sep = " ";
611611
for (&var_id, upvar_ty) in self
612612
.tcx()
613-
.upvars(did)
613+
.upvars_mentioned(did)
614614
.as_ref()
615615
.iter()
616616
.flat_map(|v| v.keys())
@@ -659,7 +659,7 @@ pub trait PrettyPrinter<'tcx>:
659659
let mut sep = " ";
660660
for (&var_id, upvar_ty) in self
661661
.tcx()
662-
.upvars(did)
662+
.upvars_mentioned(did)
663663
.as_ref()
664664
.iter()
665665
.flat_map(|v| v.keys())

src/librustc_mir/borrow_check/diagnostics/mod.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,16 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
377377
self.describe_field_from_ty(&ty, field, variant_index)
378378
}
379379
ty::Closure(def_id, _) | ty::Generator(def_id, _, _) => {
380-
// `tcx.upvars(def_id)` returns an `Option`, which is `None` in case
380+
// `tcx.upvars_mentioned(def_id)` returns an `Option`, which is `None` in case
381381
// the closure comes from another crate. But in that case we wouldn't
382382
// be borrowck'ing it, so we can just unwrap:
383-
let (&var_id, _) =
384-
self.infcx.tcx.upvars(def_id).unwrap().get_index(field.index()).unwrap();
383+
let (&var_id, _) = self
384+
.infcx
385+
.tcx
386+
.upvars_mentioned(def_id)
387+
.unwrap()
388+
.get_index(field.index())
389+
.unwrap();
385390

386391
self.infcx.tcx.hir().name(var_id).to_string()
387392
}
@@ -809,7 +814,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
809814
let expr = &self.infcx.tcx.hir().expect_expr(hir_id).kind;
810815
debug!("closure_span: hir_id={:?} expr={:?}", hir_id, expr);
811816
if let hir::ExprKind::Closure(.., body_id, args_span, _) = expr {
812-
for (upvar, place) in self.infcx.tcx.upvars(def_id)?.values().zip(places) {
817+
for (upvar, place) in self.infcx.tcx.upvars_mentioned(def_id)?.values().zip(places) {
813818
match place {
814819
Operand::Copy(place) | Operand::Move(place)
815820
if target_place == place.as_ref() =>

src/librustc_mir_build/hair/cx/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ fn make_mirror_unadjusted<'a, 'tcx>(
386386
};
387387
let upvars = cx
388388
.tcx
389-
.upvars(def_id)
389+
.upvars_mentioned(def_id)
390390
.iter()
391391
.flat_map(|upvars| upvars.iter())
392392
.zip(substs.upvar_tys())

src/librustc_passes/liveness.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ fn visit_expr<'tcx>(ir: &mut IrMaps<'tcx>, expr: &'tcx Expr<'tcx>) {
463463
hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) => {
464464
debug!("expr {}: path that leads to {:?}", expr.hir_id, path.res);
465465
if let Res::Local(var_hir_id) = path.res {
466-
let upvars = ir.tcx.upvars(ir.body_owner);
466+
let upvars = ir.tcx.upvars_mentioned(ir.body_owner);
467467
if !upvars.map_or(false, |upvars| upvars.contains_key(&var_hir_id)) {
468468
ir.add_live_node_for_node(expr.hir_id, ExprNode(expr.span));
469469
}
@@ -481,8 +481,8 @@ fn visit_expr<'tcx>(ir: &mut IrMaps<'tcx>, expr: &'tcx Expr<'tcx>) {
481481
// construction site.
482482
let mut call_caps = Vec::new();
483483
let closure_def_id = ir.tcx.hir().local_def_id(expr.hir_id);
484-
if let Some(upvars) = ir.tcx.upvars(closure_def_id) {
485-
let parent_upvars = ir.tcx.upvars(ir.body_owner);
484+
if let Some(upvars) = ir.tcx.upvars_mentioned(closure_def_id) {
485+
let parent_upvars = ir.tcx.upvars_mentioned(ir.body_owner);
486486
call_caps.extend(upvars.iter().filter_map(|(&var_id, upvar)| {
487487
let has_parent =
488488
parent_upvars.map_or(false, |upvars| upvars.contains_key(&var_id));
@@ -1364,7 +1364,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
13641364
) -> LiveNode {
13651365
match path.res {
13661366
Res::Local(hid) => {
1367-
let upvars = self.ir.tcx.upvars(self.ir.body_owner);
1367+
let upvars = self.ir.tcx.upvars_mentioned(self.ir.body_owner);
13681368
if !upvars.map_or(false, |upvars| upvars.contains_key(&hid)) {
13691369
self.access_var(hir_id, hid, succ, acc, path.span)
13701370
} else {
@@ -1529,7 +1529,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
15291529
match expr.kind {
15301530
hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) => {
15311531
if let Res::Local(var_hid) = path.res {
1532-
let upvars = self.ir.tcx.upvars(self.ir.body_owner);
1532+
let upvars = self.ir.tcx.upvars_mentioned(self.ir.body_owner);
15331533
if !upvars.map_or(false, |upvars| upvars.contains_key(&var_hid)) {
15341534
// Assignment to an immutable variable or argument: only legal
15351535
// if there is no later assignment. If this local is actually

src/librustc_passes/upvars.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_middle::ty::TyCtxt;
1010
use rustc_span::Span;
1111

1212
pub fn provide(providers: &mut Providers<'_>) {
13-
providers.upvars = |tcx, def_id| {
13+
providers.upvars_mentioned = |tcx, def_id| {
1414
if !tcx.is_closure(def_id) {
1515
return None;
1616
}
@@ -89,7 +89,7 @@ impl Visitor<'tcx> for CaptureCollector<'a, 'tcx> {
8989
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
9090
if let hir::ExprKind::Closure(..) = expr.kind {
9191
let closure_def_id = self.tcx.hir().local_def_id(expr.hir_id);
92-
if let Some(upvars) = self.tcx.upvars(closure_def_id) {
92+
if let Some(upvars) = self.tcx.upvars_mentioned(closure_def_id) {
9393
// Every capture of a closure expression is a local in scope,
9494
// that is moved/copied/borrowed into the closure value, and
9595
// for this analysis they are like any other access to a local.

src/librustc_trait_selection/traits/error_reporting/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
13801380
let mut interior_or_upvar_span = None;
13811381
let mut interior_extra_info = None;
13821382

1383-
if let Some(upvars) = self.tcx.upvars(generator_did) {
1383+
if let Some(upvars) = self.tcx.upvars_mentioned(generator_did) {
13841384
interior_or_upvar_span = upvars.iter().find_map(|(upvar_id, upvar)| {
13851385
let upvar_ty = tables.node_type(*upvar_id);
13861386
let upvar_ty = self.resolve_vars_if_possible(&upvar_ty);

src/librustc_typeck/check/closure.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
9090
base_substs.extend_to(self.tcx, expr_def_id.to_def_id(), |param, _| match param.kind {
9191
GenericParamDefKind::Lifetime => span_bug!(expr.span, "closure has lifetime param"),
9292
GenericParamDefKind::Type { .. } => if param.index as usize == tupled_upvars_idx {
93-
self.tcx.mk_tup(self.tcx.upvars(expr_def_id).iter().flat_map(|upvars| {
94-
upvars.iter().map(|(&var_hir_id, _)| {
95-
// Create type variables (for now) to represent the transformed
96-
// types of upvars. These will be unified during the upvar
97-
// inference phase (`upvar.rs`).
98-
self.infcx.next_ty_var(TypeVariableOrigin {
99-
// FIXME(eddyb) distinguish upvar inference variables from the rest.
100-
kind: TypeVariableOriginKind::ClosureSynthetic,
101-
span: self.tcx.hir().span(var_hir_id),
93+
self.tcx.mk_tup(self.tcx.upvars_mentioned(expr_def_id).iter().flat_map(
94+
|upvars| {
95+
upvars.iter().map(|(&var_hir_id, _)| {
96+
// Create type variables (for now) to represent the transformed
97+
// types of upvars. These will be unified during the upvar
98+
// inference phase (`upvar.rs`).
99+
self.infcx.next_ty_var(TypeVariableOrigin {
100+
// FIXME(eddyb) distinguish upvar inference variables from the rest.
101+
kind: TypeVariableOriginKind::ClosureSynthetic,
102+
span: self.tcx.hir().span(var_hir_id),
103+
})
102104
})
103-
})
104-
}))
105+
},
106+
))
105107
} else {
106108
// Create type variables (for now) to represent the various
107109
// pieces of information kept in `{Closure,Generic}Substs`.

src/librustc_typeck/check/upvar.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
111111
None
112112
};
113113

114-
if let Some(upvars) = self.tcx.upvars(closure_def_id) {
114+
if let Some(upvars) = self.tcx.upvars_mentioned(closure_def_id) {
115115
let mut upvar_list: FxIndexMap<hir::HirId, ty::UpvarId> =
116116
FxIndexMap::with_capacity_and_hasher(upvars.len(), Default::default());
117117
for (&var_hir_id, _) in upvars.iter() {
@@ -218,7 +218,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
218218
let tcx = self.tcx;
219219
let closure_def_id = tcx.hir().local_def_id(closure_id);
220220

221-
tcx.upvars(closure_def_id)
221+
tcx.upvars_mentioned(closure_def_id)
222222
.iter()
223223
.flat_map(|upvars| {
224224
upvars.iter().map(|(&var_hir_id, _)| {

src/librustc_typeck/expr_use_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
539539
debug!("walk_captures({:?})", closure_expr);
540540

541541
let closure_def_id = self.tcx().hir().local_def_id(closure_expr.hir_id);
542-
if let Some(upvars) = self.tcx().upvars(closure_def_id) {
542+
if let Some(upvars) = self.tcx().upvars_mentioned(closure_def_id) {
543543
for &var_id in upvars.keys() {
544544
let upvar_id = ty::UpvarId {
545545
var_path: ty::UpvarPath { hir_id: var_id },

src/librustc_typeck/mem_categorization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
159159
infcx,
160160
param_env,
161161
body_owner,
162-
upvars: infcx.tcx.upvars(body_owner),
162+
upvars: infcx.tcx.upvars_mentioned(body_owner),
163163
}
164164
}
165165

0 commit comments

Comments
 (0)