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
This commit is contained in:
commit
4f4b716675
src
librustc_middle
librustc_mir/borrow_check/diagnostics
librustc_mir_build/hair/cx
librustc_passes
librustc_trait_selection/traits/error_reporting
librustc_typeck
@ -61,7 +61,7 @@ macro_rules! arena_types {
|
|||||||
[few] privacy_access_levels: rustc_middle::middle::privacy::AccessLevels,
|
[few] privacy_access_levels: rustc_middle::middle::privacy::AccessLevels,
|
||||||
[few] foreign_module: rustc_middle::middle::cstore::ForeignModule,
|
[few] foreign_module: rustc_middle::middle::cstore::ForeignModule,
|
||||||
[few] foreign_modules: Vec<rustc_middle::middle::cstore::ForeignModule>,
|
[few] foreign_modules: Vec<rustc_middle::middle::cstore::ForeignModule>,
|
||||||
[] upvars: rustc_data_structures::fx::FxIndexMap<rustc_hir::HirId, rustc_hir::Upvar>,
|
[] upvars_mentioned: rustc_data_structures::fx::FxIndexMap<rustc_hir::HirId, rustc_hir::Upvar>,
|
||||||
[] object_safety_violations: rustc_middle::traits::ObjectSafetyViolation,
|
[] object_safety_violations: rustc_middle::traits::ObjectSafetyViolation,
|
||||||
[] codegen_unit: rustc_middle::mir::mono::CodegenUnit<$tcx>,
|
[] codegen_unit: rustc_middle::mir::mono::CodegenUnit<$tcx>,
|
||||||
[] attribute: rustc_ast::ast::Attribute,
|
[] attribute: rustc_ast::ast::Attribute,
|
||||||
|
@ -2439,7 +2439,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
|
|||||||
};
|
};
|
||||||
let mut struct_fmt = fmt.debug_struct(&name);
|
let mut struct_fmt = fmt.debug_struct(&name);
|
||||||
|
|
||||||
if let Some(upvars) = tcx.upvars(def_id) {
|
if let Some(upvars) = tcx.upvars_mentioned(def_id) {
|
||||||
for (&var_id, place) in upvars.keys().zip(places) {
|
for (&var_id, place) in upvars.keys().zip(places) {
|
||||||
let var_name = tcx.hir().name(var_id);
|
let var_name = tcx.hir().name(var_id);
|
||||||
struct_fmt.field(&var_name.as_str(), place);
|
struct_fmt.field(&var_name.as_str(), place);
|
||||||
@ -2458,7 +2458,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
|
|||||||
let name = format!("[generator@{:?}]", tcx.hir().span(hir_id));
|
let name = format!("[generator@{:?}]", tcx.hir().span(hir_id));
|
||||||
let mut struct_fmt = fmt.debug_struct(&name);
|
let mut struct_fmt = fmt.debug_struct(&name);
|
||||||
|
|
||||||
if let Some(upvars) = tcx.upvars(def_id) {
|
if let Some(upvars) = tcx.upvars_mentioned(def_id) {
|
||||||
for (&var_id, place) in upvars.keys().zip(places) {
|
for (&var_id, place) in upvars.keys().zip(places) {
|
||||||
let var_name = tcx.hir().name(var_id);
|
let var_name = tcx.hir().name(var_id);
|
||||||
struct_fmt.field(&var_name.as_str(), place);
|
struct_fmt.field(&var_name.as_str(), place);
|
||||||
|
@ -1040,7 +1040,7 @@ rustc_queries! {
|
|||||||
desc { "generating a postorder list of CrateNums" }
|
desc { "generating a postorder list of CrateNums" }
|
||||||
}
|
}
|
||||||
|
|
||||||
query upvars(_: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
|
query upvars_mentioned(_: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
|
||||||
eval_always
|
eval_always
|
||||||
}
|
}
|
||||||
query maybe_unused_trait_import(def_id: LocalDefId) -> bool {
|
query maybe_unused_trait_import(def_id: LocalDefId) -> bool {
|
||||||
|
@ -610,7 +610,7 @@ pub trait PrettyPrinter<'tcx>:
|
|||||||
let mut sep = " ";
|
let mut sep = " ";
|
||||||
for (&var_id, upvar_ty) in self
|
for (&var_id, upvar_ty) in self
|
||||||
.tcx()
|
.tcx()
|
||||||
.upvars(did)
|
.upvars_mentioned(did)
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|v| v.keys())
|
.flat_map(|v| v.keys())
|
||||||
@ -659,7 +659,7 @@ pub trait PrettyPrinter<'tcx>:
|
|||||||
let mut sep = " ";
|
let mut sep = " ";
|
||||||
for (&var_id, upvar_ty) in self
|
for (&var_id, upvar_ty) in self
|
||||||
.tcx()
|
.tcx()
|
||||||
.upvars(did)
|
.upvars_mentioned(did)
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|v| v.keys())
|
.flat_map(|v| v.keys())
|
||||||
|
@ -377,11 +377,16 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||||||
self.describe_field_from_ty(&ty, field, variant_index)
|
self.describe_field_from_ty(&ty, field, variant_index)
|
||||||
}
|
}
|
||||||
ty::Closure(def_id, _) | ty::Generator(def_id, _, _) => {
|
ty::Closure(def_id, _) | ty::Generator(def_id, _, _) => {
|
||||||
// `tcx.upvars(def_id)` returns an `Option`, which is `None` in case
|
// `tcx.upvars_mentioned(def_id)` returns an `Option`, which is `None` in case
|
||||||
// the closure comes from another crate. But in that case we wouldn't
|
// the closure comes from another crate. But in that case we wouldn't
|
||||||
// be borrowck'ing it, so we can just unwrap:
|
// be borrowck'ing it, so we can just unwrap:
|
||||||
let (&var_id, _) =
|
let (&var_id, _) = self
|
||||||
self.infcx.tcx.upvars(def_id).unwrap().get_index(field.index()).unwrap();
|
.infcx
|
||||||
|
.tcx
|
||||||
|
.upvars_mentioned(def_id)
|
||||||
|
.unwrap()
|
||||||
|
.get_index(field.index())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
self.infcx.tcx.hir().name(var_id).to_string()
|
self.infcx.tcx.hir().name(var_id).to_string()
|
||||||
}
|
}
|
||||||
@ -809,7 +814,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||||||
let expr = &self.infcx.tcx.hir().expect_expr(hir_id).kind;
|
let expr = &self.infcx.tcx.hir().expect_expr(hir_id).kind;
|
||||||
debug!("closure_span: hir_id={:?} expr={:?}", hir_id, expr);
|
debug!("closure_span: hir_id={:?} expr={:?}", hir_id, expr);
|
||||||
if let hir::ExprKind::Closure(.., body_id, args_span, _) = expr {
|
if let hir::ExprKind::Closure(.., body_id, args_span, _) = expr {
|
||||||
for (upvar, place) in self.infcx.tcx.upvars(def_id)?.values().zip(places) {
|
for (upvar, place) in self.infcx.tcx.upvars_mentioned(def_id)?.values().zip(places) {
|
||||||
match place {
|
match place {
|
||||||
Operand::Copy(place) | Operand::Move(place)
|
Operand::Copy(place) | Operand::Move(place)
|
||||||
if target_place == place.as_ref() =>
|
if target_place == place.as_ref() =>
|
||||||
|
@ -386,7 +386,7 @@ fn make_mirror_unadjusted<'a, 'tcx>(
|
|||||||
};
|
};
|
||||||
let upvars = cx
|
let upvars = cx
|
||||||
.tcx
|
.tcx
|
||||||
.upvars(def_id)
|
.upvars_mentioned(def_id)
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|upvars| upvars.iter())
|
.flat_map(|upvars| upvars.iter())
|
||||||
.zip(substs.upvar_tys())
|
.zip(substs.upvar_tys())
|
||||||
|
@ -463,7 +463,7 @@ fn visit_expr<'tcx>(ir: &mut IrMaps<'tcx>, expr: &'tcx Expr<'tcx>) {
|
|||||||
hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) => {
|
hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) => {
|
||||||
debug!("expr {}: path that leads to {:?}", expr.hir_id, path.res);
|
debug!("expr {}: path that leads to {:?}", expr.hir_id, path.res);
|
||||||
if let Res::Local(var_hir_id) = path.res {
|
if let Res::Local(var_hir_id) = path.res {
|
||||||
let upvars = ir.tcx.upvars(ir.body_owner);
|
let upvars = ir.tcx.upvars_mentioned(ir.body_owner);
|
||||||
if !upvars.map_or(false, |upvars| upvars.contains_key(&var_hir_id)) {
|
if !upvars.map_or(false, |upvars| upvars.contains_key(&var_hir_id)) {
|
||||||
ir.add_live_node_for_node(expr.hir_id, ExprNode(expr.span));
|
ir.add_live_node_for_node(expr.hir_id, ExprNode(expr.span));
|
||||||
}
|
}
|
||||||
@ -481,8 +481,8 @@ fn visit_expr<'tcx>(ir: &mut IrMaps<'tcx>, expr: &'tcx Expr<'tcx>) {
|
|||||||
// construction site.
|
// construction site.
|
||||||
let mut call_caps = Vec::new();
|
let mut call_caps = Vec::new();
|
||||||
let closure_def_id = ir.tcx.hir().local_def_id(expr.hir_id);
|
let closure_def_id = ir.tcx.hir().local_def_id(expr.hir_id);
|
||||||
if let Some(upvars) = ir.tcx.upvars(closure_def_id) {
|
if let Some(upvars) = ir.tcx.upvars_mentioned(closure_def_id) {
|
||||||
let parent_upvars = ir.tcx.upvars(ir.body_owner);
|
let parent_upvars = ir.tcx.upvars_mentioned(ir.body_owner);
|
||||||
call_caps.extend(upvars.iter().filter_map(|(&var_id, upvar)| {
|
call_caps.extend(upvars.iter().filter_map(|(&var_id, upvar)| {
|
||||||
let has_parent =
|
let has_parent =
|
||||||
parent_upvars.map_or(false, |upvars| upvars.contains_key(&var_id));
|
parent_upvars.map_or(false, |upvars| upvars.contains_key(&var_id));
|
||||||
@ -1364,7 +1364,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
|||||||
) -> LiveNode {
|
) -> LiveNode {
|
||||||
match path.res {
|
match path.res {
|
||||||
Res::Local(hid) => {
|
Res::Local(hid) => {
|
||||||
let upvars = self.ir.tcx.upvars(self.ir.body_owner);
|
let upvars = self.ir.tcx.upvars_mentioned(self.ir.body_owner);
|
||||||
if !upvars.map_or(false, |upvars| upvars.contains_key(&hid)) {
|
if !upvars.map_or(false, |upvars| upvars.contains_key(&hid)) {
|
||||||
self.access_var(hir_id, hid, succ, acc, path.span)
|
self.access_var(hir_id, hid, succ, acc, path.span)
|
||||||
} else {
|
} else {
|
||||||
@ -1529,7 +1529,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
|
|||||||
match expr.kind {
|
match expr.kind {
|
||||||
hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) => {
|
hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) => {
|
||||||
if let Res::Local(var_hid) = path.res {
|
if let Res::Local(var_hid) = path.res {
|
||||||
let upvars = self.ir.tcx.upvars(self.ir.body_owner);
|
let upvars = self.ir.tcx.upvars_mentioned(self.ir.body_owner);
|
||||||
if !upvars.map_or(false, |upvars| upvars.contains_key(&var_hid)) {
|
if !upvars.map_or(false, |upvars| upvars.contains_key(&var_hid)) {
|
||||||
// Assignment to an immutable variable or argument: only legal
|
// Assignment to an immutable variable or argument: only legal
|
||||||
// if there is no later assignment. If this local is actually
|
// if there is no later assignment. If this local is actually
|
||||||
|
@ -10,7 +10,7 @@ use rustc_middle::ty::TyCtxt;
|
|||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
pub fn provide(providers: &mut Providers<'_>) {
|
pub fn provide(providers: &mut Providers<'_>) {
|
||||||
providers.upvars = |tcx, def_id| {
|
providers.upvars_mentioned = |tcx, def_id| {
|
||||||
if !tcx.is_closure(def_id) {
|
if !tcx.is_closure(def_id) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ impl Visitor<'tcx> for CaptureCollector<'a, 'tcx> {
|
|||||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
|
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
|
||||||
if let hir::ExprKind::Closure(..) = expr.kind {
|
if let hir::ExprKind::Closure(..) = expr.kind {
|
||||||
let closure_def_id = self.tcx.hir().local_def_id(expr.hir_id);
|
let closure_def_id = self.tcx.hir().local_def_id(expr.hir_id);
|
||||||
if let Some(upvars) = self.tcx.upvars(closure_def_id) {
|
if let Some(upvars) = self.tcx.upvars_mentioned(closure_def_id) {
|
||||||
// Every capture of a closure expression is a local in scope,
|
// Every capture of a closure expression is a local in scope,
|
||||||
// that is moved/copied/borrowed into the closure value, and
|
// that is moved/copied/borrowed into the closure value, and
|
||||||
// for this analysis they are like any other access to a local.
|
// for this analysis they are like any other access to a local.
|
||||||
|
@ -1380,7 +1380,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||||||
let mut interior_or_upvar_span = None;
|
let mut interior_or_upvar_span = None;
|
||||||
let mut interior_extra_info = None;
|
let mut interior_extra_info = None;
|
||||||
|
|
||||||
if let Some(upvars) = self.tcx.upvars(generator_did) {
|
if let Some(upvars) = self.tcx.upvars_mentioned(generator_did) {
|
||||||
interior_or_upvar_span = upvars.iter().find_map(|(upvar_id, upvar)| {
|
interior_or_upvar_span = upvars.iter().find_map(|(upvar_id, upvar)| {
|
||||||
let upvar_ty = tables.node_type(*upvar_id);
|
let upvar_ty = tables.node_type(*upvar_id);
|
||||||
let upvar_ty = self.resolve_vars_if_possible(&upvar_ty);
|
let upvar_ty = self.resolve_vars_if_possible(&upvar_ty);
|
||||||
|
@ -90,18 +90,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
base_substs.extend_to(self.tcx, expr_def_id.to_def_id(), |param, _| match param.kind {
|
base_substs.extend_to(self.tcx, expr_def_id.to_def_id(), |param, _| match param.kind {
|
||||||
GenericParamDefKind::Lifetime => span_bug!(expr.span, "closure has lifetime param"),
|
GenericParamDefKind::Lifetime => span_bug!(expr.span, "closure has lifetime param"),
|
||||||
GenericParamDefKind::Type { .. } => if param.index as usize == tupled_upvars_idx {
|
GenericParamDefKind::Type { .. } => if param.index as usize == tupled_upvars_idx {
|
||||||
self.tcx.mk_tup(self.tcx.upvars(expr_def_id).iter().flat_map(|upvars| {
|
self.tcx.mk_tup(self.tcx.upvars_mentioned(expr_def_id).iter().flat_map(
|
||||||
upvars.iter().map(|(&var_hir_id, _)| {
|
|upvars| {
|
||||||
// Create type variables (for now) to represent the transformed
|
upvars.iter().map(|(&var_hir_id, _)| {
|
||||||
// types of upvars. These will be unified during the upvar
|
// Create type variables (for now) to represent the transformed
|
||||||
// inference phase (`upvar.rs`).
|
// types of upvars. These will be unified during the upvar
|
||||||
self.infcx.next_ty_var(TypeVariableOrigin {
|
// inference phase (`upvar.rs`).
|
||||||
// FIXME(eddyb) distinguish upvar inference variables from the rest.
|
self.infcx.next_ty_var(TypeVariableOrigin {
|
||||||
kind: TypeVariableOriginKind::ClosureSynthetic,
|
// FIXME(eddyb) distinguish upvar inference variables from the rest.
|
||||||
span: self.tcx.hir().span(var_hir_id),
|
kind: TypeVariableOriginKind::ClosureSynthetic,
|
||||||
|
span: self.tcx.hir().span(var_hir_id),
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
},
|
||||||
}))
|
))
|
||||||
} else {
|
} else {
|
||||||
// Create type variables (for now) to represent the various
|
// Create type variables (for now) to represent the various
|
||||||
// pieces of information kept in `{Closure,Generic}Substs`.
|
// pieces of information kept in `{Closure,Generic}Substs`.
|
||||||
|
@ -111,7 +111,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(upvars) = self.tcx.upvars(closure_def_id) {
|
if let Some(upvars) = self.tcx.upvars_mentioned(closure_def_id) {
|
||||||
let mut upvar_list: FxIndexMap<hir::HirId, ty::UpvarId> =
|
let mut upvar_list: FxIndexMap<hir::HirId, ty::UpvarId> =
|
||||||
FxIndexMap::with_capacity_and_hasher(upvars.len(), Default::default());
|
FxIndexMap::with_capacity_and_hasher(upvars.len(), Default::default());
|
||||||
for (&var_hir_id, _) in upvars.iter() {
|
for (&var_hir_id, _) in upvars.iter() {
|
||||||
@ -218,7 +218,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
let closure_def_id = tcx.hir().local_def_id(closure_id);
|
let closure_def_id = tcx.hir().local_def_id(closure_id);
|
||||||
|
|
||||||
tcx.upvars(closure_def_id)
|
tcx.upvars_mentioned(closure_def_id)
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|upvars| {
|
.flat_map(|upvars| {
|
||||||
upvars.iter().map(|(&var_hir_id, _)| {
|
upvars.iter().map(|(&var_hir_id, _)| {
|
||||||
|
@ -539,7 +539,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
|
|||||||
debug!("walk_captures({:?})", closure_expr);
|
debug!("walk_captures({:?})", closure_expr);
|
||||||
|
|
||||||
let closure_def_id = self.tcx().hir().local_def_id(closure_expr.hir_id);
|
let closure_def_id = self.tcx().hir().local_def_id(closure_expr.hir_id);
|
||||||
if let Some(upvars) = self.tcx().upvars(closure_def_id) {
|
if let Some(upvars) = self.tcx().upvars_mentioned(closure_def_id) {
|
||||||
for &var_id in upvars.keys() {
|
for &var_id in upvars.keys() {
|
||||||
let upvar_id = ty::UpvarId {
|
let upvar_id = ty::UpvarId {
|
||||||
var_path: ty::UpvarPath { hir_id: var_id },
|
var_path: ty::UpvarPath { hir_id: var_id },
|
||||||
|
@ -159,7 +159,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
|
|||||||
infcx,
|
infcx,
|
||||||
param_env,
|
param_env,
|
||||||
body_owner,
|
body_owner,
|
||||||
upvars: infcx.tcx.upvars(body_owner),
|
upvars: infcx.tcx.upvars_mentioned(body_owner),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user