Skip to content

Commit 8465daf

Browse files
committed
Check for local types in writeback with debug assertions
1 parent c932518 commit 8465daf

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

src/librustc/infer/outlives/free_region_map.rs

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ pub struct FreeRegionMap<'tcx> {
1111
}
1212

1313
impl<'tcx> FreeRegionMap<'tcx> {
14+
pub fn elements(&self) -> impl Iterator<Item=&Region<'tcx>> {
15+
self.relation.elements()
16+
}
17+
1418
pub fn is_empty(&self) -> bool {
1519
self.relation.is_empty()
1620
}

src/librustc_data_structures/transitive_relation.rs

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ impl<T: Clone + Debug + Eq + Hash> TransitiveRelation<T> {
5858
self.edges.is_empty()
5959
}
6060

61+
pub fn elements(&self) -> impl Iterator<Item=&T> {
62+
self.elements.iter()
63+
}
64+
6165
fn index(&self, a: &T) -> Option<Index> {
6266
self.map.get(a).cloned()
6367
}

src/librustc_typeck/check/writeback.rs

+11-18
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,8 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
363363
}
364364

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

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

384-
let c_ty = if let Some(c_ty) = self.tcx().lift_to_global(c_ty) {
385-
c_ty
386-
} else {
382+
if cfg!(debug_assertions) && c_ty.has_local_value() {
387383
span_bug!(
388384
hir_id.to_span(self.fcx.tcx),
389-
"writeback: `{:?}` missing from the global type context",
385+
"writeback: `{:?}` is a local value",
390386
c_ty
391387
);
392388
};
@@ -423,12 +419,10 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
423419
debug_assert_eq!(fcx_tables.local_id_root, self.tables.local_id_root);
424420

425421
for (&def_id, c_sig) in fcx_tables.user_provided_sigs.iter() {
426-
let c_sig = if let Some(c_sig) = self.tcx().lift_to_global(c_sig) {
427-
c_sig
428-
} else {
422+
if cfg!(debug_assertions) && c_sig.has_local_value() {
429423
span_bug!(
430424
self.fcx.tcx.hir().span_if_local(def_id).unwrap(),
431-
"writeback: `{:?}` missing from the global type context",
425+
"writeback: `{:?}` is a local value",
432426
c_sig
433427
);
434428
};
@@ -743,20 +737,19 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
743737
}
744738
}
745739

746-
fn resolve<T>(&self, x: &T, span: &dyn Locatable) -> T::Lifted
740+
fn resolve<T>(&self, x: &T, span: &dyn Locatable) -> T
747741
where
748-
T: TypeFoldable<'tcx> + ty::Lift<'tcx>,
742+
T: TypeFoldable<'tcx>,
749743
{
750744
let x = x.fold_with(&mut Resolver::new(self.fcx, span, self.body));
751-
if let Some(lifted) = self.tcx().lift_to_global(&x) {
752-
lifted
753-
} else {
745+
if cfg!(debug_assertions) && x.has_local_value() {
754746
span_bug!(
755747
span.to_span(self.fcx.tcx),
756-
"writeback: `{:?}` missing from the global type context",
748+
"writeback: `{:?}` is a local value",
757749
x
758750
);
759751
}
752+
x
760753
}
761754
}
762755

0 commit comments

Comments
 (0)