Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions compiler/rustc_borrowck/src/diagnostics/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,11 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for FindOpaqueRegion<'_, 'tcx> {
fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result {
// If we find an opaque in a local ty, then for each of its captured regions,
// try to find a path between that captured regions and our borrow region...
if let ty::Alias(ty::Opaque, opaque) = *ty.kind()
if let ty::Alias(opaque @ ty::AliasTy { kind: ty::Opaque { def_id }, .. }) = *ty.kind()
&& let hir::OpaqueTyOrigin::FnReturn { parent, in_trait_or_impl: None } =
self.tcx.opaque_ty_origin(opaque.def_id)
self.tcx.opaque_ty_origin(def_id)
{
let variances = self.tcx.variances_of(opaque.def_id);
let variances = self.tcx.variances_of(def_id);
for (idx, (arg, variance)) in std::iter::zip(opaque.args, variances).enumerate() {
// Skip uncaptured args.
if *variance == ty::Bivariant {
Expand Down Expand Up @@ -252,7 +252,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for FindOpaqueRegion<'_, 'tcx> {
&& call_def_id == parent
&& let Locations::Single(location) = constraint.locations
{
return ControlFlow::Break((opaque.def_id, idx, location));
return ControlFlow::Break((def_id, idx, location));
}
}
}
Expand All @@ -276,11 +276,11 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for CheckExplicitRegionMentionAndCollectGen

fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result {
match *ty.kind() {
ty::Alias(ty::Opaque, opaque) => {
if self.seen_opaques.insert(opaque.def_id) {
ty::Alias(opaque @ ty::AliasTy { kind: ty::Opaque { def_id }, .. }) => {
if self.seen_opaques.insert(def_id) {
for (bound, _) in self
.tcx
.explicit_item_bounds(opaque.def_id)
.explicit_item_bounds(def_id)
.iter_instantiated_copied(self.tcx, opaque.args)
{
bound.visit_with(self)?;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
let ErrorConstraintInfo { outlived_fr, span, .. } = errci;

let mut output_ty = self.regioncx.universal_regions().unnormalized_output_ty;
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *output_ty.kind() {
if let ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }) = *output_ty.kind() {
output_ty = self.infcx.tcx.type_of(def_id).instantiate_identity()
};

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1899,7 +1899,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
| ty::Never
| ty::Tuple(_)
| ty::UnsafeBinder(_)
| ty::Alias(_, _)
| ty::Alias(_)
| ty::Param(_)
| ty::Bound(_, _)
| ty::Infer(_)
Expand Down Expand Up @@ -1941,7 +1941,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
| ty::CoroutineWitness(..)
| ty::Never
| ty::UnsafeBinder(_)
| ty::Alias(_, _)
| ty::Alias(_)
| ty::Param(_)
| ty::Bound(_, _)
| ty::Infer(_)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for CollectMemberConstraintsVisitor<'_, '_,
| ty::CoroutineClosure(def_id, args)
| ty::Coroutine(def_id, args) => self.visit_closure_args(def_id, args),

ty::Alias(kind, ty::AliasTy { def_id, args, .. })
if let Some(variances) = self.cx().opt_alias_variances(kind, def_id) =>
ty::Alias(ty::AliasTy { kind, args, .. })
if let Some(variances) = self.cx().opt_alias_variances(kind, kind.def_id()) =>
{
// Skip lifetime parameters that are not captured, since they do
// not need member constraints registered for them; we'll erase
Expand Down
20 changes: 11 additions & 9 deletions compiler/rustc_borrowck/src/region_infer/opaque_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,10 @@ fn compute_definition_site_hidden_types_from_defining_uses<'tcx>(
// usage of the opaque type and we can ignore it. This check is mirrored in typeck's
// writeback.
if !rcx.infcx.tcx.use_typing_mode_borrowck() {
if let ty::Alias(ty::Opaque, alias_ty) = hidden_type.ty.skip_binder().kind()
&& alias_ty.def_id == opaque_type_key.def_id.to_def_id()
&& alias_ty.args == opaque_type_key.args
if let &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) =
hidden_type.ty.skip_binder().kind()
&& def_id == opaque_type_key.def_id.to_def_id()
&& args == opaque_type_key.args
{
continue;
}
Expand Down Expand Up @@ -499,8 +500,8 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for ToArgRegionsFolder<'_, 'tcx> {
Ty::new_coroutine(tcx, def_id, self.fold_closure_args(def_id, args)?)
}

ty::Alias(kind, ty::AliasTy { def_id, args, .. })
if let Some(variances) = tcx.opt_alias_variances(kind, def_id) =>
ty::Alias(ty::AliasTy { kind, args, .. })
if let Some(variances) = tcx.opt_alias_variances(kind, kind.def_id()) =>
{
let args = tcx.mk_args_from_iter(std::iter::zip(variances, args.iter()).map(
|(&v, s)| {
Expand All @@ -511,7 +512,7 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for ToArgRegionsFolder<'_, 'tcx> {
}
},
))?;
ty::AliasTy::new_from_args(tcx, def_id, args).to_ty(tcx)
ty::AliasTy::new_from_args(tcx, kind, args).to_ty(tcx)
}

_ => ty.try_super_fold_with(self)?,
Expand Down Expand Up @@ -540,9 +541,10 @@ pub(crate) fn apply_definition_site_hidden_types<'tcx>(
for &(key, hidden_type) in opaque_types {
let Some(expected) = hidden_types.get(&key.def_id) else {
if !tcx.use_typing_mode_borrowck() {
if let ty::Alias(ty::Opaque, alias_ty) = hidden_type.ty.kind()
&& alias_ty.def_id == key.def_id.to_def_id()
&& alias_ty.args == key.args
if let &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) =
hidden_type.ty.kind()
&& def_id == key.def_id.to_def_id()
&& args == key.args
{
continue;
} else {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// Necessary for non-trivial patterns whose user-type annotation is an opaque type,
// e.g. `let (_a,): Tait = whatever`, see #105897
if !self.infcx.next_trait_solver()
&& let ty::Alias(ty::Opaque, ..) = curr_projected_ty.ty.kind()
&& let ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) =
curr_projected_ty.ty.kind()
{
// There is nothing that we can compare here if we go through an opaque type.
// We're always in its defining scope as we can otherwise not project through
Expand Down
16 changes: 10 additions & 6 deletions compiler/rustc_borrowck/src/type_check/relate_tys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,12 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
};

let (a, b) = match (a.kind(), b.kind()) {
(&ty::Alias(ty::Opaque, ..), _) => (a, enable_subtyping(b, true)?),
(_, &ty::Alias(ty::Opaque, ..)) => (enable_subtyping(a, false)?, b),
(&ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }), _) => {
(a, enable_subtyping(b, true)?)
}
(_, &ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. })) => {
(enable_subtyping(a, false)?, b)
}
_ => unreachable!(
"expected at least one opaque type in `relate_opaques`, got {a} and {b}."
),
Expand Down Expand Up @@ -382,8 +386,8 @@ impl<'b, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'b, 'tcx> {
}

(
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, .. }),
&ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }),
&ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: a_def_id }, .. }),
&ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: b_def_id }, .. }),
) if a_def_id == b_def_id || infcx.next_trait_solver() => {
super_combine_tys(&infcx.infcx, self, a, b).map(|_| ()).or_else(|err| {
// This behavior is only there for the old solver, the new solver
Expand All @@ -397,8 +401,8 @@ impl<'b, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'b, 'tcx> {
if a_def_id.is_local() { self.relate_opaques(a, b) } else { Err(err) }
})?;
}
(&ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), _)
| (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }))
(&ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }), _)
| (_, &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }))
if def_id.is_local() && !self.type_checker.infcx.next_trait_solver() =>
{
self.relate_opaques(a, b)?;
Expand Down
14 changes: 11 additions & 3 deletions compiler/rustc_const_eval/src/util/type_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,22 @@ impl<'tcx> Printer<'tcx> for TypeNamePrinter<'tcx> {
// Types with identity (print the module path).
ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), args)
| ty::FnDef(def_id, args)
| ty::Alias(ty::Projection | ty::Opaque, ty::AliasTy { def_id, args, .. })
| ty::Alias(ty::AliasTy {
kind: ty::Projection { def_id } | ty::Opaque { def_id },
args,
..
})
| ty::Closure(def_id, args)
| ty::CoroutineClosure(def_id, args)
| ty::Coroutine(def_id, args) => self.print_def_path(def_id, args),
ty::Foreign(def_id) => self.print_def_path(def_id, &[]),

ty::Alias(ty::Free, _) => bug!("type_name: unexpected free alias"),
ty::Alias(ty::Inherent, _) => bug!("type_name: unexpected inherent projection"),
ty::Alias(ty::AliasTy { kind: ty::Free { .. }, .. }) => {
bug!("type_name: unexpected free alias")
}
ty::Alias(ty::AliasTy { kind: ty::Inherent { .. }, .. }) => {
bug!("type_name: unexpected inherent projection")
}
ty::CoroutineWitness(..) => bug!("type_name: unexpected `CoroutineWitness`"),
}
}
Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,8 @@ fn sanity_check_found_hidden_type<'tcx>(
// Nothing was actually constrained.
return Ok(());
}
if let ty::Alias(ty::Opaque, alias) = ty.ty.kind() {
if alias.def_id == key.def_id.to_def_id() && alias.args == key.args {
if let &ty::Alias(alias @ ty::AliasTy { kind: ty::Opaque { def_id }, .. }) = ty.ty.kind() {
if def_id == key.def_id.to_def_id() && alias.args == key.args {
// Nothing was actually constrained, this is an opaque usage that was
// only discovered to be opaque after inference vars resolved.
return Ok(());
Expand Down Expand Up @@ -2150,7 +2150,7 @@ fn opaque_type_cycle_error(tcx: TyCtxt<'_>, opaque_def_id: LocalDefId) -> ErrorG
impl<'tcx> ty::TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector {
fn visit_ty(&mut self, t: Ty<'tcx>) {
match *t.kind() {
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => {
ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: def }, .. }) => {
self.opaques.push(def);
}
ty::Closure(def_id, ..) | ty::Coroutine(def_id, ..) => {
Expand Down Expand Up @@ -2183,10 +2183,10 @@ fn opaque_type_cycle_error(tcx: TyCtxt<'_>, opaque_def_id: LocalDefId) -> ErrorG
let mut label_match = |ty: Ty<'_>, span| {
for arg in ty.walk() {
if let ty::GenericArgKind::Type(ty) = arg.kind()
&& let ty::Alias(
ty::Opaque,
ty::AliasTy { def_id: captured_def_id, .. },
) = *ty.kind()
&& let ty::Alias(ty::AliasTy {
kind: ty::Opaque { def_id: captured_def_id },
..
}) = *ty.kind()
&& captured_def_id == opaque_def_id.to_def_id()
{
err.span_label(
Expand Down
26 changes: 15 additions & 11 deletions compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,10 +820,10 @@ where
}

fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
if let ty::Alias(ty::Projection, proj) = ty.kind()
&& self.cx().is_impl_trait_in_trait(proj.def_id)
if let &ty::Alias(proj @ ty::AliasTy { kind: ty::Projection { def_id }, .. }) = ty.kind()
&& self.cx().is_impl_trait_in_trait(def_id)
{
if let Some((ty, _)) = self.types.get(&proj.def_id) {
if let Some((ty, _)) = self.types.get(&def_id) {
return *ty;
}
//FIXME(RPITIT): Deny nested RPITIT in args too
Expand All @@ -832,11 +832,11 @@ where
}
// Replace with infer var
let infer_ty = self.ocx.infcx.next_ty_var(self.span);
self.types.insert(proj.def_id, (infer_ty, proj.args));
self.types.insert(def_id, (infer_ty, proj.args));
// Recurse into bounds
for (pred, pred_span) in self
.cx()
.explicit_item_bounds(proj.def_id)
.explicit_item_bounds(def_id)
.iter_instantiated_copied(self.cx(), proj.args)
{
let pred = pred.fold_with(self);
Expand All @@ -851,7 +851,7 @@ where
ObligationCause::new(
self.span,
self.body_id,
ObligationCauseCode::WhereClause(proj.def_id, pred_span),
ObligationCauseCode::WhereClause(def_id, pred_span),
),
self.param_env,
pred,
Expand Down Expand Up @@ -922,8 +922,12 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> {
} else {
let guar = match region.opt_param_def_id(self.tcx, self.impl_m_def_id) {
Some(def_id) => {
let return_span = if let ty::Alias(ty::Opaque, opaque_ty) = self.ty.kind() {
self.tcx.def_span(opaque_ty.def_id)
let return_span = if let &ty::Alias(ty::AliasTy {
kind: ty::Opaque { def_id: opaque_ty_def_id },
..
}) = self.ty.kind()
{
self.tcx.def_span(opaque_ty_def_id)
} else {
self.return_span
};
Expand Down Expand Up @@ -2703,8 +2707,8 @@ fn param_env_with_gat_bounds<'tcx>(
let bound_vars = tcx.mk_bound_variable_kinds(&bound_vars);

match normalize_impl_ty.kind() {
ty::Alias(ty::Projection, proj)
if proj.def_id == trait_ty.def_id && proj.args == rebased_args =>
&ty::Alias(proj @ ty::AliasTy { kind: ty::Projection { def_id }, .. })
if def_id == trait_ty.def_id && proj.args == rebased_args =>
{
// Don't include this predicate if the projected type is
// exactly the same as the projection. This can occur in
Expand Down Expand Up @@ -2746,7 +2750,7 @@ fn try_report_async_mismatch<'tcx>(
return Ok(());
}

let ty::Alias(ty::Projection, ty::AliasTy { def_id: async_future_def_id, .. }) =
let ty::Alias(ty::AliasTy { kind: ty::Projection { def_id: async_future_def_id }, .. }) =
*tcx.fn_sig(trait_m.def_id).skip_binder().skip_binder().output().kind()
else {
bug!("expected `async fn` to return an RPITIT");
Expand Down
Loading
Loading