Skip to content

Commit dc0b517

Browse files
committed
remove AliasTerm::def_id()
1 parent d8c2e97 commit dc0b517

33 files changed

Lines changed: 291 additions & 230 deletions

File tree

compiler/rustc_hir_analysis/src/check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,10 @@ fn bounds_from_generic_predicates<'tcx>(
370370
let mut projections_str = vec![];
371371
for projection in &projections {
372372
let p = projection.skip_binder();
373-
if bound == tcx.parent(p.projection_term.def_id())
373+
if bound == p.projection_term.trait_def_id(tcx)
374374
&& p.projection_term.self_ty() == ty
375375
{
376-
let name = tcx.item_name(p.projection_term.def_id());
376+
let name = tcx.item_name(p.projection_term.expect_projection_def_id());
377377
projections_str.push(format!("{} = {}", name, p.term));
378378
}
379379
}

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,10 +1633,8 @@ pub(super) fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, def_id:
16331633
let pred_binder = proj
16341634
.map_bound(|pred| {
16351635
pred.term.as_const().map(|ct| {
1636-
let assoc_const_ty = tcx
1637-
.type_of(pred.projection_term.def_id())
1638-
.instantiate(tcx, pred.projection_term.args)
1639-
.skip_norm_wip();
1636+
let assoc_const_ty =
1637+
pred.projection_term.expect_ct().type_of(tcx).skip_norm_wip();
16401638
ty::ClauseKind::ConstArgHasType(ct, assoc_const_ty)
16411639
})
16421640
})

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,9 +542,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
542542
let term = match term {
543543
hir::Term::Ty(ty) => self.lower_ty(ty).into(),
544544
hir::Term::Const(ct) => {
545-
let ty = projection_term.map_bound(|alias| {
546-
tcx.type_of(alias.def_id()).instantiate(tcx, alias.args).skip_norm_wip()
547-
});
545+
let ty = projection_term
546+
.map_bound(|alias| alias.expect_ct().type_of(tcx).skip_norm_wip());
548547
let ty = check_assoc_const_binding_type(
549548
self,
550549
constraint.ident,

compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
487487
// FIXME(mgca): code duplication with other places we lower
488488
// the rhs' of associated const bindings
489489
let ty = projection_term.map_bound(|alias| {
490-
tcx.type_of(alias.def_id())
491-
.instantiate(tcx, alias.args)
492-
.skip_norm_wip()
490+
alias.expect_ct().type_of(tcx).skip_norm_wip()
493491
});
494492
let ty = super::bounds::check_assoc_const_binding_type(
495493
self,

compiler/rustc_hir_typeck/src/closure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10561056
// The `Future` trait has only one associated item, `Output`,
10571057
// so check that this is what we see.
10581058
let output_assoc_item = self.tcx.associated_item_def_ids(trait_def_id)[0];
1059-
if output_assoc_item != predicate.projection_term.def_id() {
1059+
if output_assoc_item != predicate.def_id() {
10601060
span_bug!(
10611061
cause_span,
10621062
"projecting associated item `{:?}` from future, which is not Output `{:?}`",

compiler/rustc_infer/src/infer/projection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl<'tcx> InferCtxt<'tcx> {
2222
) -> Term<'tcx> {
2323
debug_assert!(!self.next_trait_solver());
2424

25-
let span = self.tcx.def_span(alias_term.def_id());
25+
let span = self.tcx.def_span(alias_term.expect_projection_def_id());
2626
let infer_var = if alias_term.kind.is_type() {
2727
self.next_ty_var(span).into()
2828
} else {

compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
130130
return;
131131
}
132132

133-
let proj_ty = Ty::new_projection_from_args(
134-
cx.tcx,
135-
proj.projection_term.def_id(),
136-
proj.projection_term.args,
137-
);
133+
let proj_ty = proj.projection_term.expect_ty().to_ty(cx.tcx);
138134
// For every instance of the projection type in the bounds,
139135
// replace them with the term we're assigning to the associated
140136
// type in our opaque type.
@@ -149,7 +145,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
149145
// with `impl Send: OtherTrait`.
150146
for (assoc_pred, assoc_pred_span) in cx
151147
.tcx
152-
.explicit_item_bounds(proj.projection_term.def_id())
148+
.explicit_item_bounds(proj.def_id())
153149
.iter_instantiated_copied(cx.tcx, proj.projection_term.args)
154150
.map(Unnormalized::skip_norm_wip)
155151
{

compiler/rustc_middle/src/ty/error.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ impl<'tcx> TypeError<'tcx> {
9898
.into(),
9999
TypeError::ProjectionMismatched(ref values) => format!(
100100
"expected `{}`, found `{}`",
101-
tcx.def_path_str(values.expected),
102-
tcx.def_path_str(values.found)
101+
tcx.alias_term_kind_def_path_str(values.expected),
102+
tcx.alias_term_kind_def_path_str(values.found)
103103
)
104104
.into(),
105105
TypeError::ExistentialMismatch(ref values) => report_maybe_different(
@@ -309,4 +309,17 @@ impl<'tcx> TyCtxt<'tcx> {
309309
Err(_) => regular,
310310
}
311311
}
312+
313+
pub fn alias_term_kind_def_path_str(self, alias: ty::AliasTermKind<'tcx>) -> String {
314+
match alias {
315+
ty::AliasTermKind::ProjectionTy { def_id }
316+
| ty::AliasTermKind::InherentTy { def_id }
317+
| ty::AliasTermKind::OpaqueTy { def_id }
318+
| ty::AliasTermKind::FreeTy { def_id }
319+
| ty::AliasTermKind::AnonConst { def_id }
320+
| ty::AliasTermKind::ProjectionConst { def_id }
321+
| ty::AliasTermKind::FreeConst { def_id }
322+
| ty::AliasTermKind::InherentConst { def_id } => self.def_path_str(def_id),
323+
}
324+
}
312325
}

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,17 +1344,18 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
13441344

13451345
fn pretty_print_inherent_projection(
13461346
&mut self,
1347-
alias_ty: ty::AliasTerm<'tcx>,
1347+
alias_term: ty::AliasTerm<'tcx>,
13481348
) -> Result<(), PrintError> {
1349-
let def_key = self.tcx().def_key(alias_ty.def_id());
1349+
let alias_def_id = alias_term.expect_inherent_def_id();
1350+
let def_key = self.tcx().def_key(alias_def_id);
13501351
self.print_path_with_generic_args(
13511352
|p| {
13521353
p.print_path_with_simple(
1353-
|p| p.print_path_with_qualified(alias_ty.self_ty(), None),
1354+
|p| p.print_path_with_qualified(alias_term.self_ty(), None),
13541355
&def_key.disambiguated_data,
13551356
)
13561357
},
1357-
&alias_ty.args[1..],
1358+
&alias_term.args[1..],
13581359
)
13591360
}
13601361

@@ -3157,7 +3158,9 @@ define_print! {
31573158

31583159
ty::AliasTerm<'tcx> {
31593160
match self.kind {
3160-
ty::AliasTermKind::InherentTy {..} | ty::AliasTermKind::InherentConst {..} => p.pretty_print_inherent_projection(*self)?,
3161+
ty::AliasTermKind::InherentTy { .. } | ty::AliasTermKind::InherentConst { .. } => {
3162+
p.pretty_print_inherent_projection(*self)?;
3163+
}
31613164
ty::AliasTermKind::ProjectionTy { def_id } => {
31623165
if !(p.should_print_verbose() || with_reduced_queries())
31633166
&& p.tcx().is_impl_trait_in_trait(def_id)

compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -925,10 +925,7 @@ where
925925
// show up in the bounds, but just ones that come from substituting
926926
// `Self` with the dyn type.
927927
let proj = proj.with_self_ty(cx, trait_ref.self_ty());
928-
replace_projection_with
929-
.entry(proj.def_id().into())
930-
.or_default()
931-
.push(bound.rebind(proj));
928+
replace_projection_with.entry(proj.def_id()).or_default().push(bound.rebind(proj));
932929
}
933930
}
934931

@@ -952,7 +949,7 @@ struct ReplaceProjectionWith<'a, 'b, I: Interner, D: SolverDelegate<Interner = I
952949
ecx: &'a mut EvalCtxt<'b, D>,
953950
param_env: I::ParamEnv,
954951
self_ty: I::Ty,
955-
mapping: &'a HashMap<I::DefId, Vec<ty::Binder<I, ty::ProjectionPredicate<I>>>>,
952+
mapping: &'a HashMap<I::TraitAssocTermId, Vec<ty::Binder<I, ty::ProjectionPredicate<I>>>>,
956953
nested: Vec<Goal<I, I::Predicate>>,
957954
}
958955

@@ -966,7 +963,7 @@ where
966963
source_projection: ty::Binder<I, ty::ProjectionPredicate<I>>,
967964
target_projection: ty::AliasTerm<I>,
968965
) -> bool {
969-
source_projection.item_def_id() == target_projection.def_id()
966+
source_projection.item_def_id() == target_projection.expect_projection_def_id()
970967
&& self
971968
.ecx
972969
.probe(|_| ProbeKind::ProjectionCompatibility)
@@ -990,7 +987,7 @@ where
990987
return Ok(None);
991988
}
992989

993-
let Some(replacements) = self.mapping.get(&alias_term.def_id()) else {
990+
let Some(replacements) = self.mapping.get(&alias_term.expect_projection_def_id()) else {
994991
return Ok(None);
995992
};
996993

0 commit comments

Comments
 (0)