Skip to content
2 changes: 1 addition & 1 deletion src/librustc_middle/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ macro_rules! arena_types {
[few] privacy_access_levels: rustc_middle::middle::privacy::AccessLevels,
[few] foreign_module: 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,
[] codegen_unit: rustc_middle::mir::mono::CodegenUnit<$tcx>,
[] attribute: rustc_ast::ast::Attribute,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_middle/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2439,7 +2439,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
};
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) {
let var_name = tcx.hir().name(var_id);
struct_fmt.field(&var_name.as_str(), place);
Expand All @@ -2458,7 +2458,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
let name = format!("[generator@{:?}]", tcx.hir().span(hir_id));
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) {
let var_name = tcx.hir().name(var_id);
struct_fmt.field(&var_name.as_str(), place);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_middle/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ rustc_queries! {
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
}
query maybe_unused_trait_import(def_id: LocalDefId) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_middle/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ pub trait PrettyPrinter<'tcx>:
let mut sep = " ";
for (&var_id, upvar_ty) in self
.tcx()
.upvars(did)
.upvars_mentioned(did)
.as_ref()
.iter()
.flat_map(|v| v.keys())
Expand Down Expand Up @@ -659,7 +659,7 @@ pub trait PrettyPrinter<'tcx>:
let mut sep = " ";
for (&var_id, upvar_ty) in self
.tcx()
.upvars(did)
.upvars_mentioned(did)
.as_ref()
.iter()
.flat_map(|v| v.keys())
Expand Down
13 changes: 9 additions & 4 deletions src/librustc_mir/borrow_check/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,16 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
self.describe_field_from_ty(&ty, field, variant_index)
}
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
// be borrowck'ing it, so we can just unwrap:
let (&var_id, _) =
self.infcx.tcx.upvars(def_id).unwrap().get_index(field.index()).unwrap();
let (&var_id, _) = self
.infcx
.tcx
.upvars_mentioned(def_id)
.unwrap()
.get_index(field.index())
.unwrap();

self.infcx.tcx.hir().name(var_id).to_string()
}
Expand Down Expand Up @@ -809,7 +814,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let expr = &self.infcx.tcx.hir().expect_expr(hir_id).kind;
debug!("closure_span: hir_id={:?} expr={:?}", hir_id, 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 {
Operand::Copy(place) | Operand::Move(place)
if target_place == place.as_ref() =>
Expand Down
Loading