Skip to content

Commit a68ed06

Browse files
varkoryodaldevoid
andcommitted
Split ct_err out into CommonConsts
Co-Authored-By: Gabriel Smith <[email protected]>
1 parent 541de81 commit a68ed06

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

src/librustc/infer/resolve.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for FullTypeResolver<'a, 'gcx, 'tcx>
220220
match c.val {
221221
ConstValue::Infer(InferConst::Var(vid)) => {
222222
self.err = Some(FixupError::UnresolvedConst(vid));
223-
return self.tcx().types.ct_err;
223+
return self.tcx().consts.err;
224224
}
225225
ConstValue::Infer(InferConst::Fresh(_)) => {
226226
bug!("Unexpected const in full const resolver: {:?}", c);

src/librustc/ty/context.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,10 @@ pub struct CommonLifetimes<'tcx> {
231231
pub re_empty: Region<'tcx>,
232232
pub re_static: Region<'tcx>,
233233
pub re_erased: Region<'tcx>,
234+
}
234235

235-
pub ct_err: &'tcx Const<'tcx>,
236+
pub struct CommonConsts<'tcx> {
237+
pub err: &'tcx Const<'tcx>,
236238
}
237239

238240
pub struct LocalTableInContext<'a, V: 'a> {
@@ -945,7 +947,7 @@ impl<'tcx> CommonTypes<'tcx> {
945947
bool: mk(Bool),
946948
char: mk(Char),
947949
never: mk(Never),
948-
err,
950+
err: mk(Error),
949951
isize: mk(Int(ast::IntTy::Isize)),
950952
i8: mk(Int(ast::IntTy::I8)),
951953
i16: mk(Int(ast::IntTy::I16)),
@@ -982,6 +984,20 @@ impl<'tcx> CommonLifetimes<'tcx> {
982984
}
983985
}
984986

987+
impl<'tcx> CommonConsts<'tcx> {
988+
fn new(interners: &CtxtInterners<'tcx>, types: &CommonTypes<'tcx>) -> CommonConsts<'tcx> {
989+
let mk_const = |c| {
990+
interners.const_.borrow_mut().intern(c, |c| {
991+
Interned(interners.arena.alloc(c))
992+
}).0
993+
};
994+
995+
CommonConsts {
996+
err: mk_const(ty::Const::zero_sized(types.err)),
997+
}
998+
}
999+
}
1000+
9851001
// This struct contains information regarding the `ReFree(FreeRegion)` corresponding to a lifetime
9861002
// conflict.
9871003
#[derive(Debug)]
@@ -1032,6 +1048,9 @@ pub struct GlobalCtxt<'tcx> {
10321048
/// Common lifetimes, pre-interned for your convenience.
10331049
pub lifetimes: CommonLifetimes<'tcx>,
10341050

1051+
/// Common consts, pre-interned for your convenience.
1052+
pub consts: CommonConsts<'tcx>,
1053+
10351054
/// Map indicating what traits are in scope for places where this
10361055
/// is relevant; generated by resolve.
10371056
trait_map: FxHashMap<DefIndex,
@@ -1231,6 +1250,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
12311250
let interners = CtxtInterners::new(&arenas.interner);
12321251
let common_types = CommonTypes::new(&interners);
12331252
let common_lifetimes = CommonLifetimes::new(&interners);
1253+
let common_consts = CommonConsts::new(&interners, &common_types);
12341254
let dep_graph = hir.dep_graph.clone();
12351255
let max_cnum = cstore.crates_untracked().iter().map(|c| c.as_usize()).max().unwrap_or(0);
12361256
let mut providers = IndexVec::from_elem_n(extern_providers, max_cnum + 1);
@@ -1286,6 +1306,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
12861306
dep_graph,
12871307
types: common_types,
12881308
lifetimes: common_lifetimes,
1309+
consts: common_consts,
12891310
trait_map,
12901311
export_map: resolutions.export_map.into_iter().map(|(k, v)| {
12911312
let exports: Vec<_> = v.into_iter().map(|e| {

src/librustc_typeck/check/writeback.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
594594
),
595595
)
596596
.emit();
597-
return self.tcx().types.ct_err;
597+
return self.tcx().consts.err;
598598
}
599599
ct
600600
}
@@ -864,7 +864,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Resolver<'cx, 'gcx, 'tcx> {
864864
);
865865
// FIXME: we'd like to use `self.report_error`, but it doesn't yet
866866
// accept a &'tcx ty::Const.
867-
self.tcx().types.ct_err
867+
self.tcx().consts.err
868868
}
869869
}
870870
}

0 commit comments

Comments
 (0)