Skip to content

Commit

Permalink
Check for local types in writeback with debug assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Jun 26, 2019
1 parent c932518 commit 8465daf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
4 changes: 4 additions & 0 deletions src/librustc/infer/outlives/free_region_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ pub struct FreeRegionMap<'tcx> {
}

impl<'tcx> FreeRegionMap<'tcx> {
pub fn elements(&self) -> impl Iterator<Item=&Region<'tcx>> {
self.relation.elements()
}

pub fn is_empty(&self) -> bool {
self.relation.is_empty()
}
Expand Down
4 changes: 4 additions & 0 deletions src/librustc_data_structures/transitive_relation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ impl<T: Clone + Debug + Eq + Hash> TransitiveRelation<T> {
self.edges.is_empty()
}

pub fn elements(&self) -> impl Iterator<Item=&T> {
self.elements.iter()
}

fn index(&self, a: &T) -> Option<Index> {
self.map.get(a).cloned()
}
Expand Down
29 changes: 11 additions & 18 deletions src/librustc_typeck/check/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,8 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
}

fn visit_free_region_map(&mut self) {
let free_region_map = self.tcx()
.lift_to_global(&self.fcx.tables.borrow().free_region_map);
let free_region_map = free_region_map.expect("all regions in free-region-map are global");
self.tables.free_region_map = free_region_map;
self.tables.free_region_map = self.fcx.tables.borrow().free_region_map.clone();
debug_assert!(!self.tables.free_region_map.elements().any(|r| r.has_local_value()));
}

fn visit_user_provided_tys(&mut self) {
Expand All @@ -381,12 +379,10 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
local_id,
};

let c_ty = if let Some(c_ty) = self.tcx().lift_to_global(c_ty) {
c_ty
} else {
if cfg!(debug_assertions) && c_ty.has_local_value() {
span_bug!(
hir_id.to_span(self.fcx.tcx),
"writeback: `{:?}` missing from the global type context",
"writeback: `{:?}` is a local value",
c_ty
);
};
Expand Down Expand Up @@ -423,12 +419,10 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
debug_assert_eq!(fcx_tables.local_id_root, self.tables.local_id_root);

for (&def_id, c_sig) in fcx_tables.user_provided_sigs.iter() {
let c_sig = if let Some(c_sig) = self.tcx().lift_to_global(c_sig) {
c_sig
} else {
if cfg!(debug_assertions) && c_sig.has_local_value() {
span_bug!(
self.fcx.tcx.hir().span_if_local(def_id).unwrap(),
"writeback: `{:?}` missing from the global type context",
"writeback: `{:?}` is a local value",
c_sig
);
};
Expand Down Expand Up @@ -743,20 +737,19 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
}
}

fn resolve<T>(&self, x: &T, span: &dyn Locatable) -> T::Lifted
fn resolve<T>(&self, x: &T, span: &dyn Locatable) -> T
where
T: TypeFoldable<'tcx> + ty::Lift<'tcx>,
T: TypeFoldable<'tcx>,
{
let x = x.fold_with(&mut Resolver::new(self.fcx, span, self.body));
if let Some(lifted) = self.tcx().lift_to_global(&x) {
lifted
} else {
if cfg!(debug_assertions) && x.has_local_value() {
span_bug!(
span.to_span(self.fcx.tcx),
"writeback: `{:?}` missing from the global type context",
"writeback: `{:?}` is a local value",
x
);
}
x
}
}

Expand Down

0 comments on commit 8465daf

Please sign in to comment.