1
Fork 0

Use associated_item_def_ids more

This commit is contained in:
Matthew Jasper 2021-11-05 18:47:52 +00:00
parent 3ea84e879a
commit ba518ffdd3
7 changed files with 16 additions and 34 deletions

View file

@ -1704,13 +1704,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
if let ty::Opaque(def_id, substs) = ty.kind() { if let ty::Opaque(def_id, substs) = ty.kind() {
let future_trait = self.tcx.require_lang_item(LangItem::Future, None); let future_trait = self.tcx.require_lang_item(LangItem::Future, None);
// Future::Output // Future::Output
let item_def_id = self let item_def_id = self.tcx.associated_item_def_ids(future_trait)[0];
.tcx
.associated_items(future_trait)
.in_definition_order()
.next()
.unwrap()
.def_id;
let bounds = self.tcx.explicit_item_bounds(*def_id); let bounds = self.tcx.explicit_item_bounds(*def_id);

View file

@ -2086,10 +2086,10 @@ impl<'tcx> TyS<'tcx> {
ty::Generator(_, substs, _) => substs.as_generator().discr_ty(tcx), ty::Generator(_, substs, _) => substs.as_generator().discr_ty(tcx),
ty::Param(_) | ty::Projection(_) | ty::Opaque(..) | ty::Infer(ty::TyVar(_)) => { ty::Param(_) | ty::Projection(_) | ty::Opaque(..) | ty::Infer(ty::TyVar(_)) => {
let assoc_items = let assoc_items = tcx.associated_item_def_ids(
tcx.associated_items(tcx.lang_items().discriminant_kind_trait().unwrap()); tcx.require_lang_item(hir::LangItem::DiscriminantKind, None),
let discriminant_def_id = assoc_items.in_definition_order().next().unwrap().def_id; );
tcx.mk_projection(discriminant_def_id, tcx.mk_substs([self.into()].iter())) tcx.mk_projection(assoc_items[0], tcx.intern_substs(&[self.into()]))
} }
ty::Bool ty::Bool

View file

@ -325,9 +325,9 @@ impl<'tcx> TyCtxt<'tcx> {
let ty = self.type_of(adt_did); let ty = self.type_of(adt_did);
let (did, constness) = self.find_map_relevant_impl(drop_trait, ty, |impl_did| { let (did, constness) = self.find_map_relevant_impl(drop_trait, ty, |impl_did| {
if let Some(item) = self.associated_items(impl_did).in_definition_order().next() { if let Some(item_id) = self.associated_item_def_ids(impl_did).first() {
if validate(self, impl_did).is_ok() { if validate(self, impl_did).is_ok() {
return Some((item.def_id, self.impl_constness(impl_did))); return Some((*item_id, self.impl_constness(impl_did)));
} }
} }
None None

View file

@ -604,7 +604,7 @@ where
debug!("destructor_call_block({:?}, {:?})", self, succ); debug!("destructor_call_block({:?}, {:?})", self, succ);
let tcx = self.tcx(); let tcx = self.tcx();
let drop_trait = tcx.require_lang_item(LangItem::Drop, None); let drop_trait = tcx.require_lang_item(LangItem::Drop, None);
let drop_fn = tcx.associated_items(drop_trait).in_definition_order().next().unwrap(); let drop_fn = tcx.associated_item_def_ids(drop_trait)[0];
let ty = self.place_ty(self.place); let ty = self.place_ty(self.place);
let substs = tcx.mk_substs_trait(ty, &[]); let substs = tcx.mk_substs_trait(ty, &[]);
@ -624,12 +624,7 @@ where
)], )],
terminator: Some(Terminator { terminator: Some(Terminator {
kind: TerminatorKind::Call { kind: TerminatorKind::Call {
func: Operand::function_handle( func: Operand::function_handle(tcx, drop_fn, substs, self.source_info.span),
tcx,
drop_fn.def_id,
substs,
self.source_info.span,
),
args: vec![Operand::Move(Place::from(ref_place))], args: vec![Operand::Move(Place::from(ref_place))],
destination: Some((unit_temp, succ)), destination: Some((unit_temp, succ)),
cleanup: unwind.into_option(), cleanup: unwind.into_option(),

View file

@ -2471,13 +2471,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
obligation.param_env, obligation.param_env,
); );
let item_def_id = self let item_def_id = self.tcx.associated_item_def_ids(future_trait)[0];
.tcx
.associated_items(future_trait)
.in_definition_order()
.next()
.unwrap()
.def_id;
// `<T as Future>::Output` // `<T as Future>::Output`
let projection_ty = ty::ProjectionTy { let projection_ty = ty::ProjectionTy {
// `T` // `T`

View file

@ -257,8 +257,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if is_gen { if is_gen {
// Check that we deduce the signature from the `<_ as std::ops::Generator>::Return` // Check that we deduce the signature from the `<_ as std::ops::Generator>::Return`
// associated item and not yield. // associated item and not yield.
let return_assoc_item = let return_assoc_item = self.tcx.associated_item_def_ids(gen_trait)[1];
self.tcx.associated_items(gen_trait).in_definition_order().nth(1).unwrap().def_id;
if return_assoc_item != projection.projection_def_id() { if return_assoc_item != projection.projection_def_id() {
debug!("deduce_sig_from_projection: not return assoc item of generator"); debug!("deduce_sig_from_projection: not return assoc item of generator");
return None; return None;
@ -694,8 +693,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// The `Future` trait has only one associted item, `Output`, // The `Future` trait has only one associted item, `Output`,
// so check that this is what we see. // so check that this is what we see.
let output_assoc_item = let output_assoc_item = self.tcx.associated_item_def_ids(future_trait)[0];
self.tcx.associated_items(future_trait).in_definition_order().next().unwrap().def_id;
if output_assoc_item != predicate.projection_ty.item_def_id { if output_assoc_item != predicate.projection_ty.item_def_id {
span_bug!( span_bug!(
cause_span, cause_span,

View file

@ -324,9 +324,10 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
sym::unlikely => (0, vec![tcx.types.bool], tcx.types.bool), sym::unlikely => (0, vec![tcx.types.bool], tcx.types.bool),
sym::discriminant_value => { sym::discriminant_value => {
let assoc_items = let assoc_items = tcx.associated_item_def_ids(
tcx.associated_items(tcx.lang_items().discriminant_kind_trait().unwrap()); tcx.require_lang_item(hir::LangItem::DiscriminantKind, None),
let discriminant_def_id = assoc_items.in_definition_order().next().unwrap().def_id; );
let discriminant_def_id = assoc_items[0];
let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(0) }; let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(0) };
( (