Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
roxelo committed Dec 27, 2020
1 parent 84318a3 commit 3fa405c
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 17 deletions.
8 changes: 4 additions & 4 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::arena::Arena;
use crate::dep_graph::{self, DepGraph, DepKind, DepNode, DepNodeExt};
use crate::hir::exports::ExportMap;
use crate::hir::place;
use crate::hir::place::Place as HirPlace;
use crate::ich::{NodeIdHashingMode, StableHashingContext};
use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
use crate::lint::{struct_lint_level, LintDiagnosticBuilder, LintLevelSource};
Expand Down Expand Up @@ -380,7 +380,7 @@ pub struct TypeckResults<'tcx> {

/// Records the reasons that we picked the kind of each closure;
/// not all closures are present in the map.
closure_kind_origins: ItemLocalMap<(Span, place::Place<'tcx>)>,
closure_kind_origins: ItemLocalMap<(Span, HirPlace<'tcx>)>,

/// For each fn, records the "liberated" types of its arguments
/// and return type. Liberated means that all bound regions
Expand Down Expand Up @@ -643,13 +643,13 @@ impl<'tcx> TypeckResults<'tcx> {
self.upvar_capture_map[&upvar_id]
}

pub fn closure_kind_origins(&self) -> LocalTableInContext<'_, (Span, place::Place<'tcx>)> {
pub fn closure_kind_origins(&self) -> LocalTableInContext<'_, (Span, HirPlace<'tcx>)> {
LocalTableInContext { hir_owner: self.hir_owner, data: &self.closure_kind_origins }
}

pub fn closure_kind_origins_mut(
&mut self,
) -> LocalTableInContextMut<'_, (Span, place::Place<'tcx>)> {
) -> LocalTableInContextMut<'_, (Span, HirPlace<'tcx>)> {
LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.closure_kind_origins }
}

Expand Down
12 changes: 7 additions & 5 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ pub use self::IntVarValue::*;
pub use self::Variance::*;

use crate::hir::exports::ExportMap;
use crate::hir::place::{Place as HirPlace, PlaceBase, ProjectionKind};
use crate::hir::place::{
Place as HirPlace, PlaceBase as HirPlaceBase, ProjectionKind as HirProjectionKind,
};
use crate::ich::StableHashingContext;
use crate::middle::cstore::CrateStoreDyn;
use crate::middle::resolve_lifetime::ObjectLifetimeDefault;
Expand Down Expand Up @@ -742,20 +744,20 @@ impl<'tcx> CapturedPlace<'tcx> {

pub fn place_to_string_for_capture(tcx: TyCtxt<'tcx>, place: &HirPlace<'tcx>) -> String {
let name = match place.base {
PlaceBase::Upvar(upvar_id) => tcx.hir().name(upvar_id.var_path.hir_id).to_string(),
HirPlaceBase::Upvar(upvar_id) => tcx.hir().name(upvar_id.var_path.hir_id).to_string(),
_ => bug!("Capture_information should only contain upvars"),
};
let mut curr_string = format!("{}", name);

for (i, proj) in place.projections.iter().enumerate() {
if ProjectionKind::Deref == proj.kind {
if HirProjectionKind::Deref == proj.kind {
curr_string = format!("*{}", curr_string);
} else {
match place.ty_before_projection(i).kind() {
ty::Adt(def, ..) if def.is_enum() => {
// we might be projecting *to* a variant, or to a field *in* a variant.
match proj.kind {
ProjectionKind::Field(_idx, variant) => {
HirProjectionKind::Field(_idx, variant) => {
curr_string = format!(
"{}.{}",
curr_string,
Expand All @@ -775,7 +777,7 @@ pub fn place_to_string_for_capture(tcx: TyCtxt<'tcx>, place: &HirPlace<'tcx>) ->
);
}
ty::Tuple(_) => match proj.kind {
ProjectionKind::Field(idx, _) => {
HirProjectionKind::Field(idx, _) => {
curr_string = format!("{}.{}", curr_string, idx);
}
_ => {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_mir/src/borrow_check/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_middle::mir::{
PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind,
};
use rustc_middle::ty::print::Print;
use rustc_middle::ty::{self, place_to_string_for_capture, DefIdTree, Instance, Ty, TyCtxt};
use rustc_middle::ty::{self, DefIdTree, Instance, Ty, TyCtxt};
use rustc_span::{
hygiene::{DesugaringKind, ForLoopLoc},
symbol::sym,
Expand Down Expand Up @@ -111,7 +111,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&format!(
"closure cannot be invoked more than once because it moves the \
variable `{}` out of its environment",
place_to_string_for_capture(self.infcx.tcx, hir_place)
ty::place_to_string_for_capture(self.infcx.tcx, hir_place)
),
);
return;
Expand All @@ -135,7 +135,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&format!(
"closure cannot be moved more than once as it is not `Copy` due to \
moving the variable `{}` out of its environment",
place_to_string_for_capture(self.infcx.tcx, hir_place)
ty::place_to_string_for_capture(self.infcx.tcx, hir_place)
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::ty::error::ExpectedFound;
use rustc_middle::ty::fold::TypeFolder;
use rustc_middle::ty::{
self, fast_reject, place_to_string_for_capture, AdtKind, SubtypePredicate, ToPolyTraitRef,
ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness,
self, fast_reject, AdtKind, SubtypePredicate, ToPolyTraitRef, ToPredicate, Ty, TyCtxt,
TypeFoldable, WithConstness,
};
use rustc_session::DiagnosticMessageId;
use rustc_span::symbol::{kw, sym};
Expand Down Expand Up @@ -603,7 +603,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
format!(
"closure is `FnOnce` because it moves the \
variable `{}` out of its environment",
place_to_string_for_capture(tcx, place)
ty::place_to_string_for_capture(tcx, place)
),
);
}
Expand All @@ -613,7 +613,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
format!(
"closure is `FnMut` because it mutates the \
variable `{}` here",
place_to_string_for_capture(tcx, place)
ty::place_to_string_for_capture(tcx, place)
),
);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
let common_hir_owner = fcx_typeck_results.hir_owner;

for (id, origin) in fcx_typeck_results.closure_kind_origins().iter() {
let hir_id = hir::HirId { owner: common_hir_owner, local_id: id.clone() };
let hir_id = hir::HirId { owner: common_hir_owner, local_id: *id };
self.typeck_results.closure_kind_origins_mut().insert(hir_id, origin.clone());
}
}
Expand Down
File renamed without changes.

0 comments on commit 3fa405c

Please sign in to comment.