Skip to content

Commit

Permalink
Split ct_err out into CommonConsts
Browse files Browse the repository at this point in the history
Co-Authored-By: Gabriel Smith <yodaldevoid@users.noreply.github.com>
  • Loading branch information
varkor and yodaldevoid committed May 1, 2019
1 parent 541de81 commit a68ed06
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/librustc/infer/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for FullTypeResolver<'a, 'gcx, 'tcx>
match c.val {
ConstValue::Infer(InferConst::Var(vid)) => {
self.err = Some(FixupError::UnresolvedConst(vid));
return self.tcx().types.ct_err;
return self.tcx().consts.err;
}
ConstValue::Infer(InferConst::Fresh(_)) => {
bug!("Unexpected const in full const resolver: {:?}", c);
Expand Down
25 changes: 23 additions & 2 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,10 @@ pub struct CommonLifetimes<'tcx> {
pub re_empty: Region<'tcx>,
pub re_static: Region<'tcx>,
pub re_erased: Region<'tcx>,
}

pub ct_err: &'tcx Const<'tcx>,
pub struct CommonConsts<'tcx> {
pub err: &'tcx Const<'tcx>,
}

pub struct LocalTableInContext<'a, V: 'a> {
Expand Down Expand Up @@ -945,7 +947,7 @@ impl<'tcx> CommonTypes<'tcx> {
bool: mk(Bool),
char: mk(Char),
never: mk(Never),
err,
err: mk(Error),
isize: mk(Int(ast::IntTy::Isize)),
i8: mk(Int(ast::IntTy::I8)),
i16: mk(Int(ast::IntTy::I16)),
Expand Down Expand Up @@ -982,6 +984,20 @@ impl<'tcx> CommonLifetimes<'tcx> {
}
}

impl<'tcx> CommonConsts<'tcx> {
fn new(interners: &CtxtInterners<'tcx>, types: &CommonTypes<'tcx>) -> CommonConsts<'tcx> {
let mk_const = |c| {
interners.const_.borrow_mut().intern(c, |c| {
Interned(interners.arena.alloc(c))
}).0
};

CommonConsts {
err: mk_const(ty::Const::zero_sized(types.err)),
}
}
}

// This struct contains information regarding the `ReFree(FreeRegion)` corresponding to a lifetime
// conflict.
#[derive(Debug)]
Expand Down Expand Up @@ -1032,6 +1048,9 @@ pub struct GlobalCtxt<'tcx> {
/// Common lifetimes, pre-interned for your convenience.
pub lifetimes: CommonLifetimes<'tcx>,

/// Common consts, pre-interned for your convenience.
pub consts: CommonConsts<'tcx>,

/// Map indicating what traits are in scope for places where this
/// is relevant; generated by resolve.
trait_map: FxHashMap<DefIndex,
Expand Down Expand Up @@ -1231,6 +1250,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
let interners = CtxtInterners::new(&arenas.interner);
let common_types = CommonTypes::new(&interners);
let common_lifetimes = CommonLifetimes::new(&interners);
let common_consts = CommonConsts::new(&interners, &common_types);
let dep_graph = hir.dep_graph.clone();
let max_cnum = cstore.crates_untracked().iter().map(|c| c.as_usize()).max().unwrap_or(0);
let mut providers = IndexVec::from_elem_n(extern_providers, max_cnum + 1);
Expand Down Expand Up @@ -1286,6 +1306,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
dep_graph,
types: common_types,
lifetimes: common_lifetimes,
consts: common_consts,
trait_map,
export_map: resolutions.export_map.into_iter().map(|(k, v)| {
let exports: Vec<_> = v.into_iter().map(|e| {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
),
)
.emit();
return self.tcx().types.ct_err;
return self.tcx().consts.err;
}
ct
}
Expand Down Expand Up @@ -864,7 +864,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Resolver<'cx, 'gcx, 'tcx> {
);
// FIXME: we'd like to use `self.report_error`, but it doesn't yet
// accept a &'tcx ty::Const.
self.tcx().types.ct_err
self.tcx().consts.err
}
}
}
Expand Down

0 comments on commit a68ed06

Please sign in to comment.