use require_lang_item
over unwrap
.
This commit is contained in:
parent
750db09fa8
commit
5f93bc774b
@ -2,6 +2,7 @@ use crate::ty::subst::SubstsRef;
|
||||
use crate::ty::{self, Ty, TyCtxt};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::lang_items::{DerefMutTraitLangItem, DerefTraitLangItem};
|
||||
use rustc_macros::HashStable;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)]
|
||||
@ -117,11 +118,11 @@ pub struct OverloadedDeref<'tcx> {
|
||||
impl<'tcx> OverloadedDeref<'tcx> {
|
||||
pub fn method_call(&self, tcx: TyCtxt<'tcx>, source: Ty<'tcx>) -> (DefId, SubstsRef<'tcx>) {
|
||||
let trait_def_id = match self.mutbl {
|
||||
hir::Mutability::Not => tcx.lang_items().deref_trait(),
|
||||
hir::Mutability::Mut => tcx.lang_items().deref_mut_trait(),
|
||||
hir::Mutability::Not => tcx.require_lang_item(DerefTraitLangItem, None),
|
||||
hir::Mutability::Mut => tcx.require_lang_item(DerefMutTraitLangItem, None),
|
||||
};
|
||||
let method_def_id = tcx
|
||||
.associated_items(trait_def_id.unwrap())
|
||||
.associated_items(trait_def_id)
|
||||
.in_definition_order()
|
||||
.find(|m| m.kind == ty::AssocKind::Fn)
|
||||
.unwrap()
|
||||
|
@ -4,7 +4,7 @@ use crate::ty::{self, SubstsRef, Ty, TyCtxt, TypeFoldable};
|
||||
use rustc_errors::ErrorReported;
|
||||
use rustc_hir::def::Namespace;
|
||||
use rustc_hir::def_id::{CrateNum, DefId};
|
||||
use rustc_hir::lang_items::DropInPlaceFnLangItem;
|
||||
use rustc_hir::lang_items::{DropInPlaceFnLangItem, FnOnceTraitLangItem};
|
||||
use rustc_macros::HashStable;
|
||||
|
||||
use std::fmt;
|
||||
@ -375,7 +375,7 @@ impl<'tcx> Instance<'tcx> {
|
||||
substs: ty::SubstsRef<'tcx>,
|
||||
) -> Instance<'tcx> {
|
||||
debug!("fn_once_adapter_shim({:?}, {:?})", closure_did, substs);
|
||||
let fn_once = tcx.lang_items().fn_once_trait().unwrap();
|
||||
let fn_once = tcx.require_lang_item(FnOnceTraitLangItem, None);
|
||||
let call_once = tcx
|
||||
.associated_items(fn_once)
|
||||
.in_definition_order()
|
||||
|
@ -8,6 +8,7 @@ use rustc_ast::ast::{self, IntTy, UintTy};
|
||||
use rustc_attr as attr;
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::lang_items::{GeneratorStateLangItem, PinTypeLangItem};
|
||||
use rustc_index::bit_set::BitSet;
|
||||
use rustc_index::vec::{Idx, IndexVec};
|
||||
use rustc_session::{DataTypeKind, FieldInfo, SizeKind, VariantInfo};
|
||||
@ -2317,13 +2318,13 @@ impl<'tcx> ty::Instance<'tcx> {
|
||||
let env_region = ty::ReLateBound(ty::INNERMOST, ty::BrEnv);
|
||||
let env_ty = tcx.mk_mut_ref(tcx.mk_region(env_region), ty);
|
||||
|
||||
let pin_did = tcx.lang_items().pin_type().unwrap();
|
||||
let pin_did = tcx.require_lang_item(PinTypeLangItem, None);
|
||||
let pin_adt_ref = tcx.adt_def(pin_did);
|
||||
let pin_substs = tcx.intern_substs(&[env_ty.into()]);
|
||||
let env_ty = tcx.mk_adt(pin_adt_ref, pin_substs);
|
||||
|
||||
sig.map_bound(|sig| {
|
||||
let state_did = tcx.lang_items().gen_state().unwrap();
|
||||
let state_did = tcx.require_lang_item(GeneratorStateLangItem, None);
|
||||
let state_adt_ref = tcx.adt_def(state_did);
|
||||
let state_substs = tcx.intern_substs(&[
|
||||
sig.yield_ty.into(),
|
||||
|
@ -10,6 +10,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_errors::struct_span_err;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_hir::lang_items::{CoerceUnsizedTraitLangItem, CopyTraitLangItem, SizedTraitLangItem};
|
||||
use rustc_index::vec::{Idx, IndexVec};
|
||||
use rustc_infer::infer::canonical::QueryRegionConstraints;
|
||||
use rustc_infer::infer::outlives::env::RegionBoundPairs;
|
||||
@ -502,7 +503,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
|
||||
if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context {
|
||||
let tcx = self.tcx();
|
||||
let trait_ref = ty::TraitRef {
|
||||
def_id: tcx.lang_items().copy_trait().unwrap(),
|
||||
def_id: tcx.require_lang_item(CopyTraitLangItem, None),
|
||||
substs: tcx.mk_substs_trait(place_ty.ty, &[]),
|
||||
};
|
||||
|
||||
@ -1468,7 +1469,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
self.check_rvalue(body, rv, location);
|
||||
if !self.tcx().features().unsized_locals {
|
||||
let trait_ref = ty::TraitRef {
|
||||
def_id: tcx.lang_items().sized_trait().unwrap(),
|
||||
def_id: tcx.require_lang_item(SizedTraitLangItem, None),
|
||||
substs: tcx.mk_substs_trait(place_ty, &[]),
|
||||
};
|
||||
self.prove_trait_ref(
|
||||
@ -2013,7 +2014,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
ty::Predicate::Trait(
|
||||
ty::Binder::bind(ty::TraitPredicate {
|
||||
trait_ref: ty::TraitRef::new(
|
||||
self.tcx().lang_items().copy_trait().unwrap(),
|
||||
self.tcx()
|
||||
.require_lang_item(CopyTraitLangItem, None),
|
||||
tcx.mk_substs_trait(ty, &[]),
|
||||
),
|
||||
}),
|
||||
@ -2037,7 +2039,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
}
|
||||
|
||||
let trait_ref = ty::TraitRef {
|
||||
def_id: tcx.lang_items().sized_trait().unwrap(),
|
||||
def_id: tcx.require_lang_item(SizedTraitLangItem, None),
|
||||
substs: tcx.mk_substs_trait(ty, &[]),
|
||||
};
|
||||
|
||||
@ -2135,7 +2137,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
CastKind::Pointer(PointerCast::Unsize) => {
|
||||
let &ty = ty;
|
||||
let trait_ref = ty::TraitRef {
|
||||
def_id: tcx.lang_items().coerce_unsized_trait().unwrap(),
|
||||
def_id: tcx.require_lang_item(CoerceUnsizedTraitLangItem, None),
|
||||
substs: tcx.mk_substs_trait(op.ty(body, tcx), &[ty.into()]),
|
||||
};
|
||||
|
||||
|
@ -580,10 +580,8 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
|
||||
}
|
||||
mir::Rvalue::NullaryOp(mir::NullOp::Box, _) => {
|
||||
let tcx = self.tcx;
|
||||
let exchange_malloc_fn_def_id = tcx
|
||||
.lang_items()
|
||||
.require(ExchangeMallocFnLangItem)
|
||||
.unwrap_or_else(|e| tcx.sess.fatal(&e));
|
||||
let exchange_malloc_fn_def_id =
|
||||
tcx.require_lang_item(ExchangeMallocFnLangItem, None);
|
||||
let instance = Instance::mono(tcx, exchange_malloc_fn_def_id);
|
||||
if should_monomorphize_locally(tcx, &instance) {
|
||||
self.output.push(create_fn_mono_item(instance));
|
||||
|
@ -1,5 +1,6 @@
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::lang_items::FnMutTraitLangItem;
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::subst::{InternalSubsts, Subst};
|
||||
@ -70,7 +71,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<'
|
||||
build_call_shim(tcx, instance, None, CallKind::Direct(def_id), None)
|
||||
}
|
||||
ty::InstanceDef::ClosureOnceShim { call_once: _ } => {
|
||||
let fn_mut = tcx.lang_items().fn_mut_trait().unwrap();
|
||||
let fn_mut = tcx.require_lang_item(FnMutTraitLangItem, None);
|
||||
let call_mut = tcx
|
||||
.associated_items(fn_mut)
|
||||
.in_definition_order()
|
||||
|
@ -61,6 +61,7 @@ use crate::util::storage;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::lang_items::{GeneratorStateLangItem, PinTypeLangItem};
|
||||
use rustc_index::bit_set::{BitMatrix, BitSet};
|
||||
use rustc_index::vec::{Idx, IndexVec};
|
||||
use rustc_middle::mir::visit::{MutVisitor, PlaceContext};
|
||||
@ -381,7 +382,7 @@ fn make_generator_state_argument_indirect<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Bo
|
||||
fn make_generator_state_argument_pinned<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||
let ref_gen_ty = body.local_decls.raw[1].ty;
|
||||
|
||||
let pin_did = tcx.lang_items().pin_type().unwrap();
|
||||
let pin_did = tcx.require_lang_item(PinTypeLangItem, None);
|
||||
let pin_adt_ref = tcx.adt_def(pin_did);
|
||||
let substs = tcx.intern_substs(&[ref_gen_ty.into()]);
|
||||
let pin_ref_gen_ty = tcx.mk_adt(pin_adt_ref, substs);
|
||||
@ -1207,7 +1208,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
|
||||
};
|
||||
|
||||
// Compute GeneratorState<yield_ty, return_ty>
|
||||
let state_did = tcx.lang_items().gen_state().unwrap();
|
||||
let state_did = tcx.require_lang_item(GeneratorStateLangItem, None);
|
||||
let state_adt_ref = tcx.adt_def(state_did);
|
||||
let state_substs = tcx.intern_substs(&[yield_ty.into(), body.return_ty().into()]);
|
||||
let ret_ty = tcx.mk_adt(state_adt_ref, state_substs);
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::util::patch::MirPatch;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::lang_items;
|
||||
use rustc_hir::lang_items::{BoxFreeFnLangItem, DropTraitLangItem};
|
||||
use rustc_index::vec::Idx;
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::traits::Reveal;
|
||||
@ -535,7 +535,7 @@ where
|
||||
fn destructor_call_block(&mut self, (succ, unwind): (BasicBlock, Unwind)) -> BasicBlock {
|
||||
debug!("destructor_call_block({:?}, {:?})", self, succ);
|
||||
let tcx = self.tcx();
|
||||
let drop_trait = tcx.lang_items().drop_trait().unwrap();
|
||||
let drop_trait = tcx.require_lang_item(DropTraitLangItem, None);
|
||||
let drop_fn = tcx.associated_items(drop_trait).in_definition_order().next().unwrap();
|
||||
let ty = self.place_ty(self.place);
|
||||
let substs = tcx.mk_substs_trait(ty, &[]);
|
||||
@ -877,8 +877,7 @@ where
|
||||
) -> BasicBlock {
|
||||
let tcx = self.tcx();
|
||||
let unit_temp = Place::from(self.new_temp(tcx.mk_unit()));
|
||||
let free_func =
|
||||
tcx.require_lang_item(lang_items::BoxFreeFnLangItem, Some(self.source_info.span));
|
||||
let free_func = tcx.require_lang_item(BoxFreeFnLangItem, Some(self.source_info.span));
|
||||
let args = adt.variants[VariantIdx::new(0)]
|
||||
.fields
|
||||
.iter()
|
||||
|
@ -1,4 +1,5 @@
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::lang_items::EqTraitLangItem;
|
||||
use rustc_index::vec::Idx;
|
||||
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
|
||||
use rustc_middle::mir::Field;
|
||||
@ -140,7 +141,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
|
||||
// code at the moment, because types like `for <'a> fn(&'a ())` do
|
||||
// not *yet* implement `PartialEq`. So for now we leave this here.
|
||||
let ty_is_partial_eq: bool = {
|
||||
let partial_eq_trait_id = self.tcx().lang_items().eq_trait().unwrap();
|
||||
let partial_eq_trait_id = self.tcx().require_lang_item(EqTraitLangItem, None);
|
||||
let obligation: PredicateObligation<'_> = predicate_for_trait_def(
|
||||
self.tcx(),
|
||||
self.param_env,
|
||||
|
@ -20,6 +20,7 @@ use crate::traits::error_reporting::InferCtxtExt;
|
||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||
use rustc_errors::ErrorReported;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::lang_items::{FnOnceTraitLangItem, GeneratorTraitLangItem};
|
||||
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder};
|
||||
use rustc_middle::ty::subst::{InternalSubsts, Subst};
|
||||
use rustc_middle::ty::{self, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, WithConstness};
|
||||
@ -1222,7 +1223,7 @@ fn confirm_generator_candidate<'cx, 'tcx>(
|
||||
|
||||
let tcx = selcx.tcx();
|
||||
|
||||
let gen_def_id = tcx.lang_items().gen_trait().unwrap();
|
||||
let gen_def_id = tcx.require_lang_item(GeneratorTraitLangItem, None);
|
||||
|
||||
let predicate = super::util::generator_trait_ref_and_outputs(
|
||||
tcx,
|
||||
@ -1309,7 +1310,7 @@ fn confirm_callable_candidate<'cx, 'tcx>(
|
||||
debug!("confirm_callable_candidate({:?},{:?})", obligation, fn_sig);
|
||||
|
||||
// the `Output` associated type is declared on `FnOnce`
|
||||
let fn_once_def_id = tcx.lang_items().fn_once_trait().unwrap();
|
||||
let fn_once_def_id = tcx.require_lang_item(FnOnceTraitLangItem, None);
|
||||
|
||||
let predicate = super::util::closure_trait_ref_and_return_type(
|
||||
tcx,
|
||||
|
Loading…
Reference in New Issue
Block a user