Skip to content

Commit cbebdcc

Browse files
committed
remove AliasTy::def_id()
1 parent 98594f4 commit cbebdcc

39 files changed

Lines changed: 309 additions & 205 deletions

File tree

compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ pub(crate) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
8383

8484
for trait_projection in collector.types.into_iter().rev() {
8585
let impl_opaque_args = trait_projection.args.rebase_onto(tcx, trait_m.def_id, impl_m_args);
86-
let hidden_ty = hidden_tys[&trait_projection.kind.def_id()]
87-
.instantiate(tcx, impl_opaque_args)
88-
.skip_norm_wip();
86+
let hidden_ty =
87+
hidden_tys[&trait_projection.kind].instantiate(tcx, impl_opaque_args).skip_norm_wip();
8988

9089
// If the hidden type is not an opaque, then we have "refined" the trait signature.
91-
let ty::Alias(
92-
impl_opaque @ ty::AliasTy { kind: ty::Opaque { def_id: impl_opaque_def_id }, .. },
93-
) = *hidden_ty.kind()
94-
else {
90+
let impl_opaque = if let ty::Alias(alias) = *hidden_ty.kind()
91+
&& let Some(impl_opaque) = alias.try_to_opaque()
92+
{
93+
impl_opaque
94+
} else {
9595
report_mismatched_rpitit_signature(
9696
tcx,
9797
trait_m_sig_with_self_for_diag,
@@ -105,7 +105,7 @@ pub(crate) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
105105

106106
// This opaque also needs to be from the impl method -- otherwise,
107107
// it's a refinement to a TAIT.
108-
if !tcx.hir_get_if_local(impl_opaque_def_id).is_some_and(|node| {
108+
if !tcx.hir_get_if_local(impl_opaque.kind).is_some_and(|node| {
109109
matches!(
110110
node.expect_opaque_ty().origin,
111111
hir::OpaqueTyOrigin::AsyncFn { parent, .. } | hir::OpaqueTyOrigin::FnReturn { parent, .. }
@@ -124,13 +124,13 @@ pub(crate) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
124124
}
125125

126126
trait_bounds.extend(
127-
tcx.item_bounds(trait_projection.kind.def_id())
127+
tcx.item_bounds(trait_projection.kind)
128128
.iter_instantiated(tcx, trait_projection.args)
129129
.map(Unnormalized::skip_norm_wip),
130130
);
131131
impl_bounds.extend(elaborate(
132132
tcx,
133-
tcx.explicit_item_bounds(impl_opaque_def_id)
133+
tcx.explicit_item_bounds(impl_opaque.kind)
134134
.iter_instantiated_copied(tcx, impl_opaque.args)
135135
.map(Unnormalized::skip_norm_wip),
136136
));
@@ -231,7 +231,7 @@ pub(crate) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
231231
// is literally unrepresentable in the type system; however, we may be
232232
// promising stronger outlives guarantees if we capture *fewer* regions.
233233
for (trait_projection, impl_opaque) in pairs {
234-
let impl_variances = tcx.variances_of(impl_opaque.kind.def_id());
234+
let impl_variances = tcx.variances_of(impl_opaque.kind);
235235
let impl_captures: FxIndexSet<_> = impl_opaque
236236
.args
237237
.iter()
@@ -240,7 +240,7 @@ pub(crate) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
240240
.map(|(arg, _)| arg)
241241
.collect();
242242

243-
let trait_variances = tcx.variances_of(trait_projection.kind.def_id());
243+
let trait_variances = tcx.variances_of(trait_projection.kind);
244244
let mut trait_captures = FxIndexSet::default();
245245
for (arg, variance) in trait_projection.args.iter().zip_eq(trait_variances) {
246246
if *variance != ty::Invariant {
@@ -252,7 +252,7 @@ pub(crate) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
252252
if !trait_captures.iter().all(|arg| impl_captures.contains(arg)) {
253253
report_mismatched_rpitit_captures(
254254
tcx,
255-
impl_opaque.kind.def_id().expect_local(),
255+
impl_opaque.kind.expect_local(),
256256
trait_captures,
257257
is_internal,
258258
);
@@ -262,18 +262,19 @@ pub(crate) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
262262

263263
struct ImplTraitInTraitCollector<'tcx> {
264264
tcx: TyCtxt<'tcx>,
265-
types: FxIndexSet<ty::AliasTy<'tcx>>,
265+
types: FxIndexSet<ty::ProjectionAliasTy<'tcx>>,
266266
}
267267

268268
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'tcx> {
269269
fn visit_ty(&mut self, ty: Ty<'tcx>) {
270-
if let ty::Alias(proj @ ty::AliasTy { kind: ty::Projection { def_id }, .. }) = *ty.kind()
271-
&& self.tcx.is_impl_trait_in_trait(def_id)
270+
if let ty::Alias(alias) = *ty.kind()
271+
&& let Some(proj) = alias.try_to_projection()
272+
&& self.tcx.is_impl_trait_in_trait(proj.kind)
272273
{
273274
if self.types.insert(proj) {
274275
for (pred, _) in self
275276
.tcx
276-
.explicit_item_bounds(def_id)
277+
.explicit_item_bounds(proj.kind)
277278
.iter_instantiated_copied(self.tcx, proj.args)
278279
.map(Unnormalized::skip_norm_wip)
279280
{

compiler/rustc_hir_analysis/src/check/mod.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ use rustc_middle::ty::error::{ExpectedFound, TypeError};
8989
use rustc_middle::ty::print::with_types_for_signature;
9090
use rustc_middle::ty::{
9191
self, GenericArgs, GenericArgsRef, OutlivesPredicate, Region, Ty, TyCtxt, TypingMode,
92-
Unnormalized,
9392
};
9493
use rustc_middle::{bug, span_bug};
9594
use rustc_session::errors::feature_err;
@@ -487,21 +486,12 @@ fn fn_sig_suggestion<'tcx>(
487486
let mut output = sig.output();
488487

489488
let asyncness = if tcx.asyncness(assoc.def_id).is_async() {
490-
output = if let ty::Alias(alias_ty) = *output.kind()
491-
&& let Some(output) = tcx
492-
.explicit_item_self_bounds(alias_ty.kind.def_id())
493-
.iter_instantiated_copied(tcx, alias_ty.args)
494-
.map(Unnormalized::skip_norm_wip)
495-
.find_map(|(bound, _)| {
496-
bound.as_projection_clause()?.no_bound_vars()?.term.as_type()
497-
}) {
498-
output
499-
} else {
489+
output = tcx.get_impl_future_output_ty(output).unwrap_or_else(|| {
500490
span_bug!(
501491
ident.span,
502492
"expected async fn to have `impl Future` output, but it returns {output}"
503493
)
504-
};
494+
});
505495
"async "
506496
} else {
507497
""

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
13591359
)? {
13601360
TypeRelativePath::AssocItem(alias_term) => {
13611361
let alias_ty = alias_term.expect_ty();
1362-
let def_id = alias_ty.kind.def_id();
1362+
let def_id = match alias_ty.kind {
1363+
ty::AliasTyKind::Projection { def_id } => def_id,
1364+
ty::AliasTyKind::Inherent { def_id } => def_id,
1365+
kind => bug!("expected projection or inherent alias, got {kind:?}"),
1366+
};
13631367
let ty = alias_ty.to_ty(tcx);
13641368
let ty = self.check_param_uses_if_mcg(ty, span, false);
13651369
Ok((ty, tcx.def_kind(def_id), def_id))

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2910,7 +2910,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
29102910
base: &'tcx hir::Expr<'tcx>,
29112911
ty: Ty<'tcx>,
29122912
) {
2913-
let Some(output_ty) = self.err_ctxt().get_impl_future_output_ty(ty) else {
2913+
let Some(output_ty) = self.tcx.get_impl_future_output_ty(ty) else {
29142914
err.span_label(field_ident.span, "unknown field");
29152915
return;
29162916
};

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13511351
.instantiate_bound_regions_with_erased(Binder::bind_with_vars(ty, bound_vars));
13521352
let ty = match self.tcx.asyncness(fn_id) {
13531353
ty::Asyncness::Yes => {
1354-
self.err_ctxt().get_impl_future_output_ty(ty).unwrap_or_else(|| {
1354+
self.tcx.get_impl_future_output_ty(ty).unwrap_or_else(|| {
13551355
span_bug!(
13561356
fn_decl.output.span(),
13571357
"failed to get output type of async function"

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3878,7 +3878,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
38783878
span: Span,
38793879
return_type: Option<Ty<'tcx>>,
38803880
) {
3881-
let Some(output_ty) = self.err_ctxt().get_impl_future_output_ty(ty) else { return };
3881+
let Some(output_ty) = self.tcx.get_impl_future_output_ty(ty) else { return };
38823882
let output_ty = self.resolve_vars_if_possible(output_ty);
38833883
let method_exists =
38843884
self.method_exists_for_diagnostic(item_name, output_ty, call.hir_id, return_type);

compiler/rustc_infer/src/infer/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ impl<'tcx> rustc_type_ir::InferCtxtLike for InferCtxt<'tcx> {
380380
.map(|(k, h)| (k, h.ty))
381381
.collect()
382382
}
383-
fn opaques_with_sub_unified_hidden_type(&self, ty: ty::TyVid) -> Vec<ty::AliasTy<'tcx>> {
383+
fn opaques_with_sub_unified_hidden_type(&self, ty: ty::TyVid) -> Vec<ty::OpaqueAliasTy<'tcx>> {
384384
self.opaques_with_sub_unified_hidden_type(ty)
385385
}
386386

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,10 @@ impl<'tcx> InferCtxt<'tcx> {
11111111
/// Searches for an opaque type key whose hidden type is related to `ty_vid`.
11121112
///
11131113
/// This only checks for a subtype relation, it does not require equality.
1114-
pub fn opaques_with_sub_unified_hidden_type(&self, ty_vid: TyVid) -> Vec<ty::AliasTy<'tcx>> {
1114+
pub fn opaques_with_sub_unified_hidden_type(
1115+
&self,
1116+
ty_vid: TyVid,
1117+
) -> Vec<ty::OpaqueAliasTy<'tcx>> {
11151118
// Avoid accidentally allowing more code to compile with the old solver.
11161119
if !self.next_trait_solver() {
11171120
return vec![];
@@ -1129,11 +1132,15 @@ impl<'tcx> InferCtxt<'tcx> {
11291132
if let ty::Infer(ty::TyVar(hidden_vid)) = *hidden_ty.ty.kind() {
11301133
let opaque_sub_vid = type_variables.sub_unification_table_root_var(hidden_vid);
11311134
if opaque_sub_vid == ty_sub_vid {
1132-
return Some(ty::AliasTy::new_from_args(
1133-
self.tcx,
1134-
ty::Opaque { def_id: key.def_id.into() },
1135-
key.args,
1136-
));
1135+
return Some(
1136+
ty::AliasTy::new_from_args(
1137+
self.tcx,
1138+
ty::Opaque { def_id: key.def_id.into() },
1139+
key.args,
1140+
)
1141+
.try_to_opaque()
1142+
.unwrap(),
1143+
);
11371144
}
11381145
}
11391146

compiler/rustc_infer/src/infer/outlives/for_liveness.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,14 @@ where
5959
ty::Alias(ty::AliasTy { kind, args, .. }) => {
6060
let tcx = self.tcx;
6161
let param_env = self.param_env;
62+
let def_id = match kind {
63+
ty::AliasTyKind::Projection { def_id }
64+
| ty::AliasTyKind::Inherent { def_id }
65+
| ty::AliasTyKind::Opaque { def_id }
66+
| ty::AliasTyKind::Free { def_id } => def_id,
67+
};
6268
let outlives_bounds: Vec<_> = tcx
63-
.item_bounds(kind.def_id())
69+
.item_bounds(def_id)
6470
.iter_instantiated(tcx, args)
6571
.map(Unnormalized::skip_norm_wip)
6672
.chain(param_env.caller_bounds())

compiler/rustc_infer/src/infer/outlives/verify.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
236236
// And therefore we can safely use structural equality for alias types.
237237
(GenericKind::Param(p1), ty::Param(p2)) if p1 == p2 => {}
238238
(GenericKind::Placeholder(p1), ty::Placeholder(p2)) if p1 == p2 => {}
239-
(GenericKind::Alias(a1), ty::Alias(a2)) if a1.kind.def_id() == a2.kind.def_id() => {
240-
}
239+
(GenericKind::Alias(a1), ty::Alias(a2)) if a1.kind == a2.kind => {}
241240
_ => return None,
242241
}
243242

0 commit comments

Comments
 (0)