Adds TyCtxt::require_lang_item(LangItem) to simplify lang item requires.
Replaces instances of tcx.lang_items.require(..) with fatal unwrap with this method.
This commit is contained in:
parent
9b803ec421
commit
a79c80d0b0
@ -1493,8 +1493,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
let copy_def_id = self.tcx.lang_items.require(lang_items::CopyTraitLangItem)
|
||||
.unwrap_or_else(|msg| self.tcx.sess.fatal(&msg[..]));
|
||||
let copy_def_id = self.tcx.require_lang_item(lang_items::CopyTraitLangItem);
|
||||
|
||||
// this can get called from typeck (by euv), and moves_by_default
|
||||
// rightly refuses to work with inference variables, but
|
||||
|
@ -356,3 +356,11 @@ language_item_table! {
|
||||
|
||||
DebugTraitLangItem, "debug_trait", debug_trait;
|
||||
}
|
||||
|
||||
impl<'a, 'tcx, 'gcx> ty::TyCtxt<'a, 'tcx, 'gcx> {
|
||||
pub fn require_lang_item(&self, lang_item: LangItem) -> DefId {
|
||||
self.lang_items.require(lang_item).unwrap_or_else(|msg| {
|
||||
self.sess.fatal(&msg)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -2521,8 +2521,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
|
||||
|
||||
// We can only make objects from sized types.
|
||||
let tr = ty::TraitRef {
|
||||
def_id: tcx.lang_items.require(lang_items::SizedTraitLangItem)
|
||||
.unwrap_or_else(|msg| tcx.sess.fatal(&msg[..])),
|
||||
def_id: tcx.require_lang_item(lang_items::SizedTraitLangItem),
|
||||
substs: tcx.mk_substs_trait(source, &[]),
|
||||
};
|
||||
push(tr.to_predicate());
|
||||
|
@ -11,6 +11,7 @@
|
||||
use hir::def_id::DefId;
|
||||
use ty::{self, Ty, TyCtxt};
|
||||
use syntax::ast;
|
||||
use middle::lang_items::OwnedBoxLangItem;
|
||||
|
||||
use self::SimplifiedType::*;
|
||||
|
||||
@ -70,10 +71,7 @@ pub fn simplify_type<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
}
|
||||
ty::TyBox(_) => {
|
||||
// treat like we would treat `Box`
|
||||
match tcx.lang_items.require_owned_box() {
|
||||
Ok(def_id) => Some(AdtSimplifiedType(def_id)),
|
||||
Err(msg) => tcx.sess.fatal(&msg),
|
||||
}
|
||||
Some(AdtSimplifiedType(tcx.require_lang_item(OwnedBoxLangItem)))
|
||||
}
|
||||
ty::TyClosure(def_id, _) => {
|
||||
Some(ClosureSimplifiedType(def_id))
|
||||
|
@ -1878,18 +1878,14 @@ pub enum ClosureKind {
|
||||
|
||||
impl<'a, 'tcx> ClosureKind {
|
||||
pub fn trait_did(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> DefId {
|
||||
let result = match *self {
|
||||
ClosureKind::Fn => tcx.lang_items.require(FnTraitLangItem),
|
||||
match *self {
|
||||
ClosureKind::Fn => tcx.require_lang_item(FnTraitLangItem),
|
||||
ClosureKind::FnMut => {
|
||||
tcx.lang_items.require(FnMutTraitLangItem)
|
||||
tcx.require_lang_item(FnMutTraitLangItem)
|
||||
}
|
||||
ClosureKind::FnOnce => {
|
||||
tcx.lang_items.require(FnOnceTraitLangItem)
|
||||
tcx.require_lang_item(FnOnceTraitLangItem)
|
||||
}
|
||||
};
|
||||
match result {
|
||||
Ok(trait_did) => trait_did,
|
||||
Err(err) => tcx.sess.fatal(&err[..]),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -646,8 +646,7 @@ impl<'a, 'tcx> ty::TyS<'tcx> {
|
||||
TyProjection(..) | TyParam(..) | TyInfer(..) | TyError => None
|
||||
}.unwrap_or_else(|| {
|
||||
!self.impls_bound(tcx, param_env,
|
||||
tcx.lang_items.require(lang_items::CopyTraitLangItem)
|
||||
.unwrap_or_else(|msg| tcx.sess.fatal(&msg[..])),
|
||||
tcx.require_lang_item(lang_items::CopyTraitLangItem),
|
||||
¶m_env.is_copy_cache, span) });
|
||||
|
||||
if !self.has_param_types() && !self.has_self_ty() {
|
||||
@ -689,9 +688,8 @@ impl<'a, 'tcx> ty::TyS<'tcx> {
|
||||
TyAdt(..) | TyProjection(..) | TyParam(..) |
|
||||
TyInfer(..) | TyAnon(..) | TyError => None
|
||||
}.unwrap_or_else(|| {
|
||||
self.impls_bound(tcx, param_env, tcx.lang_items.require(lang_items::SizedTraitLangItem)
|
||||
.unwrap_or_else(|msg| tcx.sess.fatal(&msg[..])),
|
||||
¶m_env.is_copy_cache, span) });
|
||||
self.impls_bound(tcx, param_env, tcx.require_lang_item(lang_items::SizedTraitLangItem),
|
||||
¶m_env.is_sized_cache, span) });
|
||||
|
||||
if !self.has_param_types() && !self.has_self_ty() {
|
||||
self.flags.set(self.flags.get() | if result {
|
||||
|
@ -283,8 +283,7 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> {
|
||||
if !subty.has_escaping_regions() {
|
||||
let cause = self.cause(cause);
|
||||
let trait_ref = ty::TraitRef {
|
||||
def_id: self.infcx.tcx.lang_items.require(lang_items::SizedTraitLangItem)
|
||||
.unwrap_or_else(|msg| self.infcx.tcx.sess.fatal(&msg[..])),
|
||||
def_id: self.infcx.tcx.require_lang_item(lang_items::SizedTraitLangItem),
|
||||
substs: self.infcx.tcx.mk_substs_trait(subty, &[]),
|
||||
};
|
||||
self.out.push(traits::Obligation::new(cause, trait_ref.to_predicate()));
|
||||
|
@ -857,8 +857,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
|
||||
|
||||
let tcx = self.tcx;
|
||||
let unit_temp = Lvalue::Local(self.patch.new_temp(tcx.mk_nil()));
|
||||
let free_func = tcx.lang_items.require(lang_items::BoxFreeFnLangItem)
|
||||
.unwrap_or_else(|e| tcx.sess.fatal(&e));
|
||||
let free_func = tcx.require_lang_item(lang_items::BoxFreeFnLangItem);
|
||||
let substs = tcx.mk_substs(iter::once(Kind::from(ty)));
|
||||
let fty = tcx.item_type(free_func).subst(tcx, substs);
|
||||
|
||||
|
@ -783,8 +783,7 @@ fn build_free<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
data: &FreeData<'tcx>,
|
||||
target: BasicBlock)
|
||||
-> TerminatorKind<'tcx> {
|
||||
let free_func = tcx.lang_items.require(lang_items::BoxFreeFnLangItem)
|
||||
.unwrap_or_else(|e| tcx.sess.fatal(&e));
|
||||
let free_func = tcx.require_lang_item(lang_items::BoxFreeFnLangItem);
|
||||
let substs = tcx.intern_substs(&[Kind::from(data.item_ty)]);
|
||||
TerminatorKind::Call {
|
||||
func: Operand::Constant(Constant {
|
||||
|
@ -1048,9 +1048,7 @@ impl<'tcx> MirPass<'tcx> for QualifyAndPromoteConstants {
|
||||
let cause = traits::ObligationCause::new(mir.span, id, traits::SharedStatic);
|
||||
let mut fulfillment_cx = traits::FulfillmentContext::new();
|
||||
fulfillment_cx.register_bound(&infcx, ty,
|
||||
tcx.lang_items
|
||||
.require(lang_items::SyncTraitLangItem)
|
||||
.unwrap_or_else(|msg| tcx.sess.fatal(&msg[..])),
|
||||
tcx.require_lang_item(lang_items::SyncTraitLangItem),
|
||||
cause);
|
||||
if let Err(err) = fulfillment_cx.select_all_or_error(&infcx) {
|
||||
infcx.report_fulfillment_errors(&err);
|
||||
|
@ -545,8 +545,7 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
|
||||
|
||||
impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
fn type_is_known_to_be_sized(&self, ty: Ty<'tcx>, span: Span) -> bool {
|
||||
let lang_item = self.tcx.lang_items.require(lang_items::SizedTraitLangItem)
|
||||
.unwrap_or_else(|msg| self.tcx.sess.fatal(&msg[..]));
|
||||
let lang_item = self.tcx.require_lang_item(lang_items::SizedTraitLangItem);
|
||||
traits::type_known_to_meet_bound(self, ty, lang_item, span)
|
||||
}
|
||||
}
|
||||
|
@ -1819,8 +1819,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
span: Span,
|
||||
code: traits::ObligationCauseCode<'tcx>)
|
||||
{
|
||||
let lang_item = self.tcx.lang_items.require(lang_items::SizedTraitLangItem)
|
||||
.unwrap_or_else(|msg| self.tcx.sess.fatal(&msg[..]));
|
||||
let lang_item = self.tcx.require_lang_item(lang_items::SizedTraitLangItem);
|
||||
self.require_type_meets(ty, span, code, lang_item);
|
||||
}
|
||||
|
||||
@ -3902,8 +3901,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
if count > 1 {
|
||||
// For [foo, ..n] where n > 1, `foo` must have
|
||||
// Copy type:
|
||||
let lang_item = self.tcx.lang_items.require(lang_items::CopyTraitLangItem)
|
||||
.unwrap_or_else(|msg| self.tcx.sess.fatal(&msg[..]));
|
||||
let lang_item = self.tcx.require_lang_item(lang_items::CopyTraitLangItem);
|
||||
self.require_type_meets(t, expr.span, traits::RepeatVec, lang_item);
|
||||
}
|
||||
|
||||
|
@ -238,8 +238,7 @@ impl<'ccx, 'gcx> CheckTypeWellFormedVisitor<'ccx, 'gcx> {
|
||||
for field in &variant.fields[..variant.fields.len() - unsized_len] {
|
||||
fcx.register_bound(
|
||||
field.ty,
|
||||
fcx.tcx.lang_items.require(lang_items::SizedTraitLangItem)
|
||||
.unwrap_or_else(|msg| fcx.tcx.sess.fatal(&msg[..])),
|
||||
fcx.tcx.require_lang_item(lang_items::SizedTraitLangItem),
|
||||
traits::ObligationCause::new(field.span,
|
||||
fcx.body_id,
|
||||
traits::FieldSized));
|
||||
|
@ -594,8 +594,7 @@ pub enum TyParamBound {
|
||||
|
||||
impl TyParamBound {
|
||||
fn maybe_sized(cx: &DocContext) -> TyParamBound {
|
||||
let did = cx.tcx.lang_items.require(lang_items::SizedTraitLangItem)
|
||||
.unwrap_or_else(|msg| cx.tcx.sess.fatal(&msg[..]));
|
||||
let did = cx.tcx.require_lang_item(lang_items::SizedTraitLangItem);
|
||||
let empty = cx.tcx.intern_substs(&[]);
|
||||
let path = external_path(cx, &cx.tcx.item_name(did).as_str(),
|
||||
Some(did), false, vec![], empty);
|
||||
|
Loading…
x
Reference in New Issue
Block a user