Skip to content

Commit ba518ff

Browse files
committed
Use associated_item_def_ids more
1 parent 3ea84e8 commit ba518ff

File tree

7 files changed

+16
-34
lines changed

7 files changed

+16
-34
lines changed

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1704,13 +1704,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
17041704
if let ty::Opaque(def_id, substs) = ty.kind() {
17051705
let future_trait = self.tcx.require_lang_item(LangItem::Future, None);
17061706
// Future::Output
1707-
let item_def_id = self
1708-
.tcx
1709-
.associated_items(future_trait)
1710-
.in_definition_order()
1711-
.next()
1712-
.unwrap()
1713-
.def_id;
1707+
let item_def_id = self.tcx.associated_item_def_ids(future_trait)[0];
17141708

17151709
let bounds = self.tcx.explicit_item_bounds(*def_id);
17161710

compiler/rustc_middle/src/ty/sty.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2086,10 +2086,10 @@ impl<'tcx> TyS<'tcx> {
20862086
ty::Generator(_, substs, _) => substs.as_generator().discr_ty(tcx),
20872087

20882088
ty::Param(_) | ty::Projection(_) | ty::Opaque(..) | ty::Infer(ty::TyVar(_)) => {
2089-
let assoc_items =
2090-
tcx.associated_items(tcx.lang_items().discriminant_kind_trait().unwrap());
2091-
let discriminant_def_id = assoc_items.in_definition_order().next().unwrap().def_id;
2092-
tcx.mk_projection(discriminant_def_id, tcx.mk_substs([self.into()].iter()))
2089+
let assoc_items = tcx.associated_item_def_ids(
2090+
tcx.require_lang_item(hir::LangItem::DiscriminantKind, None),
2091+
);
2092+
tcx.mk_projection(assoc_items[0], tcx.intern_substs(&[self.into()]))
20932093
}
20942094

20952095
ty::Bool

compiler/rustc_middle/src/ty/util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,9 @@ impl<'tcx> TyCtxt<'tcx> {
325325

326326
let ty = self.type_of(adt_did);
327327
let (did, constness) = self.find_map_relevant_impl(drop_trait, ty, |impl_did| {
328-
if let Some(item) = self.associated_items(impl_did).in_definition_order().next() {
328+
if let Some(item_id) = self.associated_item_def_ids(impl_did).first() {
329329
if validate(self, impl_did).is_ok() {
330-
return Some((item.def_id, self.impl_constness(impl_did)));
330+
return Some((*item_id, self.impl_constness(impl_did)));
331331
}
332332
}
333333
None

compiler/rustc_mir_dataflow/src/elaborate_drops.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ where
604604
debug!("destructor_call_block({:?}, {:?})", self, succ);
605605
let tcx = self.tcx();
606606
let drop_trait = tcx.require_lang_item(LangItem::Drop, None);
607-
let drop_fn = tcx.associated_items(drop_trait).in_definition_order().next().unwrap();
607+
let drop_fn = tcx.associated_item_def_ids(drop_trait)[0];
608608
let ty = self.place_ty(self.place);
609609
let substs = tcx.mk_substs_trait(ty, &[]);
610610

@@ -624,12 +624,7 @@ where
624624
)],
625625
terminator: Some(Terminator {
626626
kind: TerminatorKind::Call {
627-
func: Operand::function_handle(
628-
tcx,
629-
drop_fn.def_id,
630-
substs,
631-
self.source_info.span,
632-
),
627+
func: Operand::function_handle(tcx, drop_fn, substs, self.source_info.span),
633628
args: vec![Operand::Move(Place::from(ref_place))],
634629
destination: Some((unit_temp, succ)),
635630
cleanup: unwind.into_option(),

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -2471,13 +2471,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
24712471
obligation.param_env,
24722472
);
24732473

2474-
let item_def_id = self
2475-
.tcx
2476-
.associated_items(future_trait)
2477-
.in_definition_order()
2478-
.next()
2479-
.unwrap()
2480-
.def_id;
2474+
let item_def_id = self.tcx.associated_item_def_ids(future_trait)[0];
24812475
// `<T as Future>::Output`
24822476
let projection_ty = ty::ProjectionTy {
24832477
// `T`

compiler/rustc_typeck/src/check/closure.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
257257
if is_gen {
258258
// Check that we deduce the signature from the `<_ as std::ops::Generator>::Return`
259259
// associated item and not yield.
260-
let return_assoc_item =
261-
self.tcx.associated_items(gen_trait).in_definition_order().nth(1).unwrap().def_id;
260+
let return_assoc_item = self.tcx.associated_item_def_ids(gen_trait)[1];
262261
if return_assoc_item != projection.projection_def_id() {
263262
debug!("deduce_sig_from_projection: not return assoc item of generator");
264263
return None;
@@ -694,8 +693,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
694693

695694
// The `Future` trait has only one associted item, `Output`,
696695
// so check that this is what we see.
697-
let output_assoc_item =
698-
self.tcx.associated_items(future_trait).in_definition_order().next().unwrap().def_id;
696+
let output_assoc_item = self.tcx.associated_item_def_ids(future_trait)[0];
699697
if output_assoc_item != predicate.projection_ty.item_def_id {
700698
span_bug!(
701699
cause_span,

compiler/rustc_typeck/src/check/intrinsic.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,10 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
324324
sym::unlikely => (0, vec![tcx.types.bool], tcx.types.bool),
325325

326326
sym::discriminant_value => {
327-
let assoc_items =
328-
tcx.associated_items(tcx.lang_items().discriminant_kind_trait().unwrap());
329-
let discriminant_def_id = assoc_items.in_definition_order().next().unwrap().def_id;
327+
let assoc_items = tcx.associated_item_def_ids(
328+
tcx.require_lang_item(hir::LangItem::DiscriminantKind, None),
329+
);
330+
let discriminant_def_id = assoc_items[0];
330331

331332
let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(0) };
332333
(

0 commit comments

Comments
 (0)