Skip to content

Commit b053550

Browse files
committed
Auto merge of #90827 - matthewjasper:assoc-item-cleanup-2, r=cjgillot
Assoc item cleanup Part 2 - Remove `AssocItem` from `RegionVariableOrigin::AutoRef` - Use the `associated_item_def_ids` query instead of the `associated_items` query when possible The change to `ObligationCauseCode` from #90639 is omitted because it caused a perf regression. r? `@cjgillot`
2 parents 891ca5f + ba518ff commit b053550

File tree

9 files changed

+20
-38
lines changed

9 files changed

+20
-38
lines changed

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

+2-8
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

@@ -2528,7 +2522,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
25282522
infer::MiscVariable(_) => String::new(),
25292523
infer::PatternRegion(_) => " for pattern".to_string(),
25302524
infer::AddrOfRegion(_) => " for borrow expression".to_string(),
2531-
infer::Autoref(_, _) => " for autoref".to_string(),
2525+
infer::Autoref(_) => " for autoref".to_string(),
25322526
infer::Coercion(_) => " for automatic coercion".to_string(),
25332527
infer::LateBoundRegion(_, br, infer::FnCall) => {
25342528
format!(" for lifetime parameter {}in function call", br_string(br))

compiler/rustc_infer/src/infer/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ pub enum RegionVariableOrigin {
459459
AddrOfRegion(Span),
460460

461461
/// Regions created as part of an autoref of a method receiver
462-
Autoref(Span, ty::AssocItem),
462+
Autoref(Span),
463463

464464
/// Regions created as part of an automatic coercion
465465
Coercion(Span),
@@ -1848,7 +1848,7 @@ impl RegionVariableOrigin {
18481848
MiscVariable(a)
18491849
| PatternRegion(a)
18501850
| AddrOfRegion(a)
1851-
| Autoref(a, _)
1851+
| Autoref(a)
18521852
| Coercion(a)
18531853
| EarlyBoundRegion(a, ..)
18541854
| LateBoundRegion(a, ..)

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
(

compiler/rustc_typeck/src/check/method/confirm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
162162

163163
match &pick.autoref_or_ptr_adjustment {
164164
Some(probe::AutorefOrPtrAdjustment::Autoref { mutbl, unsize }) => {
165-
let region = self.next_region_var(infer::Autoref(self.span, pick.item));
165+
let region = self.next_region_var(infer::Autoref(self.span));
166166
target = self.tcx.mk_ref(region, ty::TypeAndMut { mutbl: *mutbl, ty: target });
167167
let mutbl = match mutbl {
168168
hir::Mutability::Not => AutoBorrowMutability::Not,

0 commit comments

Comments
 (0)