| author | bors <bors@rust-lang.org> 2026-04-07 12:56:57 UTC |
| committer | bors <bors@rust-lang.org> 2026-04-07 12:56:57 UTC |
| log | c3bd6289f65fa7210c50bdeeb0ed4541caa33d2d |
| tree | c19a04f57b28a5769711a14a00d1dad4b3ad5eb1 |
| parent | 49b6ac01d6f4c3da812039ae846407a20961aa4c |
| parent | 6ab50d53e332190cbebdf709602c16732ba7aab5 |
`ty::Alias` refactor
This PR changes the following alias-related types from this:
```rust
pub enum AliasTyKind {
Projection,
Inherent,
Opaque,
Free,
}
pub struct AliasTy<I: Interner> {
pub args: I::GenericArgs,
pub def_id: I::DefId,
}
pub enum TyKind<I: Interner> {
...
Alias(AliasTyKind, AliasTy<I>),
}
```
Into this:
```rust
pub enum AliasTyKind<I: Interner> {
Projection { def_id: I::DefId },
Inherent { def_id: I::DefId },
Opaque { def_id: I::DefId },
Free { def_id: I::DefId },
}
pub struct AliasTy<I: Interner> {
pub args: I::GenericArgs,
pub kind: AliasTyKind<I>,
}
pub enum TyKind<I: Interner> {
...
Alias(AliasTy<I>),
}
```
... and then does a thousand other changes to accommodate for this change everywhere.
This brings us closer to being able to have `AliasTyKind`s which don't require a `DefId` (and thus can be more easily created, etc). Although notably we depend on both `AliasTyKind -> DefId` and `DefId -> AliasTyKind` conversions in a bunch of places still.
r? lcnr
----
A lot of these changes were done either by search & replace (via `ast-grep`) or on auto pilot, so I'm not quite sure I didn't mess up somewhere, but at least tests pass...124 files changed, 991 insertions(+), 691 deletions(-)
compiler/rustc_borrowck/src/diagnostics/opaque_types.rs+7-7| ... | @@ -219,11 +219,11 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for FindOpaqueRegion<'_, 'tcx> { | ... | @@ -219,11 +219,11 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for FindOpaqueRegion<'_, 'tcx> { |
| 219 | fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result { | 219 | fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result { |
| 220 | // If we find an opaque in a local ty, then for each of its captured regions, | 220 | // If we find an opaque in a local ty, then for each of its captured regions, |
| 221 | // try to find a path between that captured regions and our borrow region... | 221 | // try to find a path between that captured regions and our borrow region... |
| 222 | if let ty::Alias(ty::Opaque, opaque) = *ty.kind() | 222 | if let ty::Alias(opaque @ ty::AliasTy { kind: ty::Opaque { def_id }, .. }) = *ty.kind() |
| 223 | && let hir::OpaqueTyOrigin::FnReturn { parent, in_trait_or_impl: None } = | 223 | && let hir::OpaqueTyOrigin::FnReturn { parent, in_trait_or_impl: None } = |
| 224 | self.tcx.opaque_ty_origin(opaque.def_id) | 224 | self.tcx.opaque_ty_origin(def_id) |
| 225 | { | 225 | { |
| 226 | let variances = self.tcx.variances_of(opaque.def_id); | 226 | let variances = self.tcx.variances_of(def_id); |
| 227 | for (idx, (arg, variance)) in std::iter::zip(opaque.args, variances).enumerate() { | 227 | for (idx, (arg, variance)) in std::iter::zip(opaque.args, variances).enumerate() { |
| 228 | // Skip uncaptured args. | 228 | // Skip uncaptured args. |
| 229 | if *variance == ty::Bivariant { | 229 | if *variance == ty::Bivariant { |
| ... | @@ -252,7 +252,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for FindOpaqueRegion<'_, 'tcx> { | ... | @@ -252,7 +252,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for FindOpaqueRegion<'_, 'tcx> { |
| 252 | && call_def_id == parent | 252 | && call_def_id == parent |
| 253 | && let Locations::Single(location) = constraint.locations | 253 | && let Locations::Single(location) = constraint.locations |
| 254 | { | 254 | { |
| 255 | return ControlFlow::Break((opaque.def_id, idx, location)); | 255 | return ControlFlow::Break((def_id, idx, location)); |
| 256 | } | 256 | } |
| 257 | } | 257 | } |
| 258 | } | 258 | } |
| ... | @@ -276,11 +276,11 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for CheckExplicitRegionMentionAndCollectGen | ... | @@ -276,11 +276,11 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for CheckExplicitRegionMentionAndCollectGen |
| 276 | 276 | ||
| 277 | fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result { | 277 | fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result { |
| 278 | match *ty.kind() { | 278 | match *ty.kind() { |
| 279 | ty::Alias(ty::Opaque, opaque) => { | 279 | ty::Alias(opaque @ ty::AliasTy { kind: ty::Opaque { def_id }, .. }) => { |
| 280 | if self.seen_opaques.insert(opaque.def_id) { | 280 | if self.seen_opaques.insert(def_id) { |
| 281 | for (bound, _) in self | 281 | for (bound, _) in self |
| 282 | .tcx | 282 | .tcx |
| 283 | .explicit_item_bounds(opaque.def_id) | 283 | .explicit_item_bounds(def_id) |
| 284 | .iter_instantiated_copied(self.tcx, opaque.args) | 284 | .iter_instantiated_copied(self.tcx, opaque.args) |
| 285 | { | 285 | { |
| 286 | bound.visit_with(self)?; | 286 | bound.visit_with(self)?; |
compiler/rustc_borrowck/src/diagnostics/region_errors.rs+1-1| ... | @@ -594,7 +594,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { | ... | @@ -594,7 +594,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { |
| 594 | let ErrorConstraintInfo { outlived_fr, span, .. } = errci; | 594 | let ErrorConstraintInfo { outlived_fr, span, .. } = errci; |
| 595 | 595 | ||
| 596 | let mut output_ty = self.regioncx.universal_regions().unnormalized_output_ty; | 596 | let mut output_ty = self.regioncx.universal_regions().unnormalized_output_ty; |
| 597 | if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *output_ty.kind() { | 597 | if let ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }) = *output_ty.kind() { |
| 598 | output_ty = self.infcx.tcx.type_of(def_id).instantiate_identity() | 598 | output_ty = self.infcx.tcx.type_of(def_id).instantiate_identity() |
| 599 | }; | 599 | }; |
| 600 | 600 |
compiler/rustc_borrowck/src/lib.rs+2-2| ... | @@ -1899,7 +1899,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> { | ... | @@ -1899,7 +1899,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> { |
| 1899 | | ty::Never | 1899 | | ty::Never |
| 1900 | | ty::Tuple(_) | 1900 | | ty::Tuple(_) |
| 1901 | | ty::UnsafeBinder(_) | 1901 | | ty::UnsafeBinder(_) |
| 1902 | | ty::Alias(_, _) | 1902 | | ty::Alias(_) |
| 1903 | | ty::Param(_) | 1903 | | ty::Param(_) |
| 1904 | | ty::Bound(_, _) | 1904 | | ty::Bound(_, _) |
| 1905 | | ty::Infer(_) | 1905 | | ty::Infer(_) |
| ... | @@ -1941,7 +1941,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> { | ... | @@ -1941,7 +1941,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> { |
| 1941 | | ty::CoroutineWitness(..) | 1941 | | ty::CoroutineWitness(..) |
| 1942 | | ty::Never | 1942 | | ty::Never |
| 1943 | | ty::UnsafeBinder(_) | 1943 | | ty::UnsafeBinder(_) |
| 1944 | | ty::Alias(_, _) | 1944 | | ty::Alias(_) |
| 1945 | | ty::Param(_) | 1945 | | ty::Param(_) |
| 1946 | | ty::Bound(_, _) | 1946 | | ty::Bound(_, _) |
| 1947 | | ty::Infer(_) | 1947 | | ty::Infer(_) |
compiler/rustc_borrowck/src/region_infer/opaque_types/member_constraints.rs+2-2| ... | @@ -176,8 +176,8 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for CollectMemberConstraintsVisitor<'_, '_, | ... | @@ -176,8 +176,8 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for CollectMemberConstraintsVisitor<'_, '_, |
| 176 | | ty::CoroutineClosure(def_id, args) | 176 | | ty::CoroutineClosure(def_id, args) |
| 177 | | ty::Coroutine(def_id, args) => self.visit_closure_args(def_id, args), | 177 | | ty::Coroutine(def_id, args) => self.visit_closure_args(def_id, args), |
| 178 | 178 | ||
| 179 | ty::Alias(kind, ty::AliasTy { def_id, args, .. }) | 179 | ty::Alias(ty::AliasTy { kind, args, .. }) |
| 180 | if let Some(variances) = self.cx().opt_alias_variances(kind, def_id) => | 180 | if let Some(variances) = self.cx().opt_alias_variances(kind, kind.def_id()) => |
| 181 | { | 181 | { |
| 182 | // Skip lifetime parameters that are not captured, since they do | 182 | // Skip lifetime parameters that are not captured, since they do |
| 183 | // not need member constraints registered for them; we'll erase | 183 | // not need member constraints registered for them; we'll erase |
compiler/rustc_borrowck/src/region_infer/opaque_types/mod.rs+11-9| ... | @@ -367,9 +367,10 @@ fn compute_definition_site_hidden_types_from_defining_uses<'tcx>( | ... | @@ -367,9 +367,10 @@ fn compute_definition_site_hidden_types_from_defining_uses<'tcx>( |
| 367 | // usage of the opaque type and we can ignore it. This check is mirrored in typeck's | 367 | // usage of the opaque type and we can ignore it. This check is mirrored in typeck's |
| 368 | // writeback. | 368 | // writeback. |
| 369 | if !rcx.infcx.tcx.use_typing_mode_borrowck() { | 369 | if !rcx.infcx.tcx.use_typing_mode_borrowck() { |
| 370 | if let ty::Alias(ty::Opaque, alias_ty) = hidden_type.ty.skip_binder().kind() | 370 | if let &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) = |
| 371 | && alias_ty.def_id == opaque_type_key.def_id.to_def_id() | 371 | hidden_type.ty.skip_binder().kind() |
| 372 | && alias_ty.args == opaque_type_key.args | 372 | && def_id == opaque_type_key.def_id.to_def_id() |
| 373 | && args == opaque_type_key.args | ||
| 373 | { | 374 | { |
| 374 | continue; | 375 | continue; |
| 375 | } | 376 | } |
| ... | @@ -499,8 +500,8 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for ToArgRegionsFolder<'_, 'tcx> { | ... | @@ -499,8 +500,8 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for ToArgRegionsFolder<'_, 'tcx> { |
| 499 | Ty::new_coroutine(tcx, def_id, self.fold_closure_args(def_id, args)?) | 500 | Ty::new_coroutine(tcx, def_id, self.fold_closure_args(def_id, args)?) |
| 500 | } | 501 | } |
| 501 | 502 | ||
| 502 | ty::Alias(kind, ty::AliasTy { def_id, args, .. }) | 503 | ty::Alias(ty::AliasTy { kind, args, .. }) |
| 503 | if let Some(variances) = tcx.opt_alias_variances(kind, def_id) => | 504 | if let Some(variances) = tcx.opt_alias_variances(kind, kind.def_id()) => |
| 504 | { | 505 | { |
| 505 | let args = tcx.mk_args_from_iter(std::iter::zip(variances, args.iter()).map( | 506 | let args = tcx.mk_args_from_iter(std::iter::zip(variances, args.iter()).map( |
| 506 | |(&v, s)| { | 507 | |(&v, s)| { |
| ... | @@ -511,7 +512,7 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for ToArgRegionsFolder<'_, 'tcx> { | ... | @@ -511,7 +512,7 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for ToArgRegionsFolder<'_, 'tcx> { |
| 511 | } | 512 | } |
| 512 | }, | 513 | }, |
| 513 | ))?; | 514 | ))?; |
| 514 | ty::AliasTy::new_from_args(tcx, def_id, args).to_ty(tcx) | 515 | ty::AliasTy::new_from_args(tcx, kind, args).to_ty(tcx) |
| 515 | } | 516 | } |
| 516 | 517 | ||
| 517 | _ => ty.try_super_fold_with(self)?, | 518 | _ => ty.try_super_fold_with(self)?, |
| ... | @@ -540,9 +541,10 @@ pub(crate) fn apply_definition_site_hidden_types<'tcx>( | ... | @@ -540,9 +541,10 @@ pub(crate) fn apply_definition_site_hidden_types<'tcx>( |
| 540 | for &(key, hidden_type) in opaque_types { | 541 | for &(key, hidden_type) in opaque_types { |
| 541 | let Some(expected) = hidden_types.get(&key.def_id) else { | 542 | let Some(expected) = hidden_types.get(&key.def_id) else { |
| 542 | if !tcx.use_typing_mode_borrowck() { | 543 | if !tcx.use_typing_mode_borrowck() { |
| 543 | if let ty::Alias(ty::Opaque, alias_ty) = hidden_type.ty.kind() | 544 | if let &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) = |
| 544 | && alias_ty.def_id == key.def_id.to_def_id() | 545 | hidden_type.ty.kind() |
| 545 | && alias_ty.args == key.args | 546 | && def_id == key.def_id.to_def_id() |
| 547 | && args == key.args | ||
| 546 | { | 548 | { |
| 547 | continue; | 549 | continue; |
| 548 | } else { | 550 | } else { |
compiler/rustc_borrowck/src/type_check/mod.rs+2-1| ... | @@ -450,7 +450,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { | ... | @@ -450,7 +450,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { |
| 450 | // Necessary for non-trivial patterns whose user-type annotation is an opaque type, | 450 | // Necessary for non-trivial patterns whose user-type annotation is an opaque type, |
| 451 | // e.g. `let (_a,): Tait = whatever`, see #105897 | 451 | // e.g. `let (_a,): Tait = whatever`, see #105897 |
| 452 | if !self.infcx.next_trait_solver() | 452 | if !self.infcx.next_trait_solver() |
| 453 | && let ty::Alias(ty::Opaque, ..) = curr_projected_ty.ty.kind() | 453 | && let ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) = |
| 454 | curr_projected_ty.ty.kind() | ||
| 454 | { | 455 | { |
| 455 | // There is nothing that we can compare here if we go through an opaque type. | 456 | // There is nothing that we can compare here if we go through an opaque type. |
| 456 | // We're always in its defining scope as we can otherwise not project through | 457 | // We're always in its defining scope as we can otherwise not project through |
compiler/rustc_borrowck/src/type_check/relate_tys.rs+10-6| ... | @@ -150,8 +150,12 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> { | ... | @@ -150,8 +150,12 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> { |
| 150 | }; | 150 | }; |
| 151 | 151 | ||
| 152 | let (a, b) = match (a.kind(), b.kind()) { | 152 | let (a, b) = match (a.kind(), b.kind()) { |
| 153 | (&ty::Alias(ty::Opaque, ..), _) => (a, enable_subtyping(b, true)?), | 153 | (&ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }), _) => { |
| 154 | (_, &ty::Alias(ty::Opaque, ..)) => (enable_subtyping(a, false)?, b), | 154 | (a, enable_subtyping(b, true)?) |
| 155 | } | ||
| 156 | (_, &ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. })) => { | ||
| 157 | (enable_subtyping(a, false)?, b) | ||
| 158 | } | ||
| 155 | _ => unreachable!( | 159 | _ => unreachable!( |
| 156 | "expected at least one opaque type in `relate_opaques`, got {a} and {b}." | 160 | "expected at least one opaque type in `relate_opaques`, got {a} and {b}." |
| 157 | ), | 161 | ), |
| ... | @@ -382,8 +386,8 @@ impl<'b, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'b, 'tcx> { | ... | @@ -382,8 +386,8 @@ impl<'b, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'b, 'tcx> { |
| 382 | } | 386 | } |
| 383 | 387 | ||
| 384 | ( | 388 | ( |
| 385 | &ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, .. }), | 389 | &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: a_def_id }, .. }), |
| 386 | &ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }), | 390 | &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: b_def_id }, .. }), |
| 387 | ) if a_def_id == b_def_id || infcx.next_trait_solver() => { | 391 | ) if a_def_id == b_def_id || infcx.next_trait_solver() => { |
| 388 | super_combine_tys(&infcx.infcx, self, a, b).map(|_| ()).or_else(|err| { | 392 | super_combine_tys(&infcx.infcx, self, a, b).map(|_| ()).or_else(|err| { |
| 389 | // This behavior is only there for the old solver, the new solver | 393 | // This behavior is only there for the old solver, the new solver |
| ... | @@ -397,8 +401,8 @@ impl<'b, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'b, 'tcx> { | ... | @@ -397,8 +401,8 @@ impl<'b, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'b, 'tcx> { |
| 397 | if a_def_id.is_local() { self.relate_opaques(a, b) } else { Err(err) } | 401 | if a_def_id.is_local() { self.relate_opaques(a, b) } else { Err(err) } |
| 398 | })?; | 402 | })?; |
| 399 | } | 403 | } |
| 400 | (&ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), _) | 404 | (&ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }), _) |
| 401 | | (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. })) | 405 | | (_, &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. })) |
| 402 | if def_id.is_local() && !self.type_checker.infcx.next_trait_solver() => | 406 | if def_id.is_local() && !self.type_checker.infcx.next_trait_solver() => |
| 403 | { | 407 | { |
| 404 | self.relate_opaques(a, b)?; | 408 | self.relate_opaques(a, b)?; |
compiler/rustc_const_eval/src/util/type_name.rs+11-3| ... | @@ -53,14 +53,22 @@ impl<'tcx> Printer<'tcx> for TypeNamePrinter<'tcx> { | ... | @@ -53,14 +53,22 @@ impl<'tcx> Printer<'tcx> for TypeNamePrinter<'tcx> { |
| 53 | // Types with identity (print the module path). | 53 | // Types with identity (print the module path). |
| 54 | ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), args) | 54 | ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), args) |
| 55 | | ty::FnDef(def_id, args) | 55 | | ty::FnDef(def_id, args) |
| 56 | | ty::Alias(ty::Projection | ty::Opaque, ty::AliasTy { def_id, args, .. }) | 56 | | ty::Alias(ty::AliasTy { |
| 57 | kind: ty::Projection { def_id } | ty::Opaque { def_id }, | ||
| 58 | args, | ||
| 59 | .. | ||
| 60 | }) | ||
| 57 | | ty::Closure(def_id, args) | 61 | | ty::Closure(def_id, args) |
| 58 | | ty::CoroutineClosure(def_id, args) | 62 | | ty::CoroutineClosure(def_id, args) |
| 59 | | ty::Coroutine(def_id, args) => self.print_def_path(def_id, args), | 63 | | ty::Coroutine(def_id, args) => self.print_def_path(def_id, args), |
| 60 | ty::Foreign(def_id) => self.print_def_path(def_id, &[]), | 64 | ty::Foreign(def_id) => self.print_def_path(def_id, &[]), |
| 61 | 65 | ||
| 62 | ty::Alias(ty::Free, _) => bug!("type_name: unexpected free alias"), | 66 | ty::Alias(ty::AliasTy { kind: ty::Free { .. }, .. }) => { |
| 63 | ty::Alias(ty::Inherent, _) => bug!("type_name: unexpected inherent projection"), | 67 | bug!("type_name: unexpected free alias") |
| 68 | } | ||
| 69 | ty::Alias(ty::AliasTy { kind: ty::Inherent { .. }, .. }) => { | ||
| 70 | bug!("type_name: unexpected inherent projection") | ||
| 71 | } | ||
| 64 | ty::CoroutineWitness(..) => bug!("type_name: unexpected `CoroutineWitness`"), | 72 | ty::CoroutineWitness(..) => bug!("type_name: unexpected `CoroutineWitness`"), |
| 65 | } | 73 | } |
| 66 | } | 74 | } |
compiler/rustc_hir_analysis/src/check/check.rs+7-7| ... | @@ -523,8 +523,8 @@ fn sanity_check_found_hidden_type<'tcx>( | ... | @@ -523,8 +523,8 @@ fn sanity_check_found_hidden_type<'tcx>( |
| 523 | // Nothing was actually constrained. | 523 | // Nothing was actually constrained. |
| 524 | return Ok(()); | 524 | return Ok(()); |
| 525 | } | 525 | } |
| 526 | if let ty::Alias(ty::Opaque, alias) = ty.ty.kind() { | 526 | if let &ty::Alias(alias @ ty::AliasTy { kind: ty::Opaque { def_id }, .. }) = ty.ty.kind() { |
| 527 | if alias.def_id == key.def_id.to_def_id() && alias.args == key.args { | 527 | if def_id == key.def_id.to_def_id() && alias.args == key.args { |
| 528 | // Nothing was actually constrained, this is an opaque usage that was | 528 | // Nothing was actually constrained, this is an opaque usage that was |
| 529 | // only discovered to be opaque after inference vars resolved. | 529 | // only discovered to be opaque after inference vars resolved. |
| 530 | return Ok(()); | 530 | return Ok(()); |
| ... | @@ -2150,7 +2150,7 @@ fn opaque_type_cycle_error(tcx: TyCtxt<'_>, opaque_def_id: LocalDefId) -> ErrorG | ... | @@ -2150,7 +2150,7 @@ fn opaque_type_cycle_error(tcx: TyCtxt<'_>, opaque_def_id: LocalDefId) -> ErrorG |
| 2150 | impl<'tcx> ty::TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector { | 2150 | impl<'tcx> ty::TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector { |
| 2151 | fn visit_ty(&mut self, t: Ty<'tcx>) { | 2151 | fn visit_ty(&mut self, t: Ty<'tcx>) { |
| 2152 | match *t.kind() { | 2152 | match *t.kind() { |
| 2153 | ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => { | 2153 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: def }, .. }) => { |
| 2154 | self.opaques.push(def); | 2154 | self.opaques.push(def); |
| 2155 | } | 2155 | } |
| 2156 | ty::Closure(def_id, ..) | ty::Coroutine(def_id, ..) => { | 2156 | ty::Closure(def_id, ..) | ty::Coroutine(def_id, ..) => { |
| ... | @@ -2183,10 +2183,10 @@ fn opaque_type_cycle_error(tcx: TyCtxt<'_>, opaque_def_id: LocalDefId) -> ErrorG | ... | @@ -2183,10 +2183,10 @@ fn opaque_type_cycle_error(tcx: TyCtxt<'_>, opaque_def_id: LocalDefId) -> ErrorG |
| 2183 | let mut label_match = |ty: Ty<'_>, span| { | 2183 | let mut label_match = |ty: Ty<'_>, span| { |
| 2184 | for arg in ty.walk() { | 2184 | for arg in ty.walk() { |
| 2185 | if let ty::GenericArgKind::Type(ty) = arg.kind() | 2185 | if let ty::GenericArgKind::Type(ty) = arg.kind() |
| 2186 | && let ty::Alias( | 2186 | && let ty::Alias(ty::AliasTy { |
| 2187 | ty::Opaque, | 2187 | kind: ty::Opaque { def_id: captured_def_id }, |
| 2188 | ty::AliasTy { def_id: captured_def_id, .. }, | 2188 | .. |
| 2189 | ) = *ty.kind() | 2189 | }) = *ty.kind() |
| 2190 | && captured_def_id == opaque_def_id.to_def_id() | 2190 | && captured_def_id == opaque_def_id.to_def_id() |
| 2191 | { | 2191 | { |
| 2192 | err.span_label( | 2192 | err.span_label( |
compiler/rustc_hir_analysis/src/check/compare_impl_item.rs+15-11| ... | @@ -820,10 +820,10 @@ where | ... | @@ -820,10 +820,10 @@ where |
| 820 | } | 820 | } |
| 821 | 821 | ||
| 822 | fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { | 822 | fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { |
| 823 | if let ty::Alias(ty::Projection, proj) = ty.kind() | 823 | if let &ty::Alias(proj @ ty::AliasTy { kind: ty::Projection { def_id }, .. }) = ty.kind() |
| 824 | && self.cx().is_impl_trait_in_trait(proj.def_id) | 824 | && self.cx().is_impl_trait_in_trait(def_id) |
| 825 | { | 825 | { |
| 826 | if let Some((ty, _)) = self.types.get(&proj.def_id) { | 826 | if let Some((ty, _)) = self.types.get(&def_id) { |
| 827 | return *ty; | 827 | return *ty; |
| 828 | } | 828 | } |
| 829 | //FIXME(RPITIT): Deny nested RPITIT in args too | 829 | //FIXME(RPITIT): Deny nested RPITIT in args too |
| ... | @@ -832,11 +832,11 @@ where | ... | @@ -832,11 +832,11 @@ where |
| 832 | } | 832 | } |
| 833 | // Replace with infer var | 833 | // Replace with infer var |
| 834 | let infer_ty = self.ocx.infcx.next_ty_var(self.span); | 834 | let infer_ty = self.ocx.infcx.next_ty_var(self.span); |
| 835 | self.types.insert(proj.def_id, (infer_ty, proj.args)); | 835 | self.types.insert(def_id, (infer_ty, proj.args)); |
| 836 | // Recurse into bounds | 836 | // Recurse into bounds |
| 837 | for (pred, pred_span) in self | 837 | for (pred, pred_span) in self |
| 838 | .cx() | 838 | .cx() |
| 839 | .explicit_item_bounds(proj.def_id) | 839 | .explicit_item_bounds(def_id) |
| 840 | .iter_instantiated_copied(self.cx(), proj.args) | 840 | .iter_instantiated_copied(self.cx(), proj.args) |
| 841 | { | 841 | { |
| 842 | let pred = pred.fold_with(self); | 842 | let pred = pred.fold_with(self); |
| ... | @@ -851,7 +851,7 @@ where | ... | @@ -851,7 +851,7 @@ where |
| 851 | ObligationCause::new( | 851 | ObligationCause::new( |
| 852 | self.span, | 852 | self.span, |
| 853 | self.body_id, | 853 | self.body_id, |
| 854 | ObligationCauseCode::WhereClause(proj.def_id, pred_span), | 854 | ObligationCauseCode::WhereClause(def_id, pred_span), |
| 855 | ), | 855 | ), |
| 856 | self.param_env, | 856 | self.param_env, |
| 857 | pred, | 857 | pred, |
| ... | @@ -922,8 +922,12 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> { | ... | @@ -922,8 +922,12 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> { |
| 922 | } else { | 922 | } else { |
| 923 | let guar = match region.opt_param_def_id(self.tcx, self.impl_m_def_id) { | 923 | let guar = match region.opt_param_def_id(self.tcx, self.impl_m_def_id) { |
| 924 | Some(def_id) => { | 924 | Some(def_id) => { |
| 925 | let return_span = if let ty::Alias(ty::Opaque, opaque_ty) = self.ty.kind() { | 925 | let return_span = if let &ty::Alias(ty::AliasTy { |
| 926 | self.tcx.def_span(opaque_ty.def_id) | 926 | kind: ty::Opaque { def_id: opaque_ty_def_id }, |
| 927 | .. | ||
| 928 | }) = self.ty.kind() | ||
| 929 | { | ||
| 930 | self.tcx.def_span(opaque_ty_def_id) | ||
| 927 | } else { | 931 | } else { |
| 928 | self.return_span | 932 | self.return_span |
| 929 | }; | 933 | }; |
| ... | @@ -2703,8 +2707,8 @@ fn param_env_with_gat_bounds<'tcx>( | ... | @@ -2703,8 +2707,8 @@ fn param_env_with_gat_bounds<'tcx>( |
| 2703 | let bound_vars = tcx.mk_bound_variable_kinds(&bound_vars); | 2707 | let bound_vars = tcx.mk_bound_variable_kinds(&bound_vars); |
| 2704 | 2708 | ||
| 2705 | match normalize_impl_ty.kind() { | 2709 | match normalize_impl_ty.kind() { |
| 2706 | ty::Alias(ty::Projection, proj) | 2710 | &ty::Alias(proj @ ty::AliasTy { kind: ty::Projection { def_id }, .. }) |
| 2707 | if proj.def_id == trait_ty.def_id && proj.args == rebased_args => | 2711 | if def_id == trait_ty.def_id && proj.args == rebased_args => |
| 2708 | { | 2712 | { |
| 2709 | // Don't include this predicate if the projected type is | 2713 | // Don't include this predicate if the projected type is |
| 2710 | // exactly the same as the projection. This can occur in | 2714 | // exactly the same as the projection. This can occur in |
| ... | @@ -2746,7 +2750,7 @@ fn try_report_async_mismatch<'tcx>( | ... | @@ -2746,7 +2750,7 @@ fn try_report_async_mismatch<'tcx>( |
| 2746 | return Ok(()); | 2750 | return Ok(()); |
| 2747 | } | 2751 | } |
| 2748 | 2752 | ||
| 2749 | let ty::Alias(ty::Projection, ty::AliasTy { def_id: async_future_def_id, .. }) = | 2753 | let ty::Alias(ty::AliasTy { kind: ty::Projection { def_id: async_future_def_id }, .. }) = |
| 2750 | *tcx.fn_sig(trait_m.def_id).skip_binder().skip_binder().output().kind() | 2754 | *tcx.fn_sig(trait_m.def_id).skip_binder().skip_binder().output().kind() |
| 2751 | else { | 2755 | else { |
| 2752 | bug!("expected `async fn` to return an RPITIT"); | 2756 | bug!("expected `async fn` to return an RPITIT"); |
compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs+21-13| ... | @@ -80,10 +80,14 @@ pub(crate) fn check_refining_return_position_impl_trait_in_trait<'tcx>( | ... | @@ -80,10 +80,14 @@ pub(crate) fn check_refining_return_position_impl_trait_in_trait<'tcx>( |
| 80 | 80 | ||
| 81 | for trait_projection in collector.types.into_iter().rev() { | 81 | for trait_projection in collector.types.into_iter().rev() { |
| 82 | let impl_opaque_args = trait_projection.args.rebase_onto(tcx, trait_m.def_id, impl_m_args); | 82 | let impl_opaque_args = trait_projection.args.rebase_onto(tcx, trait_m.def_id, impl_m_args); |
| 83 | let hidden_ty = hidden_tys[&trait_projection.def_id].instantiate(tcx, impl_opaque_args); | 83 | let hidden_ty = |
| 84 | hidden_tys[&trait_projection.kind.def_id()].instantiate(tcx, impl_opaque_args); | ||
| 84 | 85 | ||
| 85 | // If the hidden type is not an opaque, then we have "refined" the trait signature. | 86 | // If the hidden type is not an opaque, then we have "refined" the trait signature. |
| 86 | let ty::Alias(ty::Opaque, impl_opaque) = *hidden_ty.kind() else { | 87 | let ty::Alias( |
| 88 | impl_opaque @ ty::AliasTy { kind: ty::Opaque { def_id: impl_opaque_def_id }, .. }, | ||
| 89 | ) = *hidden_ty.kind() | ||
| 90 | else { | ||
| 87 | report_mismatched_rpitit_signature( | 91 | report_mismatched_rpitit_signature( |
| 88 | tcx, | 92 | tcx, |
| 89 | trait_m_sig_with_self_for_diag, | 93 | trait_m_sig_with_self_for_diag, |
| ... | @@ -97,7 +101,7 @@ pub(crate) fn check_refining_return_position_impl_trait_in_trait<'tcx>( | ... | @@ -97,7 +101,7 @@ pub(crate) fn check_refining_return_position_impl_trait_in_trait<'tcx>( |
| 97 | 101 | ||
| 98 | // This opaque also needs to be from the impl method -- otherwise, | 102 | // This opaque also needs to be from the impl method -- otherwise, |
| 99 | // it's a refinement to a TAIT. | 103 | // it's a refinement to a TAIT. |
| 100 | if !tcx.hir_get_if_local(impl_opaque.def_id).is_some_and(|node| { | 104 | if !tcx.hir_get_if_local(impl_opaque_def_id).is_some_and(|node| { |
| 101 | matches!( | 105 | matches!( |
| 102 | node.expect_opaque_ty().origin, | 106 | node.expect_opaque_ty().origin, |
| 103 | hir::OpaqueTyOrigin::AsyncFn { parent, .. } | hir::OpaqueTyOrigin::FnReturn { parent, .. } | 107 | hir::OpaqueTyOrigin::AsyncFn { parent, .. } | hir::OpaqueTyOrigin::FnReturn { parent, .. } |
| ... | @@ -116,11 +120,12 @@ pub(crate) fn check_refining_return_position_impl_trait_in_trait<'tcx>( | ... | @@ -116,11 +120,12 @@ pub(crate) fn check_refining_return_position_impl_trait_in_trait<'tcx>( |
| 116 | } | 120 | } |
| 117 | 121 | ||
| 118 | trait_bounds.extend( | 122 | trait_bounds.extend( |
| 119 | tcx.item_bounds(trait_projection.def_id).iter_instantiated(tcx, trait_projection.args), | 123 | tcx.item_bounds(trait_projection.kind.def_id()) |
| 124 | .iter_instantiated(tcx, trait_projection.args), | ||
| 120 | ); | 125 | ); |
| 121 | impl_bounds.extend(elaborate( | 126 | impl_bounds.extend(elaborate( |
| 122 | tcx, | 127 | tcx, |
| 123 | tcx.explicit_item_bounds(impl_opaque.def_id) | 128 | tcx.explicit_item_bounds(impl_opaque_def_id) |
| 124 | .iter_instantiated_copied(tcx, impl_opaque.args), | 129 | .iter_instantiated_copied(tcx, impl_opaque.args), |
| 125 | )); | 130 | )); |
| 126 | 131 | ||
| ... | @@ -218,7 +223,7 @@ pub(crate) fn check_refining_return_position_impl_trait_in_trait<'tcx>( | ... | @@ -218,7 +223,7 @@ pub(crate) fn check_refining_return_position_impl_trait_in_trait<'tcx>( |
| 218 | // is literally unrepresentable in the type system; however, we may be | 223 | // is literally unrepresentable in the type system; however, we may be |
| 219 | // promising stronger outlives guarantees if we capture *fewer* regions. | 224 | // promising stronger outlives guarantees if we capture *fewer* regions. |
| 220 | for (trait_projection, impl_opaque) in pairs { | 225 | for (trait_projection, impl_opaque) in pairs { |
| 221 | let impl_variances = tcx.variances_of(impl_opaque.def_id); | 226 | let impl_variances = tcx.variances_of(impl_opaque.kind.def_id()); |
| 222 | let impl_captures: FxIndexSet<_> = impl_opaque | 227 | let impl_captures: FxIndexSet<_> = impl_opaque |
| 223 | .args | 228 | .args |
| 224 | .iter() | 229 | .iter() |
| ... | @@ -227,7 +232,7 @@ pub(crate) fn check_refining_return_position_impl_trait_in_trait<'tcx>( | ... | @@ -227,7 +232,7 @@ pub(crate) fn check_refining_return_position_impl_trait_in_trait<'tcx>( |
| 227 | .map(|(arg, _)| arg) | 232 | .map(|(arg, _)| arg) |
| 228 | .collect(); | 233 | .collect(); |
| 229 | 234 | ||
| 230 | let trait_variances = tcx.variances_of(trait_projection.def_id); | 235 | let trait_variances = tcx.variances_of(trait_projection.kind.def_id()); |
| 231 | let mut trait_captures = FxIndexSet::default(); | 236 | let mut trait_captures = FxIndexSet::default(); |
| 232 | for (arg, variance) in trait_projection.args.iter().zip_eq(trait_variances) { | 237 | for (arg, variance) in trait_projection.args.iter().zip_eq(trait_variances) { |
| 233 | if *variance != ty::Invariant { | 238 | if *variance != ty::Invariant { |
| ... | @@ -239,7 +244,7 @@ pub(crate) fn check_refining_return_position_impl_trait_in_trait<'tcx>( | ... | @@ -239,7 +244,7 @@ pub(crate) fn check_refining_return_position_impl_trait_in_trait<'tcx>( |
| 239 | if !trait_captures.iter().all(|arg| impl_captures.contains(arg)) { | 244 | if !trait_captures.iter().all(|arg| impl_captures.contains(arg)) { |
| 240 | report_mismatched_rpitit_captures( | 245 | report_mismatched_rpitit_captures( |
| 241 | tcx, | 246 | tcx, |
| 242 | impl_opaque.def_id.expect_local(), | 247 | impl_opaque.kind.def_id().expect_local(), |
| 243 | trait_captures, | 248 | trait_captures, |
| 244 | is_internal, | 249 | is_internal, |
| 245 | ); | 250 | ); |
| ... | @@ -254,13 +259,13 @@ struct ImplTraitInTraitCollector<'tcx> { | ... | @@ -254,13 +259,13 @@ struct ImplTraitInTraitCollector<'tcx> { |
| 254 | 259 | ||
| 255 | impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'tcx> { | 260 | impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'tcx> { |
| 256 | fn visit_ty(&mut self, ty: Ty<'tcx>) { | 261 | fn visit_ty(&mut self, ty: Ty<'tcx>) { |
| 257 | if let ty::Alias(ty::Projection, proj) = *ty.kind() | 262 | if let ty::Alias(proj @ ty::AliasTy { kind: ty::Projection { def_id }, .. }) = *ty.kind() |
| 258 | && self.tcx.is_impl_trait_in_trait(proj.def_id) | 263 | && self.tcx.is_impl_trait_in_trait(def_id) |
| 259 | { | 264 | { |
| 260 | if self.types.insert(proj) { | 265 | if self.types.insert(proj) { |
| 261 | for (pred, _) in self | 266 | for (pred, _) in self |
| 262 | .tcx | 267 | .tcx |
| 263 | .explicit_item_bounds(proj.def_id) | 268 | .explicit_item_bounds(def_id) |
| 264 | .iter_instantiated_copied(self.tcx, proj.args) | 269 | .iter_instantiated_copied(self.tcx, proj.args) |
| 265 | { | 270 | { |
| 266 | pred.visit_with(self); | 271 | pred.visit_with(self); |
| ... | @@ -303,14 +308,17 @@ fn report_mismatched_rpitit_signature<'tcx>( | ... | @@ -303,14 +308,17 @@ fn report_mismatched_rpitit_signature<'tcx>( |
| 303 | let mut return_ty = trait_m_sig.output().fold_with(&mut super::RemapLateParam { tcx, mapping }); | 308 | let mut return_ty = trait_m_sig.output().fold_with(&mut super::RemapLateParam { tcx, mapping }); |
| 304 | 309 | ||
| 305 | if tcx.asyncness(impl_m_def_id).is_async() && tcx.asyncness(trait_m_def_id).is_async() { | 310 | if tcx.asyncness(impl_m_def_id).is_async() && tcx.asyncness(trait_m_def_id).is_async() { |
| 306 | let ty::Alias(ty::Projection, future_ty) = return_ty.kind() else { | 311 | let &ty::Alias( |
| 312 | future_ty @ ty::AliasTy { kind: ty::Projection { def_id: future_ty_def_id }, .. }, | ||
| 313 | ) = return_ty.kind() | ||
| 314 | else { | ||
| 307 | span_bug!( | 315 | span_bug!( |
| 308 | tcx.def_span(trait_m_def_id), | 316 | tcx.def_span(trait_m_def_id), |
| 309 | "expected return type of async fn in trait to be a AFIT projection" | 317 | "expected return type of async fn in trait to be a AFIT projection" |
| 310 | ); | 318 | ); |
| 311 | }; | 319 | }; |
| 312 | let Some(future_output_ty) = tcx | 320 | let Some(future_output_ty) = tcx |
| 313 | .explicit_item_bounds(future_ty.def_id) | 321 | .explicit_item_bounds(future_ty_def_id) |
| 314 | .iter_instantiated_copied(tcx, future_ty.args) | 322 | .iter_instantiated_copied(tcx, future_ty.args) |
| 315 | .find_map(|(clause, _)| match clause.kind().no_bound_vars()? { | 323 | .find_map(|(clause, _)| match clause.kind().no_bound_vars()? { |
| 316 | ty::ClauseKind::Projection(proj) => proj.term.as_type(), | 324 | ty::ClauseKind::Projection(proj) => proj.term.as_type(), |
compiler/rustc_hir_analysis/src/check/mod.rs+2-2| ... | @@ -485,9 +485,9 @@ fn fn_sig_suggestion<'tcx>( | ... | @@ -485,9 +485,9 @@ fn fn_sig_suggestion<'tcx>( |
| 485 | let mut output = sig.output(); | 485 | let mut output = sig.output(); |
| 486 | 486 | ||
| 487 | let asyncness = if tcx.asyncness(assoc.def_id).is_async() { | 487 | let asyncness = if tcx.asyncness(assoc.def_id).is_async() { |
| 488 | output = if let ty::Alias(_, alias_ty) = *output.kind() | 488 | output = if let ty::Alias(alias_ty) = *output.kind() |
| 489 | && let Some(output) = tcx | 489 | && let Some(output) = tcx |
| 490 | .explicit_item_self_bounds(alias_ty.def_id) | 490 | .explicit_item_self_bounds(alias_ty.kind.def_id()) |
| 491 | .iter_instantiated_copied(tcx, alias_ty.args) | 491 | .iter_instantiated_copied(tcx, alias_ty.args) |
| 492 | .find_map(|(bound, _)| { | 492 | .find_map(|(bound, _)| { |
| 493 | bound.as_projection_clause()?.no_bound_vars()?.term.as_type() | 493 | bound.as_projection_clause()?.no_bound_vars()?.term.as_type() |
compiler/rustc_hir_analysis/src/check/wfcheck.rs+4-2| ... | @@ -773,7 +773,9 @@ impl<'tcx> GATArgsCollector<'tcx> { | ... | @@ -773,7 +773,9 @@ impl<'tcx> GATArgsCollector<'tcx> { |
| 773 | impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GATArgsCollector<'tcx> { | 773 | impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GATArgsCollector<'tcx> { |
| 774 | fn visit_ty(&mut self, t: Ty<'tcx>) { | 774 | fn visit_ty(&mut self, t: Ty<'tcx>) { |
| 775 | match t.kind() { | 775 | match t.kind() { |
| 776 | ty::Alias(ty::Projection, p) if p.def_id == self.gat => { | 776 | &ty::Alias(p @ ty::AliasTy { kind: ty::Projection { def_id }, .. }) |
| 777 | if def_id == self.gat => | ||
| 778 | { | ||
| 777 | for (idx, arg) in p.args.iter().enumerate() { | 779 | for (idx, arg) in p.args.iter().enumerate() { |
| 778 | match arg.kind() { | 780 | match arg.kind() { |
| 779 | GenericArgKind::Lifetime(lt) if !lt.is_bound() => { | 781 | GenericArgKind::Lifetime(lt) if !lt.is_bound() => { |
| ... | @@ -2250,7 +2252,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IsProbablyCyclical<'tcx> { | ... | @@ -2250,7 +2252,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IsProbablyCyclical<'tcx> { |
| 2250 | fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<(), ()> { | 2252 | fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<(), ()> { |
| 2251 | let def_id = match ty.kind() { | 2253 | let def_id = match ty.kind() { |
| 2252 | ty::Adt(adt_def, _) => Some(adt_def.did()), | 2254 | ty::Adt(adt_def, _) => Some(adt_def.did()), |
| 2253 | ty::Alias(ty::Free, alias_ty) => Some(alias_ty.def_id), | 2255 | &ty::Alias(ty::AliasTy { kind: ty::Free { def_id }, .. }) => Some(def_id), |
| 2254 | _ => None, | 2256 | _ => None, |
| 2255 | }; | 2257 | }; |
| 2256 | if let Some(def_id) = def_id { | 2258 | if let Some(def_id) = def_id { |
compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs+6-2| ... | @@ -195,7 +195,11 @@ impl<'tcx> InherentCollect<'tcx> { | ... | @@ -195,7 +195,11 @@ impl<'tcx> InherentCollect<'tcx> { |
| 195 | | ty::FnPtr(..) | 195 | | ty::FnPtr(..) |
| 196 | | ty::Tuple(..) | 196 | | ty::Tuple(..) |
| 197 | | ty::UnsafeBinder(_) => self.check_primitive_impl(id, self_ty), | 197 | | ty::UnsafeBinder(_) => self.check_primitive_impl(id, self_ty), |
| 198 | ty::Alias(ty::Projection | ty::Inherent | ty::Opaque, _) | ty::Param(_) => { | 198 | ty::Alias(ty::AliasTy { |
| 199 | kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Opaque { .. }, | ||
| 200 | .. | ||
| 201 | }) | ||
| 202 | | ty::Param(_) => { | ||
| 199 | Err(self.tcx.dcx().emit_err(errors::InherentNominal { span: item_span })) | 203 | Err(self.tcx.dcx().emit_err(errors::InherentNominal { span: item_span })) |
| 200 | } | 204 | } |
| 201 | ty::FnDef(..) | 205 | ty::FnDef(..) |
| ... | @@ -203,7 +207,7 @@ impl<'tcx> InherentCollect<'tcx> { | ... | @@ -203,7 +207,7 @@ impl<'tcx> InherentCollect<'tcx> { |
| 203 | | ty::CoroutineClosure(..) | 207 | | ty::CoroutineClosure(..) |
| 204 | | ty::Coroutine(..) | 208 | | ty::Coroutine(..) |
| 205 | | ty::CoroutineWitness(..) | 209 | | ty::CoroutineWitness(..) |
| 206 | | ty::Alias(ty::Free, _) | 210 | | ty::Alias(ty::AliasTy { kind: ty::Free { .. }, .. }) |
| 207 | | ty::Bound(..) | 211 | | ty::Bound(..) |
| 208 | | ty::Placeholder(_) | 212 | | ty::Placeholder(_) |
| 209 | | ty::Infer(_) => { | 213 | | ty::Infer(_) => { |
compiler/rustc_hir_analysis/src/coherence/orphan.rs+6-6| ... | @@ -179,20 +179,20 @@ pub(crate) fn orphan_check_impl( | ... | @@ -179,20 +179,20 @@ pub(crate) fn orphan_check_impl( |
| 179 | NonlocalImpl::DisallowOther, | 179 | NonlocalImpl::DisallowOther, |
| 180 | ), | 180 | ), |
| 181 | 181 | ||
| 182 | ty::Alias(kind, _) => { | 182 | ty::Alias(ty::AliasTy { kind, .. }) => { |
| 183 | let problematic_kind = match kind { | 183 | let problematic_kind = match kind { |
| 184 | // trait Id { type This: ?Sized; } | 184 | // trait Id { type This: ?Sized; } |
| 185 | // impl<T: ?Sized> Id for T { | 185 | // impl<T: ?Sized> Id for T { |
| 186 | // type This = T; | 186 | // type This = T; |
| 187 | // } | 187 | // } |
| 188 | // impl<T: ?Sized> AutoTrait for <T as Id>::This {} | 188 | // impl<T: ?Sized> AutoTrait for <T as Id>::This {} |
| 189 | ty::Projection => "associated type", | 189 | ty::Projection { .. } => "associated type", |
| 190 | // type Foo = (impl Sized, bool) | 190 | // type Foo = (impl Sized, bool) |
| 191 | // impl AutoTrait for Foo {} | 191 | // impl AutoTrait for Foo {} |
| 192 | ty::Free => "type alias", | 192 | ty::Free { .. } => "type alias", |
| 193 | // type Opaque = impl Trait; | 193 | // type Opaque = impl Trait; |
| 194 | // impl AutoTrait for Opaque {} | 194 | // impl AutoTrait for Opaque {} |
| 195 | ty::Opaque => "opaque type", | 195 | ty::Opaque { .. } => "opaque type", |
| 196 | // ``` | 196 | // ``` |
| 197 | // struct S<T>(T); | 197 | // struct S<T>(T); |
| 198 | // impl<T: ?Sized> S<T> { | 198 | // impl<T: ?Sized> S<T> { |
| ... | @@ -201,7 +201,7 @@ pub(crate) fn orphan_check_impl( | ... | @@ -201,7 +201,7 @@ pub(crate) fn orphan_check_impl( |
| 201 | // impl<T: ?Sized> AutoTrait for S<T>::This {} | 201 | // impl<T: ?Sized> AutoTrait for S<T>::This {} |
| 202 | // ``` | 202 | // ``` |
| 203 | // FIXME(inherent_associated_types): The example code above currently leads to a cycle | 203 | // FIXME(inherent_associated_types): The example code above currently leads to a cycle |
| 204 | ty::Inherent => "associated type", | 204 | ty::Inherent { .. } => "associated type", |
| 205 | }; | 205 | }; |
| 206 | (LocalImpl::Disallow { problematic_kind }, NonlocalImpl::DisallowOther) | 206 | (LocalImpl::Disallow { problematic_kind }, NonlocalImpl::DisallowOther) |
| 207 | } | 207 | } |
| ... | @@ -436,7 +436,7 @@ fn emit_orphan_check_error<'tcx>( | ... | @@ -436,7 +436,7 @@ fn emit_orphan_check_error<'tcx>( |
| 436 | }); | 436 | }); |
| 437 | } | 437 | } |
| 438 | } | 438 | } |
| 439 | ty::Alias(ty::Opaque, ..) => { | 439 | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) => { |
| 440 | diag.subdiagnostic(errors::OnlyCurrentTraitsOpaque { span }); | 440 | diag.subdiagnostic(errors::OnlyCurrentTraitsOpaque { span }); |
| 441 | } | 441 | } |
| 442 | ty::RawPtr(ptr_ty, mutbl) => { | 442 | ty::RawPtr(ptr_ty, mutbl) => { |
compiler/rustc_hir_analysis/src/collect/item_bounds.rs+13-5| ... | @@ -143,9 +143,12 @@ fn remap_gat_vars_and_recurse_into_nested_projections<'tcx>( | ... | @@ -143,9 +143,12 @@ fn remap_gat_vars_and_recurse_into_nested_projections<'tcx>( |
| 143 | }; | 143 | }; |
| 144 | 144 | ||
| 145 | let gat_vars = loop { | 145 | let gat_vars = loop { |
| 146 | if let ty::Alias(ty::Projection, alias_ty) = *clause_ty.kind() { | 146 | if let ty::Alias( |
| 147 | alias_ty @ ty::AliasTy { kind: ty::Projection { def_id: alias_ty_def_id }, .. }, | ||
| 148 | ) = *clause_ty.kind() | ||
| 149 | { | ||
| 147 | if alias_ty.trait_ref(tcx) == item_trait_ref | 150 | if alias_ty.trait_ref(tcx) == item_trait_ref |
| 148 | && alias_ty.def_id == assoc_item_def_id.to_def_id() | 151 | && alias_ty_def_id == assoc_item_def_id.to_def_id() |
| 149 | { | 152 | { |
| 150 | // We have found the GAT in question... | 153 | // We have found the GAT in question... |
| 151 | // Return the vars, since we may need to remap them. | 154 | // Return the vars, since we may need to remap them. |
| ... | @@ -546,12 +549,17 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTyToOpaque<'tcx> { | ... | @@ -546,12 +549,17 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTyToOpaque<'tcx> { |
| 546 | } | 549 | } |
| 547 | 550 | ||
| 548 | fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { | 551 | fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { |
| 549 | if let ty::Alias(ty::Projection, projection_ty) = ty.kind() | 552 | if let &ty::Alias( |
| 553 | projection_ty @ ty::AliasTy { | ||
| 554 | kind: ty::Projection { def_id: projection_ty_def_id }, | ||
| 555 | .. | ||
| 556 | }, | ||
| 557 | ) = ty.kind() | ||
| 550 | && let Some(ty::ImplTraitInTraitData::Trait { fn_def_id, .. }) = | 558 | && let Some(ty::ImplTraitInTraitData::Trait { fn_def_id, .. }) = |
| 551 | self.tcx.opt_rpitit_info(projection_ty.def_id) | 559 | self.tcx.opt_rpitit_info(projection_ty_def_id) |
| 552 | && fn_def_id == self.fn_def_id | 560 | && fn_def_id == self.fn_def_id |
| 553 | { | 561 | { |
| 554 | self.tcx.type_of(projection_ty.def_id).instantiate(self.tcx, projection_ty.args) | 562 | self.tcx.type_of(projection_ty_def_id).instantiate(self.tcx, projection_ty.args) |
| 555 | } else { | 563 | } else { |
| 556 | ty.super_fold_with(self) | 564 | ty.super_fold_with(self) |
| 557 | } | 565 | } |
compiler/rustc_hir_analysis/src/collect/predicates_of.rs+8-3| ... | @@ -513,11 +513,16 @@ pub(super) fn explicit_predicates_of<'tcx>( | ... | @@ -513,11 +513,16 @@ pub(super) fn explicit_predicates_of<'tcx>( |
| 513 | // identity args of the trait. | 513 | // identity args of the trait. |
| 514 | // * It must be an associated type for this trait (*not* a | 514 | // * It must be an associated type for this trait (*not* a |
| 515 | // supertrait). | 515 | // supertrait). |
| 516 | if let ty::Alias(ty::Projection, projection) = ty.kind() { | 516 | if let &ty::Alias( |
| 517 | projection @ ty::AliasTy { | ||
| 518 | kind: ty::Projection { def_id: projection_def_id }, .. | ||
| 519 | }, | ||
| 520 | ) = ty.kind() | ||
| 521 | { | ||
| 517 | projection.args == trait_identity_args | 522 | projection.args == trait_identity_args |
| 518 | // FIXME(return_type_notation): This check should be more robust | 523 | // FIXME(return_type_notation): This check should be more robust |
| 519 | && !tcx.is_impl_trait_in_trait(projection.def_id) | 524 | && !tcx.is_impl_trait_in_trait(projection_def_id) |
| 520 | && tcx.parent(projection.def_id) == def_id.to_def_id() | 525 | && tcx.parent(projection_def_id) == def_id.to_def_id() |
| 521 | } else { | 526 | } else { |
| 522 | false | 527 | false |
| 523 | } | 528 | } |
compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs+4-1| ... | @@ -2407,7 +2407,10 @@ fn is_late_bound_map( | ... | @@ -2407,7 +2407,10 @@ fn is_late_bound_map( |
| 2407 | ty::Param(param_ty) => { | 2407 | ty::Param(param_ty) => { |
| 2408 | self.arg_is_constrained[param_ty.index as usize] = true; | 2408 | self.arg_is_constrained[param_ty.index as usize] = true; |
| 2409 | } | 2409 | } |
| 2410 | ty::Alias(ty::Projection | ty::Inherent, _) => return, | 2410 | ty::Alias(ty::AliasTy { |
| 2411 | kind: ty::Projection { .. } | ty::Inherent { .. }, | ||
| 2412 | .. | ||
| 2413 | }) => return, | ||
| 2411 | _ => (), | 2414 | _ => (), |
| 2412 | } | 2415 | } |
| 2413 | t.super_visit_with(self) | 2416 | t.super_visit_with(self) |
compiler/rustc_hir_analysis/src/constrained_generic_params.rs+7-4| ... | @@ -63,13 +63,16 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ParameterCollector { | ... | @@ -63,13 +63,16 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ParameterCollector { |
| 63 | fn visit_ty(&mut self, t: Ty<'tcx>) { | 63 | fn visit_ty(&mut self, t: Ty<'tcx>) { |
| 64 | match *t.kind() { | 64 | match *t.kind() { |
| 65 | // Projections are not injective in general. | 65 | // Projections are not injective in general. |
| 66 | ty::Alias(ty::Projection | ty::Inherent | ty::Opaque, _) | 66 | ty::Alias(ty::AliasTy { |
| 67 | if !self.include_nonconstraining => | 67 | kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Opaque { .. }, |
| 68 | { | 68 | .. |
| 69 | }) if !self.include_nonconstraining => { | ||
| 69 | return; | 70 | return; |
| 70 | } | 71 | } |
| 71 | // All free alias types should've been expanded beforehand. | 72 | // All free alias types should've been expanded beforehand. |
| 72 | ty::Alias(ty::Free, _) if !self.include_nonconstraining => { | 73 | ty::Alias(ty::AliasTy { kind: ty::Free { .. }, .. }) |
| 74 | if !self.include_nonconstraining => | ||
| 75 | { | ||
| 73 | bug!("unexpected free alias type") | 76 | bug!("unexpected free alias type") |
| 74 | } | 77 | } |
| 75 | ty::Param(param) => self.parameters.push(Parameter::from(param)), | 78 | ty::Param(param) => self.parameters.push(Parameter::from(param)), |
compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs+6-6| ... | @@ -639,8 +639,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { | ... | @@ -639,8 +639,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { |
| 639 | .map_bound(|projection_term| projection_term.expect_ty(self.tcx())); | 639 | .map_bound(|projection_term| projection_term.expect_ty(self.tcx())); |
| 640 | // Calling `skip_binder` is okay, because `lower_bounds` expects the `param_ty` | 640 | // Calling `skip_binder` is okay, because `lower_bounds` expects the `param_ty` |
| 641 | // parameter to have a skipped binder. | 641 | // parameter to have a skipped binder. |
| 642 | let param_ty = | 642 | let param_ty = Ty::new_alias(tcx, projection_ty.skip_binder()); |
| 643 | Ty::new_alias(tcx, ty::Projection, projection_ty.skip_binder()); | ||
| 644 | self.lower_bounds( | 643 | self.lower_bounds( |
| 645 | param_ty, | 644 | param_ty, |
| 646 | hir_bounds, | 645 | hir_bounds, |
| ... | @@ -730,7 +729,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { | ... | @@ -730,7 +729,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { |
| 730 | ty::Binder::bind_with_vars(trait_ref, tcx.late_bound_vars(item_segment.hir_id)); | 729 | ty::Binder::bind_with_vars(trait_ref, tcx.late_bound_vars(item_segment.hir_id)); |
| 731 | 730 | ||
| 732 | match self.lower_return_type_notation_ty(candidate, item_def_id, hir_ty.span) { | 731 | match self.lower_return_type_notation_ty(candidate, item_def_id, hir_ty.span) { |
| 733 | Ok(ty) => Ty::new_alias(tcx, ty::Projection, ty), | 732 | Ok(ty) => Ty::new_alias(tcx, ty), |
| 734 | Err(guar) => Ty::new_error(tcx, guar), | 733 | Err(guar) => Ty::new_error(tcx, guar), |
| 735 | } | 734 | } |
| 736 | } | 735 | } |
| ... | @@ -773,7 +772,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { | ... | @@ -773,7 +772,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { |
| 773 | } | 772 | } |
| 774 | 773 | ||
| 775 | match self.lower_return_type_notation_ty(bound, item_def_id, hir_ty.span) { | 774 | match self.lower_return_type_notation_ty(bound, item_def_id, hir_ty.span) { |
| 776 | Ok(ty) => Ty::new_alias(tcx, ty::Projection, ty), | 775 | Ok(ty) => Ty::new_alias(tcx, ty), |
| 777 | Err(guar) => Ty::new_error(tcx, guar), | 776 | Err(guar) => Ty::new_error(tcx, guar), |
| 778 | } | 777 | } |
| 779 | } | 778 | } |
| ... | @@ -833,8 +832,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { | ... | @@ -833,8 +832,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { |
| 833 | // Next, we need to check that the return-type notation is being used on | 832 | // Next, we need to check that the return-type notation is being used on |
| 834 | // an RPITIT (return-position impl trait in trait) or AFIT (async fn in trait). | 833 | // an RPITIT (return-position impl trait in trait) or AFIT (async fn in trait). |
| 835 | let output = tcx.fn_sig(item_def_id).skip_binder().output(); | 834 | let output = tcx.fn_sig(item_def_id).skip_binder().output(); |
| 836 | let output = if let ty::Alias(ty::Projection, alias_ty) = *output.skip_binder().kind() | 835 | let output = if let ty::Alias(alias_ty) = *output.skip_binder().kind() |
| 837 | && tcx.is_impl_trait_in_trait(alias_ty.def_id) | 836 | && let ty::AliasTy { kind: ty::Projection { def_id: projection_def_id }, .. } = alias_ty |
| 837 | && tcx.is_impl_trait_in_trait(projection_def_id) | ||
| 838 | { | 838 | { |
| 839 | alias_ty | 839 | alias_ty |
| 840 | } else { | 840 | } else { |
compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs+8-4| ... | @@ -1157,8 +1157,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { | ... | @@ -1157,8 +1157,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { |
| 1157 | // Type aliases defined in crates that have the | 1157 | // Type aliases defined in crates that have the |
| 1158 | // feature `lazy_type_alias` enabled get encoded as a type alias that normalization will | 1158 | // feature `lazy_type_alias` enabled get encoded as a type alias that normalization will |
| 1159 | // then actually instantiate the where bounds of. | 1159 | // then actually instantiate the where bounds of. |
| 1160 | let alias_ty = ty::AliasTy::new_from_args(tcx, did, args); | 1160 | let alias_ty = ty::AliasTy::new_from_args(tcx, ty::Free { def_id: did }, args); |
| 1161 | Ty::new_alias(tcx, ty::Free, alias_ty) | 1161 | Ty::new_alias(tcx, alias_ty) |
| 1162 | } else { | 1162 | } else { |
| 1163 | tcx.at(span).type_of(did).instantiate(tcx, args) | 1163 | tcx.at(span).type_of(did).instantiate(tcx, args) |
| 1164 | } | 1164 | } |
| ... | @@ -1412,8 +1412,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { | ... | @@ -1412,8 +1412,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { |
| 1412 | LowerTypeRelativePathMode::Type(permit_variants), | 1412 | LowerTypeRelativePathMode::Type(permit_variants), |
| 1413 | )? { | 1413 | )? { |
| 1414 | TypeRelativePath::AssocItem(def_id, args) => { | 1414 | TypeRelativePath::AssocItem(def_id, args) => { |
| 1415 | let alias_ty = ty::AliasTy::new_from_args(tcx, def_id, args); | 1415 | let alias_ty = ty::AliasTy::new_from_args( |
| 1416 | let ty = Ty::new_alias(tcx, alias_ty.kind(tcx), alias_ty); | 1416 | tcx, |
| 1417 | ty::AliasTyKind::new_from_def_id(tcx, def_id), | ||
| 1418 | args, | ||
| 1419 | ); | ||
| 1420 | let ty = Ty::new_alias(tcx, alias_ty); | ||
| 1417 | let ty = self.check_param_uses_if_mcg(ty, span, false); | 1421 | let ty = self.check_param_uses_if_mcg(ty, span, false); |
| 1418 | Ok((ty, tcx.def_kind(def_id), def_id)) | 1422 | Ok((ty, tcx.def_kind(def_id), def_id)) |
| 1419 | } | 1423 | } |
compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs+9-9| ... | @@ -157,21 +157,21 @@ fn insert_required_predicates_to_be_wf<'tcx>( | ... | @@ -157,21 +157,21 @@ fn insert_required_predicates_to_be_wf<'tcx>( |
| 157 | ); | 157 | ); |
| 158 | } | 158 | } |
| 159 | 159 | ||
| 160 | ty::Alias(ty::Free, alias) => { | 160 | ty::Alias(ty::AliasTy { kind: ty::Free { def_id }, args, .. }) => { |
| 161 | // This corresponds to a type like `Type<'a, T>`. | 161 | // This corresponds to a type like `Type<'a, T>`. |
| 162 | // We check inferred and explicit predicates. | 162 | // We check inferred and explicit predicates. |
| 163 | debug!("Free"); | 163 | debug!("Free"); |
| 164 | check_inferred_predicates( | 164 | check_inferred_predicates( |
| 165 | tcx, | 165 | tcx, |
| 166 | alias.def_id, | 166 | def_id, |
| 167 | alias.args, | 167 | args, |
| 168 | global_inferred_outlives, | 168 | global_inferred_outlives, |
| 169 | required_predicates, | 169 | required_predicates, |
| 170 | ); | 170 | ); |
| 171 | check_explicit_predicates( | 171 | check_explicit_predicates( |
| 172 | tcx, | 172 | tcx, |
| 173 | alias.def_id, | 173 | def_id, |
| 174 | alias.args, | 174 | args, |
| 175 | required_predicates, | 175 | required_predicates, |
| 176 | explicit_map, | 176 | explicit_map, |
| 177 | None, | 177 | None, |
| ... | @@ -203,15 +203,15 @@ fn insert_required_predicates_to_be_wf<'tcx>( | ... | @@ -203,15 +203,15 @@ fn insert_required_predicates_to_be_wf<'tcx>( |
| 203 | } | 203 | } |
| 204 | } | 204 | } |
| 205 | 205 | ||
| 206 | ty::Alias(ty::Projection, alias) => { | 206 | ty::Alias(ty::AliasTy { kind: ty::Projection { def_id }, args, .. }) => { |
| 207 | // This corresponds to a type like `<() as Trait<'a, T>>::Type`. | 207 | // This corresponds to a type like `<() as Trait<'a, T>>::Type`. |
| 208 | // We only use the explicit predicates of the trait but | 208 | // We only use the explicit predicates of the trait but |
| 209 | // not the ones of the associated type itself. | 209 | // not the ones of the associated type itself. |
| 210 | debug!("Projection"); | 210 | debug!("Projection"); |
| 211 | check_explicit_predicates( | 211 | check_explicit_predicates( |
| 212 | tcx, | 212 | tcx, |
| 213 | tcx.parent(alias.def_id), | 213 | tcx.parent(def_id), |
| 214 | alias.args, | 214 | args, |
| 215 | required_predicates, | 215 | required_predicates, |
| 216 | explicit_map, | 216 | explicit_map, |
| 217 | None, | 217 | None, |
| ... | @@ -219,7 +219,7 @@ fn insert_required_predicates_to_be_wf<'tcx>( | ... | @@ -219,7 +219,7 @@ fn insert_required_predicates_to_be_wf<'tcx>( |
| 219 | } | 219 | } |
| 220 | 220 | ||
| 221 | // FIXME(inherent_associated_types): Use the explicit predicates from the parent impl. | 221 | // FIXME(inherent_associated_types): Use the explicit predicates from the parent impl. |
| 222 | ty::Alias(ty::Inherent, _) => {} | 222 | ty::Alias(ty::AliasTy { kind: ty::Inherent { .. }, .. }) => {} |
| 223 | 223 | ||
| 224 | _ => {} | 224 | _ => {} |
| 225 | } | 225 | } |
compiler/rustc_hir_analysis/src/variance/constraints.rs+8-4| ... | @@ -273,12 +273,16 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { | ... | @@ -273,12 +273,16 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { |
| 273 | self.add_constraints_from_args(current, def.did(), args, variance); | 273 | self.add_constraints_from_args(current, def.did(), args, variance); |
| 274 | } | 274 | } |
| 275 | 275 | ||
| 276 | ty::Alias(ty::Projection | ty::Inherent | ty::Opaque, ref data) => { | 276 | ty::Alias(ty::AliasTy { |
| 277 | self.add_constraints_from_invariant_args(current, data.args, variance); | 277 | kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Opaque { .. }, |
| 278 | args, | ||
| 279 | .. | ||
| 280 | }) => { | ||
| 281 | self.add_constraints_from_invariant_args(current, args, variance); | ||
| 278 | } | 282 | } |
| 279 | 283 | ||
| 280 | ty::Alias(ty::Free, ref data) => { | 284 | ty::Alias(ty::AliasTy { kind: ty::Free { def_id }, args, .. }) => { |
| 281 | self.add_constraints_from_args(current, data.def_id, data.args, variance); | 285 | self.add_constraints_from_args(current, def_id, args, variance); |
| 282 | } | 286 | } |
| 283 | 287 | ||
| 284 | ty::Dynamic(data, r) => { | 288 | ty::Dynamic(data, r) => { |
compiler/rustc_hir_analysis/src/variance/mod.rs+1-1| ... | @@ -143,7 +143,7 @@ fn variance_of_opaque( | ... | @@ -143,7 +143,7 @@ fn variance_of_opaque( |
| 143 | #[instrument(level = "trace", skip(self), ret)] | 143 | #[instrument(level = "trace", skip(self), ret)] |
| 144 | fn visit_ty(&mut self, t: Ty<'tcx>) { | 144 | fn visit_ty(&mut self, t: Ty<'tcx>) { |
| 145 | match t.kind() { | 145 | match t.kind() { |
| 146 | ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => { | 146 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { |
| 147 | self.visit_opaque(*def_id, args); | 147 | self.visit_opaque(*def_id, args); |
| 148 | } | 148 | } |
| 149 | _ => t.super_visit_with(self), | 149 | _ => t.super_visit_with(self), |
compiler/rustc_hir_typeck/src/_match.rs+4-2| ... | @@ -246,7 +246,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | ... | @@ -246,7 +246,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 246 | self.may_coerce(arm_ty, ret_ty) | 246 | self.may_coerce(arm_ty, ret_ty) |
| 247 | && prior_arm.is_none_or(|(_, ty, _)| self.may_coerce(ty, ret_ty)) | 247 | && prior_arm.is_none_or(|(_, ty, _)| self.may_coerce(ty, ret_ty)) |
| 248 | // The match arms need to unify for the case of `impl Trait`. | 248 | // The match arms need to unify for the case of `impl Trait`. |
| 249 | && !matches!(ret_ty.kind(), ty::Alias(ty::Opaque, ..)) | 249 | && !matches!(ret_ty.kind(), ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. })) |
| 250 | } | 250 | } |
| 251 | _ => false, | 251 | _ => false, |
| 252 | }; | 252 | }; |
| ... | @@ -533,7 +533,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | ... | @@ -533,7 +533,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 533 | let expected_ty = expectation.to_option(self)?; | 533 | let expected_ty = expectation.to_option(self)?; |
| 534 | let (def_id, args) = match *expected_ty.kind() { | 534 | let (def_id, args) = match *expected_ty.kind() { |
| 535 | // FIXME: Could also check that the RPIT is not defined | 535 | // FIXME: Could also check that the RPIT is not defined |
| 536 | ty::Alias(ty::Opaque, alias_ty) => (alias_ty.def_id.as_local()?, alias_ty.args), | 536 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { |
| 537 | (def_id.as_local()?, args) | ||
| 538 | } | ||
| 537 | // FIXME(-Znext-solver=no): Remove this branch once `replace_opaque_types_with_infer` is gone. | 539 | // FIXME(-Znext-solver=no): Remove this branch once `replace_opaque_types_with_infer` is gone. |
| 538 | ty::Infer(ty::TyVar(_)) => self | 540 | ty::Infer(ty::TyVar(_)) => self |
| 539 | .inner | 541 | .inner |
compiler/rustc_hir_typeck/src/cast.rs+1-1| ... | @@ -122,7 +122,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | ... | @@ -122,7 +122,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 122 | // Pointers to foreign types are thin, despite being unsized | 122 | // Pointers to foreign types are thin, despite being unsized |
| 123 | ty::Foreign(..) => Some(PointerKind::Thin), | 123 | ty::Foreign(..) => Some(PointerKind::Thin), |
| 124 | // We should really try to normalize here. | 124 | // We should really try to normalize here. |
| 125 | ty::Alias(_, pi) => Some(PointerKind::OfAlias(pi)), | 125 | ty::Alias(pi) => Some(PointerKind::OfAlias(pi)), |
| 126 | ty::Param(p) => Some(PointerKind::OfParam(p)), | 126 | ty::Param(p) => Some(PointerKind::OfParam(p)), |
| 127 | // Insufficient type information. | 127 | // Insufficient type information. |
| 128 | ty::Placeholder(..) | ty::Bound(..) | ty::Infer(_) => None, | 128 | ty::Placeholder(..) | ty::Bound(..) | ty::Infer(_) => None, |
compiler/rustc_hir_typeck/src/closure.rs+3-3| ... | @@ -305,7 +305,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | ... | @@ -305,7 +305,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 305 | closure_kind: hir::ClosureKind, | 305 | closure_kind: hir::ClosureKind, |
| 306 | ) -> (Option<ExpectedSig<'tcx>>, Option<ty::ClosureKind>) { | 306 | ) -> (Option<ExpectedSig<'tcx>>, Option<ty::ClosureKind>) { |
| 307 | match *expected_ty.kind() { | 307 | match *expected_ty.kind() { |
| 308 | ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => self | 308 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => self |
| 309 | .deduce_closure_signature_from_predicates( | 309 | .deduce_closure_signature_from_predicates( |
| 310 | expected_ty, | 310 | expected_ty, |
| 311 | closure_kind, | 311 | closure_kind, |
| ... | @@ -1017,14 +1017,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | ... | @@ -1017,14 +1017,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 1017 | get_future_output(obligation.predicate, obligation.cause.span) | 1017 | get_future_output(obligation.predicate, obligation.cause.span) |
| 1018 | })? | 1018 | })? |
| 1019 | } | 1019 | } |
| 1020 | ty::Alias(ty::Projection, _) => { | 1020 | ty::Alias(ty::AliasTy { kind: ty::Projection { .. }, .. }) => { |
| 1021 | return Some(Ty::new_error_with_message( | 1021 | return Some(Ty::new_error_with_message( |
| 1022 | self.tcx, | 1022 | self.tcx, |
| 1023 | closure_span, | 1023 | closure_span, |
| 1024 | "this projection should have been projected to an opaque type", | 1024 | "this projection should have been projected to an opaque type", |
| 1025 | )); | 1025 | )); |
| 1026 | } | 1026 | } |
| 1027 | ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => self | 1027 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => self |
| 1028 | .tcx | 1028 | .tcx |
| 1029 | .explicit_item_self_bounds(def_id) | 1029 | .explicit_item_self_bounds(def_id) |
| 1030 | .iter_instantiated_copied(self.tcx, args) | 1030 | .iter_instantiated_copied(self.tcx, args) |
compiler/rustc_hir_typeck/src/expr.rs+1-1| ... | @@ -2978,7 +2978,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | ... | @@ -2978,7 +2978,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 2978 | err.span_label(ident.span, "unknown field"); | 2978 | err.span_label(ident.span, "unknown field"); |
| 2979 | self.point_at_param_definition(&mut err, param_ty); | 2979 | self.point_at_param_definition(&mut err, param_ty); |
| 2980 | } | 2980 | } |
| 2981 | ty::Alias(ty::Opaque, _) => { | 2981 | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) => { |
| 2982 | self.suggest_await_on_field_access(&mut err, ident, base, base_ty.peel_refs()); | 2982 | self.suggest_await_on_field_access(&mut err, ident, base, base_ty.peel_refs()); |
| 2983 | } | 2983 | } |
| 2984 | _ => { | 2984 | _ => { |
compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs+3-1| ... | @@ -1058,7 +1058,9 @@ fn find_param_in_ty<'tcx>( | ... | @@ -1058,7 +1058,9 @@ fn find_param_in_ty<'tcx>( |
| 1058 | return true; | 1058 | return true; |
| 1059 | } | 1059 | } |
| 1060 | if let ty::GenericArgKind::Type(ty) = arg.kind() | 1060 | if let ty::GenericArgKind::Type(ty) = arg.kind() |
| 1061 | && let ty::Alias(ty::Projection | ty::Inherent, ..) = ty.kind() | 1061 | && let ty::Alias(ty::AliasTy { |
| 1062 | kind: ty::Projection { .. } | ty::Inherent { .. }, .. | ||
| 1063 | }) = ty.kind() | ||
| 1062 | { | 1064 | { |
| 1063 | // This logic may seem a bit strange, but typically when | 1065 | // This logic may seem a bit strange, but typically when |
| 1064 | // we have a projection type in a function signature, the | 1066 | // we have a projection type in a function signature, the |
compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs+1-1| ... | @@ -1417,7 +1417,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | ... | @@ -1417,7 +1417,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 1417 | } | 1417 | } |
| 1418 | } | 1418 | } |
| 1419 | } | 1419 | } |
| 1420 | ty::Alias(ty::Opaque, ty::AliasTy { def_id: new_def_id, .. }) | 1420 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: new_def_id }, .. }) |
| 1421 | | ty::Closure(new_def_id, _) | 1421 | | ty::Closure(new_def_id, _) |
| 1422 | | ty::FnDef(new_def_id, _) => { | 1422 | | ty::FnDef(new_def_id, _) => { |
| 1423 | def_id = new_def_id; | 1423 | def_id = new_def_id; |
compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs+9-5| ... | @@ -403,9 +403,10 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> { | ... | @@ -403,9 +403,10 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> { |
| 403 | match ty.kind() { | 403 | match ty.kind() { |
| 404 | ty::Adt(adt_def, _) => Some(*adt_def), | 404 | ty::Adt(adt_def, _) => Some(*adt_def), |
| 405 | // FIXME(#104767): Should we handle bound regions here? | 405 | // FIXME(#104767): Should we handle bound regions here? |
| 406 | ty::Alias(ty::Projection | ty::Inherent | ty::Free, _) | 406 | ty::Alias(ty::AliasTy { |
| 407 | if !ty.has_escaping_bound_vars() => | 407 | kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Free { .. }, |
| 408 | { | 408 | .. |
| 409 | }) if !ty.has_escaping_bound_vars() => { | ||
| 409 | if self.next_trait_solver() { | 410 | if self.next_trait_solver() { |
| 410 | self.try_structurally_resolve_type(span, ty).ty_adt_def() | 411 | self.try_structurally_resolve_type(span, ty).ty_adt_def() |
| 411 | } else { | 412 | } else { |
| ... | @@ -423,8 +424,11 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> { | ... | @@ -423,8 +424,11 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> { |
| 423 | // WF obligations that are registered elsewhere, but they have a | 424 | // WF obligations that are registered elsewhere, but they have a |
| 424 | // better cause code assigned to them in `add_required_obligations_for_hir`. | 425 | // better cause code assigned to them in `add_required_obligations_for_hir`. |
| 425 | // This means that they should shadow obligations with worse spans. | 426 | // This means that they should shadow obligations with worse spans. |
| 426 | if let ty::Alias(ty::Projection | ty::Free, ty::AliasTy { args, def_id, .. }) = | 427 | if let ty::Alias(ty::AliasTy { |
| 427 | ty.kind() | 428 | kind: ty::Projection { def_id } | ty::Free { def_id }, |
| 429 | args, | ||
| 430 | .. | ||
| 431 | }) = ty.kind() | ||
| 428 | { | 432 | { |
| 429 | self.add_required_obligations_for_hir(span, *def_id, args, hir_id); | 433 | self.add_required_obligations_for_hir(span, *def_id, args, hir_id); |
| 430 | } | 434 | } |
compiler/rustc_hir_typeck/src/method/probe.rs+2-2| ... | @@ -2041,9 +2041,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { | ... | @@ -2041,9 +2041,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { |
| 2041 | // HACK: opaque types will match anything for which their bounds hold. | 2041 | // HACK: opaque types will match anything for which their bounds hold. |
| 2042 | // Thus we need to prevent them from trying to match the `&_` autoref | 2042 | // Thus we need to prevent them from trying to match the `&_` autoref |
| 2043 | // candidates that get created for `&self` trait methods. | 2043 | // candidates that get created for `&self` trait methods. |
| 2044 | ty::Alias(ty::Opaque, alias_ty) | 2044 | &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }) |
| 2045 | if !self.next_trait_solver() | 2045 | if !self.next_trait_solver() |
| 2046 | && self.infcx.can_define_opaque_ty(alias_ty.def_id) | 2046 | && self.infcx.can_define_opaque_ty(def_id) |
| 2047 | && !xform_self_ty.is_ty_var() => | 2047 | && !xform_self_ty.is_ty_var() => |
| 2048 | { | 2048 | { |
| 2049 | return ProbeResult::NoMatch; | 2049 | return ProbeResult::NoMatch; |
compiler/rustc_hir_typeck/src/method/suggest.rs+7-2| ... | @@ -175,7 +175,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | ... | @@ -175,7 +175,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 175 | } | 175 | } |
| 176 | } | 176 | } |
| 177 | } | 177 | } |
| 178 | ty::Slice(..) | ty::Adt(..) | ty::Alias(ty::Opaque, _) => { | 178 | ty::Slice(..) |
| 179 | | ty::Adt(..) | ||
| 180 | | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) => { | ||
| 179 | for unsatisfied in unsatisfied_predicates.iter() { | 181 | for unsatisfied in unsatisfied_predicates.iter() { |
| 180 | if is_iterator_predicate(unsatisfied.0) { | 182 | if is_iterator_predicate(unsatisfied.0) { |
| 181 | return true; | 183 | return true; |
| ... | @@ -3632,7 +3634,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | ... | @@ -3632,7 +3634,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 3632 | | ty::Float(_) | 3634 | | ty::Float(_) |
| 3633 | | ty::Adt(_, _) | 3635 | | ty::Adt(_, _) |
| 3634 | | ty::Str | 3636 | | ty::Str |
| 3635 | | ty::Alias(ty::Projection | ty::Inherent, _) | 3637 | | ty::Alias(ty::AliasTy { |
| 3638 | kind: ty::Projection { .. } | ty::Inherent { .. }, | ||
| 3639 | .. | ||
| 3640 | }) | ||
| 3636 | | ty::Param(_) => format!("{deref_ty}"), | 3641 | | ty::Param(_) => format!("{deref_ty}"), |
| 3637 | // we need to test something like <&[_]>::len or <(&[u32])>::len | 3642 | // we need to test something like <&[_]>::len or <(&[u32])>::len |
| 3638 | // and Vec::function(); | 3643 | // and Vec::function(); |
compiler/rustc_hir_typeck/src/writeback.rs+7-6| ... | @@ -567,9 +567,10 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { | ... | @@ -567,9 +567,10 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { |
| 567 | for (opaque_type_key, hidden_type) in opaque_types { | 567 | for (opaque_type_key, hidden_type) in opaque_types { |
| 568 | let hidden_type = self.resolve(hidden_type, &hidden_type.span); | 568 | let hidden_type = self.resolve(hidden_type, &hidden_type.span); |
| 569 | let opaque_type_key = self.resolve(opaque_type_key, &hidden_type.span); | 569 | let opaque_type_key = self.resolve(opaque_type_key, &hidden_type.span); |
| 570 | if let ty::Alias(ty::Opaque, alias_ty) = hidden_type.ty.kind() | 570 | if let &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) = |
| 571 | && alias_ty.def_id == opaque_type_key.def_id.to_def_id() | 571 | hidden_type.ty.kind() |
| 572 | && alias_ty.args == opaque_type_key.args | 572 | && def_id == opaque_type_key.def_id.to_def_id() |
| 573 | && args == opaque_type_key.args | ||
| 573 | { | 574 | { |
| 574 | continue; | 575 | continue; |
| 575 | } | 576 | } |
| ... | @@ -1049,8 +1050,8 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for HasRecursiveOpaque<'_, 'tcx> { | ... | @@ -1049,8 +1050,8 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for HasRecursiveOpaque<'_, 'tcx> { |
| 1049 | type Result = ControlFlow<()>; | 1050 | type Result = ControlFlow<()>; |
| 1050 | 1051 | ||
| 1051 | fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result { | 1052 | fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result { |
| 1052 | if let ty::Alias(ty::Opaque, alias_ty) = *t.kind() | 1053 | if let ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) = *t.kind() |
| 1053 | && let Some(def_id) = alias_ty.def_id.as_local() | 1054 | && let Some(def_id) = def_id.as_local() |
| 1054 | { | 1055 | { |
| 1055 | if self.def_id == def_id { | 1056 | if self.def_id == def_id { |
| 1056 | return ControlFlow::Break(()); | 1057 | return ControlFlow::Break(()); |
| ... | @@ -1059,7 +1060,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for HasRecursiveOpaque<'_, 'tcx> { | ... | @@ -1059,7 +1060,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for HasRecursiveOpaque<'_, 'tcx> { |
| 1059 | if self.seen.insert(def_id) | 1060 | if self.seen.insert(def_id) |
| 1060 | && let Some(hidden_ty) = self.opaques.get(&def_id) | 1061 | && let Some(hidden_ty) = self.opaques.get(&def_id) |
| 1061 | { | 1062 | { |
| 1062 | hidden_ty.ty.instantiate(self.tcx, alias_ty.args).visit_with(self)?; | 1063 | hidden_ty.ty.instantiate(self.tcx, args).visit_with(self)?; |
| 1063 | } | 1064 | } |
| 1064 | } | 1065 | } |
| 1065 | 1066 |
compiler/rustc_infer/src/infer/mod.rs+1-1| ... | @@ -1022,7 +1022,7 @@ impl<'tcx> InferCtxt<'tcx> { | ... | @@ -1022,7 +1022,7 @@ impl<'tcx> InferCtxt<'tcx> { |
| 1022 | if opaque_sub_vid == ty_sub_vid { | 1022 | if opaque_sub_vid == ty_sub_vid { |
| 1023 | return Some(ty::AliasTy::new_from_args( | 1023 | return Some(ty::AliasTy::new_from_args( |
| 1024 | self.tcx, | 1024 | self.tcx, |
| 1025 | key.def_id.into(), | 1025 | ty::Opaque { def_id: key.def_id.into() }, |
| 1026 | key.args, | 1026 | key.args, |
| 1027 | )); | 1027 | )); |
| 1028 | } | 1028 | } |
compiler/rustc_infer/src/infer/opaque_types/mod.rs+18-13| ... | @@ -45,7 +45,7 @@ impl<'tcx> InferCtxt<'tcx> { | ... | @@ -45,7 +45,7 @@ impl<'tcx> InferCtxt<'tcx> { |
| 45 | lt_op: |lt| lt, | 45 | lt_op: |lt| lt, |
| 46 | ct_op: |ct| ct, | 46 | ct_op: |ct| ct, |
| 47 | ty_op: |ty| match *ty.kind() { | 47 | ty_op: |ty| match *ty.kind() { |
| 48 | ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) | 48 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }) |
| 49 | if self.can_define_opaque_ty(def_id) && !ty.has_escaping_bound_vars() => | 49 | if self.can_define_opaque_ty(def_id) && !ty.has_escaping_bound_vars() => |
| 50 | { | 50 | { |
| 51 | let def_span = self.tcx.def_span(def_id); | 51 | let def_span = self.tcx.def_span(def_id); |
| ... | @@ -85,7 +85,9 @@ impl<'tcx> InferCtxt<'tcx> { | ... | @@ -85,7 +85,9 @@ impl<'tcx> InferCtxt<'tcx> { |
| 85 | ) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>, TypeError<'tcx>> { | 85 | ) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>, TypeError<'tcx>> { |
| 86 | debug_assert!(!self.next_trait_solver()); | 86 | debug_assert!(!self.next_trait_solver()); |
| 87 | let process = |a: Ty<'tcx>, b: Ty<'tcx>| match *a.kind() { | 87 | let process = |a: Ty<'tcx>, b: Ty<'tcx>| match *a.kind() { |
| 88 | ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) if def_id.is_local() => { | 88 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) |
| 89 | if def_id.is_local() => | ||
| 90 | { | ||
| 89 | let def_id = def_id.expect_local(); | 91 | let def_id = def_id.expect_local(); |
| 90 | if let ty::TypingMode::Coherence = self.typing_mode() { | 92 | if let ty::TypingMode::Coherence = self.typing_mode() { |
| 91 | // See comment on `insert_hidden_type` for why this is sufficient in coherence | 93 | // See comment on `insert_hidden_type` for why this is sufficient in coherence |
| ... | @@ -134,7 +136,9 @@ impl<'tcx> InferCtxt<'tcx> { | ... | @@ -134,7 +136,9 @@ impl<'tcx> InferCtxt<'tcx> { |
| 134 | return None; | 136 | return None; |
| 135 | } | 137 | } |
| 136 | 138 | ||
| 137 | if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }) = *b.kind() { | 139 | if let ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: b_def_id }, .. }) = |
| 140 | *b.kind() | ||
| 141 | { | ||
| 138 | // We could accept this, but there are various ways to handle this situation, | 142 | // We could accept this, but there are various ways to handle this situation, |
| 139 | // and we don't want to make a decision on it right now. Likely this case is so | 143 | // and we don't want to make a decision on it right now. Likely this case is so |
| 140 | // super rare anyway, that no one encounters it in practice. It does occur | 144 | // super rare anyway, that no one encounters it in practice. It does occur |
| ... | @@ -314,12 +318,13 @@ impl<'tcx> InferCtxt<'tcx> { | ... | @@ -314,12 +318,13 @@ impl<'tcx> InferCtxt<'tcx> { |
| 314 | // but we can eagerly register inference variables for them. | 318 | // but we can eagerly register inference variables for them. |
| 315 | // FIXME(RPITIT): Don't replace RPITITs with inference vars. | 319 | // FIXME(RPITIT): Don't replace RPITITs with inference vars. |
| 316 | // FIXME(inherent_associated_types): Extend this to support `ty::Inherent`, too. | 320 | // FIXME(inherent_associated_types): Extend this to support `ty::Inherent`, too. |
| 317 | ty::Alias(ty::Projection, projection_ty) | 321 | ty::Alias( |
| 318 | if !projection_ty.has_escaping_bound_vars() | 322 | projection_ty @ ty::AliasTy { kind: ty::Projection { def_id }, .. }, |
| 319 | && !tcx.is_impl_trait_in_trait(projection_ty.def_id) | 323 | ) if !projection_ty.has_escaping_bound_vars() |
| 320 | && !self.next_trait_solver() => | 324 | && !tcx.is_impl_trait_in_trait(def_id) |
| 325 | && !self.next_trait_solver() => | ||
| 321 | { | 326 | { |
| 322 | let ty_var = self.next_ty_var(self.tcx.def_span(projection_ty.def_id)); | 327 | let ty_var = self.next_ty_var(self.tcx.def_span(def_id)); |
| 323 | goals.push(Goal::new( | 328 | goals.push(Goal::new( |
| 324 | self.tcx, | 329 | self.tcx, |
| 325 | param_env, | 330 | param_env, |
| ... | @@ -334,11 +339,11 @@ impl<'tcx> InferCtxt<'tcx> { | ... | @@ -334,11 +339,11 @@ impl<'tcx> InferCtxt<'tcx> { |
| 334 | } | 339 | } |
| 335 | // Replace all other mentions of the same opaque type with the hidden type, | 340 | // Replace all other mentions of the same opaque type with the hidden type, |
| 336 | // as the bounds must hold on the hidden type after all. | 341 | // as the bounds must hold on the hidden type after all. |
| 337 | ty::Alias(ty::Opaque, ty::AliasTy { def_id: def_id2, args: args2, .. }) | 342 | ty::Alias(ty::AliasTy { |
| 338 | if def_id == def_id2 && args == args2 => | 343 | kind: ty::Opaque { def_id: def_id2 }, |
| 339 | { | 344 | args: args2, |
| 340 | hidden_ty | 345 | .. |
| 341 | } | 346 | }) if def_id == def_id2 && args == args2 => hidden_ty, |
| 342 | _ => ty, | 347 | _ => ty, |
| 343 | }, | 348 | }, |
| 344 | lt_op: |lt| lt, | 349 | lt_op: |lt| lt, |
compiler/rustc_infer/src/infer/outlives/for_liveness.rs+3-3| ... | @@ -55,11 +55,11 @@ where | ... | @@ -55,11 +55,11 @@ where |
| 55 | // either `'static` or a unique outlives region, and if one is | 55 | // either `'static` or a unique outlives region, and if one is |
| 56 | // found, we just need to prove that that region is still live. | 56 | // found, we just need to prove that that region is still live. |
| 57 | // If one is not found, then we continue to walk through the alias. | 57 | // If one is not found, then we continue to walk through the alias. |
| 58 | ty::Alias(kind, ty::AliasTy { def_id, args, .. }) => { | 58 | ty::Alias(ty::AliasTy { kind, args, .. }) => { |
| 59 | let tcx = self.tcx; | 59 | let tcx = self.tcx; |
| 60 | let param_env = self.param_env; | 60 | let param_env = self.param_env; |
| 61 | let outlives_bounds: Vec<_> = tcx | 61 | let outlives_bounds: Vec<_> = tcx |
| 62 | .item_bounds(def_id) | 62 | .item_bounds(kind.def_id()) |
| 63 | .iter_instantiated(tcx, args) | 63 | .iter_instantiated(tcx, args) |
| 64 | .chain(param_env.caller_bounds()) | 64 | .chain(param_env.caller_bounds()) |
| 65 | .filter_map(|clause| { | 65 | .filter_map(|clause| { |
| ... | @@ -93,7 +93,7 @@ where | ... | @@ -93,7 +93,7 @@ where |
| 93 | } else { | 93 | } else { |
| 94 | // Skip lifetime parameters that are not captured, since they do | 94 | // Skip lifetime parameters that are not captured, since they do |
| 95 | // not need to be live. | 95 | // not need to be live. |
| 96 | let variances = tcx.opt_alias_variances(kind, def_id); | 96 | let variances = tcx.opt_alias_variances(kind, kind.def_id()); |
| 97 | 97 | ||
| 98 | for (idx, s) in args.iter().enumerate() { | 98 | for (idx, s) in args.iter().enumerate() { |
| 99 | if variances.map(|variances| variances[idx]) != Some(ty::Bivariant) { | 99 | if variances.map(|variances| variances[idx]) != Some(ty::Bivariant) { |
compiler/rustc_infer/src/infer/outlives/obligations.rs+3-3| ... | @@ -468,13 +468,13 @@ where | ... | @@ -468,13 +468,13 @@ where |
| 468 | // the problem is to add `T: 'r`, which isn't true. So, if there are no | 468 | // the problem is to add `T: 'r`, which isn't true. So, if there are no |
| 469 | // inference variables, we use a verify constraint instead of adding | 469 | // inference variables, we use a verify constraint instead of adding |
| 470 | // edges, which winds up enforcing the same condition. | 470 | // edges, which winds up enforcing the same condition. |
| 471 | let kind = alias_ty.kind(self.tcx); | 471 | let kind = alias_ty.kind; |
| 472 | if approx_env_bounds.is_empty() | 472 | if approx_env_bounds.is_empty() |
| 473 | && trait_bounds.is_empty() | 473 | && trait_bounds.is_empty() |
| 474 | && (alias_ty.has_infer_regions() || kind == ty::Opaque) | 474 | && (alias_ty.has_infer_regions() || matches!(kind, ty::Opaque { .. })) |
| 475 | { | 475 | { |
| 476 | debug!("no declared bounds"); | 476 | debug!("no declared bounds"); |
| 477 | let opt_variances = self.tcx.opt_alias_variances(kind, alias_ty.def_id); | 477 | let opt_variances = self.tcx.opt_alias_variances(kind, kind.def_id()); |
| 478 | self.args_must_outlive(alias_ty.args, origin, region, opt_variances); | 478 | self.args_must_outlive(alias_ty.args, origin, region, opt_variances); |
| 479 | return; | 479 | return; |
| 480 | } | 480 | } |
compiler/rustc_infer/src/infer/outlives/verify.rs+5-5| ... | @@ -105,7 +105,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { | ... | @@ -105,7 +105,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { |
| 105 | // Search the env for where clauses like `P: 'a`. | 105 | // Search the env for where clauses like `P: 'a`. |
| 106 | let env_bounds = self.approx_declared_bounds_from_env(alias_ty).into_iter().map(|binder| { | 106 | let env_bounds = self.approx_declared_bounds_from_env(alias_ty).into_iter().map(|binder| { |
| 107 | if let Some(ty::OutlivesPredicate(ty, r)) = binder.no_bound_vars() | 107 | if let Some(ty::OutlivesPredicate(ty, r)) = binder.no_bound_vars() |
| 108 | && let ty::Alias(_, alias_ty_from_bound) = *ty.kind() | 108 | && let ty::Alias(alias_ty_from_bound) = *ty.kind() |
| 109 | && alias_ty_from_bound == alias_ty | 109 | && alias_ty_from_bound == alias_ty |
| 110 | { | 110 | { |
| 111 | // Micro-optimize if this is an exact match (this | 111 | // Micro-optimize if this is an exact match (this |
| ... | @@ -126,8 +126,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { | ... | @@ -126,8 +126,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { |
| 126 | // see the extensive comment in projection_must_outlive | 126 | // see the extensive comment in projection_must_outlive |
| 127 | let recursive_bound = { | 127 | let recursive_bound = { |
| 128 | let mut components = smallvec![]; | 128 | let mut components = smallvec![]; |
| 129 | let kind = alias_ty.kind(self.tcx); | 129 | compute_alias_components_recursive(self.tcx, alias_ty, &mut components); |
| 130 | compute_alias_components_recursive(self.tcx, kind, alias_ty, &mut components); | ||
| 131 | self.bound_from_components(&components) | 130 | self.bound_from_components(&components) |
| 132 | }; | 131 | }; |
| 133 | 132 | ||
| ... | @@ -236,7 +235,8 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { | ... | @@ -236,7 +235,8 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { |
| 236 | // And therefore we can safely use structural equality for alias types. | 235 | // And therefore we can safely use structural equality for alias types. |
| 237 | (GenericKind::Param(p1), ty::Param(p2)) if p1 == p2 => {} | 236 | (GenericKind::Param(p1), ty::Param(p2)) if p1 == p2 => {} |
| 238 | (GenericKind::Placeholder(p1), ty::Placeholder(p2)) if p1 == p2 => {} | 237 | (GenericKind::Placeholder(p1), ty::Placeholder(p2)) if p1 == p2 => {} |
| 239 | (GenericKind::Alias(a1), ty::Alias(_, a2)) if a1.def_id == a2.def_id => {} | 238 | (GenericKind::Alias(a1), ty::Alias(a2)) if a1.kind.def_id() == a2.kind.def_id() => { |
| 239 | } | ||
| 240 | _ => return None, | 240 | _ => return None, |
| 241 | } | 241 | } |
| 242 | 242 | ||
| ... | @@ -281,7 +281,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { | ... | @@ -281,7 +281,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { |
| 281 | alias_ty: ty::AliasTy<'tcx>, | 281 | alias_ty: ty::AliasTy<'tcx>, |
| 282 | ) -> impl Iterator<Item = ty::Region<'tcx>> { | 282 | ) -> impl Iterator<Item = ty::Region<'tcx>> { |
| 283 | let tcx = self.tcx; | 283 | let tcx = self.tcx; |
| 284 | let bounds = tcx.item_self_bounds(alias_ty.def_id); | 284 | let bounds = tcx.item_self_bounds(alias_ty.kind.def_id()); |
| 285 | trace!("{:#?}", bounds.skip_binder()); | 285 | trace!("{:#?}", bounds.skip_binder()); |
| 286 | bounds | 286 | bounds |
| 287 | .iter_instantiated(tcx, alias_ty.args) | 287 | .iter_instantiated(tcx, alias_ty.args) |
compiler/rustc_infer/src/infer/relate/generalize.rs+1-1| ... | @@ -635,7 +635,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> { | ... | @@ -635,7 +635,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> { |
| 635 | } | 635 | } |
| 636 | } | 636 | } |
| 637 | 637 | ||
| 638 | ty::Alias(_, data) => match self.structurally_relate_aliases { | 638 | ty::Alias(data) => match self.structurally_relate_aliases { |
| 639 | StructurallyRelateAliases::No => { | 639 | StructurallyRelateAliases::No => { |
| 640 | self.generalize_alias_term(data.into()).map(|v| v.expect_type()) | 640 | self.generalize_alias_term(data.into()).map(|v| v.expect_type()) |
| 641 | } | 641 | } |
compiler/rustc_infer/src/infer/relate/lattice.rs+4-4| ... | @@ -161,12 +161,12 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for LatticeOp<'_, 'tcx> { | ... | @@ -161,12 +161,12 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for LatticeOp<'_, 'tcx> { |
| 161 | } | 161 | } |
| 162 | 162 | ||
| 163 | ( | 163 | ( |
| 164 | &ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, .. }), | 164 | &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: a_def_id }, .. }), |
| 165 | &ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }), | 165 | &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: b_def_id }, .. }), |
| 166 | ) if a_def_id == b_def_id => super_combine_tys(infcx, self, a, b), | 166 | ) if a_def_id == b_def_id => super_combine_tys(infcx, self, a, b), |
| 167 | 167 | ||
| 168 | (&ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), _) | 168 | (&ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }), _) |
| 169 | | (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. })) | 169 | | (_, &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. })) |
| 170 | if def_id.is_local() && !infcx.next_trait_solver() => | 170 | if def_id.is_local() && !infcx.next_trait_solver() => |
| 171 | { | 171 | { |
| 172 | self.register_goals(infcx.handle_opaque_type( | 172 | self.register_goals(infcx.handle_opaque_type( |
compiler/rustc_infer/src/infer/relate/type_relating.rs+4-4| ... | @@ -184,14 +184,14 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for TypeRelating<'_, 'tcx> { | ... | @@ -184,14 +184,14 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for TypeRelating<'_, 'tcx> { |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | ( | 186 | ( |
| 187 | &ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, .. }), | 187 | &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: a_def_id }, .. }), |
| 188 | &ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }), | 188 | &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: b_def_id }, .. }), |
| 189 | ) if a_def_id == b_def_id => { | 189 | ) if a_def_id == b_def_id => { |
| 190 | super_combine_tys(infcx, self, a, b)?; | 190 | super_combine_tys(infcx, self, a, b)?; |
| 191 | } | 191 | } |
| 192 | 192 | ||
| 193 | (&ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), _) | 193 | (&ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }), _) |
| 194 | | (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. })) | 194 | | (_, &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. })) |
| 195 | if self.define_opaque_types == DefineOpaqueTypes::Yes && def_id.is_local() => | 195 | if self.define_opaque_types == DefineOpaqueTypes::Yes && def_id.is_local() => |
| 196 | { | 196 | { |
| 197 | self.register_goals(infcx.handle_opaque_type( | 197 | self.register_goals(infcx.handle_opaque_type( |
compiler/rustc_lint/src/foreign_modules.rs+12-3| ... | @@ -354,9 +354,18 @@ fn structurally_same_type_impl<'tcx>( | ... | @@ -354,9 +354,18 @@ fn structurally_same_type_impl<'tcx>( |
| 354 | | (ty::Closure(..), ty::Closure(..)) | 354 | | (ty::Closure(..), ty::Closure(..)) |
| 355 | | (ty::Coroutine(..), ty::Coroutine(..)) | 355 | | (ty::Coroutine(..), ty::Coroutine(..)) |
| 356 | | (ty::CoroutineWitness(..), ty::CoroutineWitness(..)) | 356 | | (ty::CoroutineWitness(..), ty::CoroutineWitness(..)) |
| 357 | | (ty::Alias(ty::Projection, ..), ty::Alias(ty::Projection, ..)) | 357 | | ( |
| 358 | | (ty::Alias(ty::Inherent, ..), ty::Alias(ty::Inherent, ..)) | 358 | ty::Alias(ty::AliasTy { kind: ty::Projection { .. }, .. }), |
| 359 | | (ty::Alias(ty::Opaque, ..), ty::Alias(ty::Opaque, ..)) => false, | 359 | ty::Alias(ty::AliasTy { kind: ty::Projection { .. }, .. }), |
| 360 | ) | ||
| 361 | | ( | ||
| 362 | ty::Alias(ty::AliasTy { kind: ty::Inherent { .. }, .. }), | ||
| 363 | ty::Alias(ty::AliasTy { kind: ty::Inherent { .. }, .. }), | ||
| 364 | ) | ||
| 365 | | ( | ||
| 366 | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }), | ||
| 367 | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }), | ||
| 368 | ) => false, | ||
| 360 | 369 | ||
| 361 | // These definitely should have been caught above. | 370 | // These definitely should have been caught above. |
| 362 | (ty::Bool, ty::Bool) | 371 | (ty::Bool, ty::Bool) |
compiler/rustc_lint/src/gpukernel_abi.rs+1-1| ... | @@ -115,7 +115,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for CheckGpuKernelTypes<'tcx> { | ... | @@ -115,7 +115,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for CheckGpuKernelTypes<'tcx> { |
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | ty::Adt(_, _) | 117 | ty::Adt(_, _) |
| 118 | | ty::Alias(_, _) | 118 | | ty::Alias(_) |
| 119 | | ty::Array(_, _) | 119 | | ty::Array(_, _) |
| 120 | | ty::Bound(_, _) | 120 | | ty::Bound(_, _) |
| 121 | | ty::Closure(_, _) | 121 | | ty::Closure(_, _) |
compiler/rustc_lint/src/impl_trait_overcaptures.rs+7-11| ... | @@ -242,16 +242,14 @@ where | ... | @@ -242,16 +242,14 @@ where |
| 242 | return; | 242 | return; |
| 243 | } | 243 | } |
| 244 | 244 | ||
| 245 | if let ty::Alias(ty::Projection, opaque_ty) = *t.kind() | 245 | if let ty::Alias(opaque_ty @ ty::AliasTy { kind: ty::Projection { def_id }, .. }) = |
| 246 | && self.tcx.is_impl_trait_in_trait(opaque_ty.def_id) | 246 | *t.kind() |
| 247 | && self.tcx.is_impl_trait_in_trait(def_id) | ||
| 247 | { | 248 | { |
| 248 | // visit the opaque of the RPITIT | 249 | // visit the opaque of the RPITIT |
| 249 | self.tcx | 250 | self.tcx.type_of(def_id).instantiate(self.tcx, opaque_ty.args).visit_with(self) |
| 250 | .type_of(opaque_ty.def_id) | 251 | } else if let ty::Alias(opaque_ty @ ty::AliasTy { kind: ty::Opaque { def_id}, .. }) = *t.kind() |
| 251 | .instantiate(self.tcx, opaque_ty.args) | 252 | && let Some(opaque_def_id) = def_id.as_local() |
| 252 | .visit_with(self) | ||
| 253 | } else if let ty::Alias(ty::Opaque, opaque_ty) = *t.kind() | ||
| 254 | && let Some(opaque_def_id) = opaque_ty.def_id.as_local() | ||
| 255 | // Don't recurse infinitely on an opaque | 253 | // Don't recurse infinitely on an opaque |
| 256 | && self.seen.insert(opaque_def_id) | 254 | && self.seen.insert(opaque_def_id) |
| 257 | // If it's owned by this function | 255 | // If it's owned by this function |
| ... | @@ -415,9 +413,7 @@ where | ... | @@ -415,9 +413,7 @@ where |
| 415 | // in this lint as well. Interestingly, one place that I expect this lint to fire | 413 | // in this lint as well. Interestingly, one place that I expect this lint to fire |
| 416 | // is for `impl for<'a> Bound<Out = impl Other>`, since `impl Other` will begin | 414 | // is for `impl for<'a> Bound<Out = impl Other>`, since `impl Other` will begin |
| 417 | // to capture `'a` in e2024 (even though late-bound vars in opaques are not allowed). | 415 | // to capture `'a` in e2024 (even though late-bound vars in opaques are not allowed). |
| 418 | for clause in | 416 | for clause in self.tcx.item_bounds(def_id).iter_instantiated(self.tcx, opaque_ty.args) { |
| 419 | self.tcx.item_bounds(opaque_ty.def_id).iter_instantiated(self.tcx, opaque_ty.args) | ||
| 420 | { | ||
| 421 | clause.visit_with(self) | 417 | clause.visit_with(self) |
| 422 | } | 418 | } |
| 423 | } | 419 | } |
compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs+4-3| ... | @@ -98,8 +98,9 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound { | ... | @@ -98,8 +98,9 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound { |
| 98 | let Some(proj_term) = proj.term.as_type() else { return }; | 98 | let Some(proj_term) = proj.term.as_type() else { return }; |
| 99 | 99 | ||
| 100 | // HACK: `impl Trait<Assoc = impl Trait2>` from an RPIT is "ok"... | 100 | // HACK: `impl Trait<Assoc = impl Trait2>` from an RPIT is "ok"... |
| 101 | if let ty::Alias(ty::Opaque, opaque_ty) = *proj_term.kind() | 101 | if let ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: opaque_def_id }, .. }) = |
| 102 | && cx.tcx.parent(opaque_ty.def_id) == def_id | 102 | *proj_term.kind() |
| 103 | && cx.tcx.parent(opaque_def_id) == def_id | ||
| 103 | && matches!( | 104 | && matches!( |
| 104 | opaque.origin, | 105 | opaque.origin, |
| 105 | hir::OpaqueTyOrigin::FnReturn { .. } | hir::OpaqueTyOrigin::AsyncFn { .. } | 106 | hir::OpaqueTyOrigin::FnReturn { .. } | hir::OpaqueTyOrigin::AsyncFn { .. } |
| ... | @@ -171,7 +172,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound { | ... | @@ -171,7 +172,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound { |
| 171 | // then we can emit a suggestion to add the bound. | 172 | // then we can emit a suggestion to add the bound. |
| 172 | let add_bound = match (proj_term.kind(), assoc_pred.kind().skip_binder()) { | 173 | let add_bound = match (proj_term.kind(), assoc_pred.kind().skip_binder()) { |
| 173 | ( | 174 | ( |
| 174 | ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), | 175 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }), |
| 175 | ty::ClauseKind::Trait(trait_pred), | 176 | ty::ClauseKind::Trait(trait_pred), |
| 176 | ) => Some(AddBound { | 177 | ) => Some(AddBound { |
| 177 | suggest_span: cx.tcx.def_span(*def_id).shrink_to_hi(), | 178 | suggest_span: cx.tcx.def_span(*def_id).shrink_to_hi(), |
compiler/rustc_lint/src/types/improper_ctypes.rs+10-8| ... | @@ -671,17 +671,16 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { | ... | @@ -671,17 +671,16 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { |
| 671 | 671 | ||
| 672 | // While opaque types are checked for earlier, if a projection in a struct field | 672 | // While opaque types are checked for earlier, if a projection in a struct field |
| 673 | // normalizes to an opaque type, then it will reach this branch. | 673 | // normalizes to an opaque type, then it will reach this branch. |
| 674 | ty::Alias(ty::Opaque, ..) => { | 674 | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) => { |
| 675 | FfiUnsafe { ty, reason: msg!("opaque types have no C equivalent"), help: None } | 675 | FfiUnsafe { ty, reason: msg!("opaque types have no C equivalent"), help: None } |
| 676 | } | 676 | } |
| 677 | 677 | ||
| 678 | // `extern "C" fn` functions can have type parameters, which may or may not be FFI-safe, | 678 | // `extern "C" fn` functions can have type parameters, which may or may not be FFI-safe, |
| 679 | // so they are currently ignored for the purposes of this lint. | 679 | // so they are currently ignored for the purposes of this lint. |
| 680 | ty::Param(..) | ty::Alias(ty::Projection | ty::Inherent, ..) | 680 | ty::Param(..) |
| 681 | if state.can_expect_ty_params() => | 681 | | ty::Alias(ty::AliasTy { |
| 682 | { | 682 | kind: ty::Projection { .. } | ty::Inherent { .. }, .. |
| 683 | FfiSafe | 683 | }) if state.can_expect_ty_params() => FfiSafe, |
| 684 | } | ||
| 685 | 684 | ||
| 686 | ty::UnsafeBinder(_) => FfiUnsafe { | 685 | ty::UnsafeBinder(_) => FfiUnsafe { |
| 687 | ty, | 686 | ty, |
| ... | @@ -690,7 +689,10 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { | ... | @@ -690,7 +689,10 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { |
| 690 | }, | 689 | }, |
| 691 | 690 | ||
| 692 | ty::Param(..) | 691 | ty::Param(..) |
| 693 | | ty::Alias(ty::Projection | ty::Inherent | ty::Free, ..) | 692 | | ty::Alias(ty::AliasTy { |
| 693 | kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Free { .. }, | ||
| 694 | .. | ||
| 695 | }) | ||
| 694 | | ty::Infer(..) | 696 | | ty::Infer(..) |
| 695 | | ty::Bound(..) | 697 | | ty::Bound(..) |
| 696 | | ty::Error(_) | 698 | | ty::Error(_) |
| ... | @@ -713,7 +715,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { | ... | @@ -713,7 +715,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { |
| 713 | return ControlFlow::Continue(()); | 715 | return ControlFlow::Continue(()); |
| 714 | } | 716 | } |
| 715 | 717 | ||
| 716 | if let ty::Alias(ty::Opaque, ..) = ty.kind() { | 718 | if let ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) = ty.kind() { |
| 717 | ControlFlow::Break(ty) | 719 | ControlFlow::Break(ty) |
| 718 | } else { | 720 | } else { |
| 719 | ty.super_visit_with(self) | 721 | ty.super_visit_with(self) |
compiler/rustc_lint/src/unused/must_use.rs+5-2| ... | @@ -204,7 +204,10 @@ pub fn is_ty_must_use<'tcx>( | ... | @@ -204,7 +204,10 @@ pub fn is_ty_must_use<'tcx>( |
| 204 | ty::Adt(def, _) => { | 204 | ty::Adt(def, _) => { |
| 205 | is_def_must_use(cx, def.did(), expr.span).map_or(IsTyMustUse::No, IsTyMustUse::Yes) | 205 | is_def_must_use(cx, def.did(), expr.span).map_or(IsTyMustUse::No, IsTyMustUse::Yes) |
| 206 | } | 206 | } |
| 207 | ty::Alias(ty::Opaque | ty::Projection, ty::AliasTy { def_id: def, .. }) => { | 207 | ty::Alias(ty::AliasTy { |
| 208 | kind: ty::Opaque { def_id: def } | ty::Projection { def_id: def }, | ||
| 209 | .. | ||
| 210 | }) => { | ||
| 208 | elaborate(cx.tcx, cx.tcx.explicit_item_self_bounds(def).iter_identity_copied()) | 211 | elaborate(cx.tcx, cx.tcx.explicit_item_self_bounds(def).iter_identity_copied()) |
| 209 | // We only care about self bounds for the impl-trait | 212 | // We only care about self bounds for the impl-trait |
| 210 | .filter_only_self() | 213 | .filter_only_self() |
| ... | @@ -316,7 +319,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults { | ... | @@ -316,7 +319,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults { |
| 316 | 319 | ||
| 317 | if let hir::ExprKind::Match(await_expr, _arms, hir::MatchSource::AwaitDesugar) = expr.kind | 320 | if let hir::ExprKind::Match(await_expr, _arms, hir::MatchSource::AwaitDesugar) = expr.kind |
| 318 | && let ty = cx.typeck_results().expr_ty(await_expr) | 321 | && let ty = cx.typeck_results().expr_ty(await_expr) |
| 319 | && let ty::Alias(ty::Opaque, ty::AliasTy { def_id: future_def_id, .. }) = ty.kind() | 322 | && let ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: future_def_id }, .. }) = ty.kind() |
| 320 | && cx.tcx.ty_is_opaque_future(ty) | 323 | && cx.tcx.ty_is_opaque_future(ty) |
| 321 | && let async_fn_def_id = cx.tcx.parent(*future_def_id) | 324 | && let async_fn_def_id = cx.tcx.parent(*future_def_id) |
| 322 | && matches!(cx.tcx.def_kind(async_fn_def_id), DefKind::Fn | DefKind::AssocFn) | 325 | && matches!(cx.tcx.def_kind(async_fn_def_id), DefKind::Fn | DefKind::AssocFn) |
compiler/rustc_middle/src/ty/context.rs+3-1| ... | @@ -2115,7 +2115,9 @@ impl<'tcx> TyCtxt<'tcx> { | ... | @@ -2115,7 +2115,9 @@ impl<'tcx> TyCtxt<'tcx> { |
| 2115 | 2115 | ||
| 2116 | /// Given a `ty`, return whether it's an `impl Future<...>`. | 2116 | /// Given a `ty`, return whether it's an `impl Future<...>`. |
| 2117 | pub fn ty_is_opaque_future(self, ty: Ty<'_>) -> bool { | 2117 | pub fn ty_is_opaque_future(self, ty: Ty<'_>) -> bool { |
| 2118 | let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *ty.kind() else { return false }; | 2118 | let ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }) = *ty.kind() else { |
| 2119 | return false; | ||
| 2120 | }; | ||
| 2119 | let future_trait = self.require_lang_item(LangItem::Future, DUMMY_SP); | 2121 | let future_trait = self.require_lang_item(LangItem::Future, DUMMY_SP); |
| 2120 | 2122 | ||
| 2121 | self.explicit_item_self_bounds(def_id).skip_binder().iter().any(|&(predicate, _)| { | 2123 | self.explicit_item_self_bounds(def_id).skip_binder().iter().any(|&(predicate, _)| { |
compiler/rustc_middle/src/ty/context/impl_interner.rs+11-12| ... | @@ -187,18 +187,17 @@ impl<'tcx> Interner for TyCtxt<'tcx> { | ... | @@ -187,18 +187,17 @@ impl<'tcx> Interner for TyCtxt<'tcx> { |
| 187 | self.adt_def(adt_def_id) | 187 | self.adt_def(adt_def_id) |
| 188 | } | 188 | } |
| 189 | 189 | ||
| 190 | fn alias_ty_kind(self, alias: ty::AliasTy<'tcx>) -> ty::AliasTyKind { | 190 | fn alias_ty_kind_from_def_id(self, def_id: DefId) -> ty::AliasTyKind<'tcx> { |
| 191 | match self.def_kind(alias.def_id) { | 191 | match self.def_kind(def_id) { |
| 192 | DefKind::AssocTy => { | 192 | DefKind::AssocTy |
| 193 | if let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(alias.def_id)) | 193 | if let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(def_id)) => |
| 194 | { | 194 | { |
| 195 | ty::Inherent | 195 | ty::Inherent { def_id } |
| 196 | } else { | ||
| 197 | ty::Projection | ||
| 198 | } | ||
| 199 | } | 196 | } |
| 200 | DefKind::OpaqueTy => ty::Opaque, | 197 | DefKind::AssocTy => ty::Projection { def_id }, |
| 201 | DefKind::TyAlias => ty::Free, | 198 | |
| 199 | DefKind::OpaqueTy => ty::Opaque { def_id }, | ||
| 200 | DefKind::TyAlias => ty::Free { def_id }, | ||
| 202 | kind => bug!("unexpected DefKind in AliasTy: {kind:?}"), | 201 | kind => bug!("unexpected DefKind in AliasTy: {kind:?}"), |
| 203 | } | 202 | } |
| 204 | } | 203 | } |
| ... | @@ -587,7 +586,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> { | ... | @@ -587,7 +586,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> { |
| 587 | // | 586 | // |
| 588 | // Impls which apply to an alias after normalization are handled by | 587 | // Impls which apply to an alias after normalization are handled by |
| 589 | // `assemble_candidates_after_normalizing_self_ty`. | 588 | // `assemble_candidates_after_normalizing_self_ty`. |
| 590 | ty::Alias(_, _) | ty::Placeholder(..) | ty::Error(_) => (), | 589 | ty::Alias(_) | ty::Placeholder(..) | ty::Error(_) => (), |
| 591 | 590 | ||
| 592 | // FIXME: These should ideally not exist as a self type. It would be nice for | 591 | // FIXME: These should ideally not exist as a self type. It would be nice for |
| 593 | // the builtin auto trait impls of coroutines to instead directly recurse | 592 | // the builtin auto trait impls of coroutines to instead directly recurse |
compiler/rustc_middle/src/ty/diagnostics.rs+5-5| ... | @@ -627,11 +627,11 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IsSuggestableVisitor<'tcx> { | ... | @@ -627,11 +627,11 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IsSuggestableVisitor<'tcx> { |
| 627 | return ControlFlow::Break(()); | 627 | return ControlFlow::Break(()); |
| 628 | } | 628 | } |
| 629 | 629 | ||
| 630 | Alias(Opaque, AliasTy { def_id, .. }) => { | 630 | Alias(AliasTy { kind: Opaque { def_id }, .. }) => { |
| 631 | let parent = self.tcx.parent(def_id); | 631 | let parent = self.tcx.parent(def_id); |
| 632 | let parent_ty = self.tcx.type_of(parent).instantiate_identity(); | 632 | let parent_ty = self.tcx.type_of(parent).instantiate_identity(); |
| 633 | if let DefKind::TyAlias | DefKind::AssocTy = self.tcx.def_kind(parent) | 633 | if let DefKind::TyAlias | DefKind::AssocTy = self.tcx.def_kind(parent) |
| 634 | && let Alias(Opaque, AliasTy { def_id: parent_opaque_def_id, .. }) = | 634 | && let Alias(AliasTy { kind: Opaque { def_id: parent_opaque_def_id }, .. }) = |
| 635 | *parent_ty.kind() | 635 | *parent_ty.kind() |
| 636 | && parent_opaque_def_id == def_id | 636 | && parent_opaque_def_id == def_id |
| 637 | { | 637 | { |
| ... | @@ -641,7 +641,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IsSuggestableVisitor<'tcx> { | ... | @@ -641,7 +641,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IsSuggestableVisitor<'tcx> { |
| 641 | } | 641 | } |
| 642 | } | 642 | } |
| 643 | 643 | ||
| 644 | Alias(Projection, AliasTy { def_id, .. }) | 644 | Alias(AliasTy { kind: Projection { def_id }, .. }) |
| 645 | if self.tcx.def_kind(def_id) != DefKind::AssocTy => | 645 | if self.tcx.def_kind(def_id) != DefKind::AssocTy => |
| 646 | { | 646 | { |
| 647 | return ControlFlow::Break(()); | 647 | return ControlFlow::Break(()); |
| ... | @@ -714,12 +714,12 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for MakeSuggestableFolder<'tcx> { | ... | @@ -714,12 +714,12 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for MakeSuggestableFolder<'tcx> { |
| 714 | placeholder | 714 | placeholder |
| 715 | } | 715 | } |
| 716 | 716 | ||
| 717 | Alias(Opaque, AliasTy { def_id, .. }) => { | 717 | Alias(AliasTy { kind: Opaque { def_id }, .. }) => { |
| 718 | let parent = self.tcx.parent(def_id); | 718 | let parent = self.tcx.parent(def_id); |
| 719 | let parent_ty = self.tcx.type_of(parent).instantiate_identity(); | 719 | let parent_ty = self.tcx.type_of(parent).instantiate_identity(); |
| 720 | if let hir::def::DefKind::TyAlias | hir::def::DefKind::AssocTy = | 720 | if let hir::def::DefKind::TyAlias | hir::def::DefKind::AssocTy = |
| 721 | self.tcx.def_kind(parent) | 721 | self.tcx.def_kind(parent) |
| 722 | && let Alias(Opaque, AliasTy { def_id: parent_opaque_def_id, .. }) = | 722 | && let Alias(AliasTy { kind: Opaque { def_id: parent_opaque_def_id }, .. }) = |
| 723 | *parent_ty.kind() | 723 | *parent_ty.kind() |
| 724 | && parent_opaque_def_id == def_id | 724 | && parent_opaque_def_id == def_id |
| 725 | { | 725 | { |
compiler/rustc_middle/src/ty/error.rs+10-10| ... | @@ -148,14 +148,12 @@ impl<'tcx> Ty<'tcx> { | ... | @@ -148,14 +148,12 @@ impl<'tcx> Ty<'tcx> { |
| 148 | ty::Infer(ty::FreshTy(_)) => "fresh type".into(), | 148 | ty::Infer(ty::FreshTy(_)) => "fresh type".into(), |
| 149 | ty::Infer(ty::FreshIntTy(_)) => "fresh integral type".into(), | 149 | ty::Infer(ty::FreshIntTy(_)) => "fresh integral type".into(), |
| 150 | ty::Infer(ty::FreshFloatTy(_)) => "fresh floating-point type".into(), | 150 | ty::Infer(ty::FreshFloatTy(_)) => "fresh floating-point type".into(), |
| 151 | ty::Alias(ty::Projection | ty::Inherent, _) => "associated type".into(), | 151 | ty::Alias(ty::AliasTy { |
| 152 | kind: ty::Projection { .. } | ty::Inherent { .. }, .. | ||
| 153 | }) => "associated type".into(), | ||
| 152 | ty::Param(p) => format!("type parameter `{p}`").into(), | 154 | ty::Param(p) => format!("type parameter `{p}`").into(), |
| 153 | ty::Alias(ty::Opaque, ..) => { | 155 | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) => { |
| 154 | if tcx.ty_is_opaque_future(self) { | 156 | if tcx.ty_is_opaque_future(self) { "future".into() } else { "opaque type".into() } |
| 155 | "future".into() | ||
| 156 | } else { | ||
| 157 | "opaque type".into() | ||
| 158 | } | ||
| 159 | } | 157 | } |
| 160 | ty::Error(_) => "type error".into(), | 158 | ty::Error(_) => "type error".into(), |
| 161 | _ => { | 159 | _ => { |
| ... | @@ -209,10 +207,12 @@ impl<'tcx> Ty<'tcx> { | ... | @@ -209,10 +207,12 @@ impl<'tcx> Ty<'tcx> { |
| 209 | ty::Tuple(..) => "tuple".into(), | 207 | ty::Tuple(..) => "tuple".into(), |
| 210 | ty::Placeholder(..) => "higher-ranked type".into(), | 208 | ty::Placeholder(..) => "higher-ranked type".into(), |
| 211 | ty::Bound(..) => "bound type variable".into(), | 209 | ty::Bound(..) => "bound type variable".into(), |
| 212 | ty::Alias(ty::Projection | ty::Inherent, _) => "associated type".into(), | 210 | ty::Alias(ty::AliasTy { |
| 213 | ty::Alias(ty::Free, _) => "type alias".into(), | 211 | kind: ty::Projection { .. } | ty::Inherent { .. }, .. |
| 212 | }) => "associated type".into(), | ||
| 213 | ty::Alias(ty::AliasTy { kind: ty::Free { .. }, .. }) => "type alias".into(), | ||
| 214 | ty::Param(_) => "type parameter".into(), | 214 | ty::Param(_) => "type parameter".into(), |
| 215 | ty::Alias(ty::Opaque, ..) => "opaque type".into(), | 215 | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) => "opaque type".into(), |
| 216 | } | 216 | } |
| 217 | } | 217 | } |
| 218 | } | 218 | } |
compiler/rustc_middle/src/ty/generic_args.rs+3| ... | @@ -50,14 +50,17 @@ impl<'tcx> rustc_type_ir::inherent::GenericArgs<TyCtxt<'tcx>> for ty::GenericArg | ... | @@ -50,14 +50,17 @@ impl<'tcx> rustc_type_ir::inherent::GenericArgs<TyCtxt<'tcx>> for ty::GenericArg |
| 50 | self.rebase_onto(tcx, source_ancestor, target_args) | 50 | self.rebase_onto(tcx, source_ancestor, target_args) |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | #[track_caller] | ||
| 53 | fn type_at(self, i: usize) -> Ty<'tcx> { | 54 | fn type_at(self, i: usize) -> Ty<'tcx> { |
| 54 | self.type_at(i) | 55 | self.type_at(i) |
| 55 | } | 56 | } |
| 56 | 57 | ||
| 58 | #[track_caller] | ||
| 57 | fn region_at(self, i: usize) -> ty::Region<'tcx> { | 59 | fn region_at(self, i: usize) -> ty::Region<'tcx> { |
| 58 | self.region_at(i) | 60 | self.region_at(i) |
| 59 | } | 61 | } |
| 60 | 62 | ||
| 63 | #[track_caller] | ||
| 61 | fn const_at(self, i: usize) -> ty::Const<'tcx> { | 64 | fn const_at(self, i: usize) -> ty::Const<'tcx> { |
| 62 | self.const_at(i) | 65 | self.const_at(i) |
| 63 | } | 66 | } |
compiler/rustc_middle/src/ty/inhabitedness/mod.rs+8-6| ... | @@ -109,16 +109,18 @@ impl<'tcx> Ty<'tcx> { | ... | @@ -109,16 +109,18 @@ impl<'tcx> Ty<'tcx> { |
| 109 | InhabitedPredicate::True | 109 | InhabitedPredicate::True |
| 110 | } | 110 | } |
| 111 | Never => InhabitedPredicate::False, | 111 | Never => InhabitedPredicate::False, |
| 112 | Param(_) | Alias(ty::Inherent | ty::Projection | ty::Free, _) => { | 112 | Param(_) |
| 113 | InhabitedPredicate::GenericType(self) | 113 | | Alias(ty::AliasTy { |
| 114 | } | 114 | kind: ty::Inherent { .. } | ty::Projection { .. } | ty::Free { .. }, |
| 115 | Alias(ty::Opaque, alias_ty) => { | 115 | .. |
| 116 | match alias_ty.def_id.as_local() { | 116 | }) => InhabitedPredicate::GenericType(self), |
| 117 | &Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { | ||
| 118 | match def_id.as_local() { | ||
| 117 | // Foreign opaque is considered inhabited. | 119 | // Foreign opaque is considered inhabited. |
| 118 | None => InhabitedPredicate::True, | 120 | None => InhabitedPredicate::True, |
| 119 | // Local opaque type may possibly be revealed. | 121 | // Local opaque type may possibly be revealed. |
| 120 | Some(local_def_id) => { | 122 | Some(local_def_id) => { |
| 121 | let key = ty::OpaqueTypeKey { def_id: local_def_id, args: alias_ty.args }; | 123 | let key = ty::OpaqueTypeKey { def_id: local_def_id, args }; |
| 122 | InhabitedPredicate::OpaqueType(key) | 124 | InhabitedPredicate::OpaqueType(key) |
| 123 | } | 125 | } |
| 124 | } | 126 | } |
compiler/rustc_middle/src/ty/layout.rs+5-1| ... | @@ -385,7 +385,11 @@ impl<'tcx> SizeSkeleton<'tcx> { | ... | @@ -385,7 +385,11 @@ impl<'tcx> SizeSkeleton<'tcx> { |
| 385 | ); | 385 | ); |
| 386 | 386 | ||
| 387 | match tail.kind() { | 387 | match tail.kind() { |
| 388 | ty::Param(_) | ty::Alias(ty::Projection | ty::Inherent, _) => { | 388 | ty::Param(_) |
| 389 | | ty::Alias(ty::AliasTy { | ||
| 390 | kind: ty::Projection { .. } | ty::Inherent { .. }, | ||
| 391 | .. | ||
| 392 | }) => { | ||
| 389 | debug_assert!(tail.has_non_region_param()); | 393 | debug_assert!(tail.has_non_region_param()); |
| 390 | Ok(SizeSkeleton::Pointer { | 394 | Ok(SizeSkeleton::Pointer { |
| 391 | non_zero, | 395 | non_zero, |
compiler/rustc_middle/src/ty/mod.rs+5-5| ... | @@ -102,10 +102,10 @@ pub use self::region::{ | ... | @@ -102,10 +102,10 @@ pub use self::region::{ |
| 102 | EarlyParamRegion, LateParamRegion, LateParamRegionKind, Region, RegionKind, RegionVid, | 102 | EarlyParamRegion, LateParamRegion, LateParamRegionKind, Region, RegionKind, RegionVid, |
| 103 | }; | 103 | }; |
| 104 | pub use self::sty::{ | 104 | pub use self::sty::{ |
| 105 | AliasTy, Article, Binder, BoundConst, BoundRegion, BoundRegionKind, BoundTy, BoundTyKind, | 105 | AliasTy, AliasTyKind, Article, Binder, BoundConst, BoundRegion, BoundRegionKind, BoundTy, |
| 106 | BoundVariableKind, CanonicalPolyFnSig, CoroutineArgsExt, EarlyBinder, FnSig, InlineConstArgs, | 106 | BoundTyKind, BoundVariableKind, CanonicalPolyFnSig, CoroutineArgsExt, EarlyBinder, FnSig, |
| 107 | InlineConstArgsParts, ParamConst, ParamTy, PlaceholderConst, PlaceholderRegion, | 107 | InlineConstArgs, InlineConstArgsParts, ParamConst, ParamTy, PlaceholderConst, |
| 108 | PlaceholderType, PolyFnSig, TyKind, TypeAndMut, TypingMode, UpvarArgs, | 108 | PlaceholderRegion, PlaceholderType, PolyFnSig, TyKind, TypeAndMut, TypingMode, UpvarArgs, |
| 109 | }; | 109 | }; |
| 110 | pub use self::trait_def::TraitDef; | 110 | pub use self::trait_def::TraitDef; |
| 111 | pub use self::typeck_results::{ | 111 | pub use self::typeck_results::{ |
| ... | @@ -605,7 +605,7 @@ impl<'tcx> Term<'tcx> { | ... | @@ -605,7 +605,7 @@ impl<'tcx> Term<'tcx> { |
| 605 | pub fn to_alias_term(self) -> Option<AliasTerm<'tcx>> { | 605 | pub fn to_alias_term(self) -> Option<AliasTerm<'tcx>> { |
| 606 | match self.kind() { | 606 | match self.kind() { |
| 607 | TermKind::Ty(ty) => match *ty.kind() { | 607 | TermKind::Ty(ty) => match *ty.kind() { |
| 608 | ty::Alias(_kind, alias_ty) => Some(alias_ty.into()), | 608 | ty::Alias(alias_ty) => Some(alias_ty.into()), |
| 609 | _ => None, | 609 | _ => None, |
| 610 | }, | 610 | }, |
| 611 | TermKind::Const(ct) => match ct.kind() { | 611 | TermKind::Const(ct) => match ct.kind() { |
compiler/rustc_middle/src/ty/offload_meta.rs+1-1| ... | @@ -89,7 +89,7 @@ impl MappingFlags { | ... | @@ -89,7 +89,7 @@ impl MappingFlags { |
| 89 | MappingFlags::LITERAL | MappingFlags::IMPLICIT | 89 | MappingFlags::LITERAL | MappingFlags::IMPLICIT |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | ty::Adt(_, _) | ty::Tuple(_) | ty::Array(_, _) | ty::Alias(_, _) | ty::Param(_) => { | 92 | ty::Adt(_, _) | ty::Tuple(_) | ty::Array(_, _) | ty::Alias(_) | ty::Param(_) => { |
| 93 | MappingFlags::TO | 93 | MappingFlags::TO |
| 94 | } | 94 | } |
| 95 | 95 |
compiler/rustc_middle/src/ty/print/pretty.rs+10-5| ... | @@ -818,9 +818,14 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { | ... | @@ -818,9 +818,14 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { |
| 818 | } | 818 | } |
| 819 | } | 819 | } |
| 820 | ty::Foreign(def_id) => self.print_def_path(def_id, &[])?, | 820 | ty::Foreign(def_id) => self.print_def_path(def_id, &[])?, |
| 821 | ty::Alias(ty::Projection | ty::Inherent | ty::Free, ref data) => data.print(self)?, | 821 | ty::Alias( |
| 822 | ref data @ ty::AliasTy { | ||
| 823 | kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Free { .. }, | ||
| 824 | .. | ||
| 825 | }, | ||
| 826 | ) => data.print(self)?, | ||
| 822 | ty::Placeholder(placeholder) => placeholder.print(self)?, | 827 | ty::Placeholder(placeholder) => placeholder.print(self)?, |
| 823 | ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => { | 828 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { |
| 824 | // We use verbose printing in 'NO_QUERIES' mode, to | 829 | // We use verbose printing in 'NO_QUERIES' mode, to |
| 825 | // avoid needing to call `predicates_of`. This should | 830 | // avoid needing to call `predicates_of`. This should |
| 826 | // only affect certain debug messages (e.g. messages printed | 831 | // only affect certain debug messages (e.g. messages printed |
| ... | @@ -840,7 +845,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { | ... | @@ -840,7 +845,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { |
| 840 | DefKind::TyAlias | DefKind::AssocTy => { | 845 | DefKind::TyAlias | DefKind::AssocTy => { |
| 841 | // NOTE: I know we should check for NO_QUERIES here, but it's alright. | 846 | // NOTE: I know we should check for NO_QUERIES here, but it's alright. |
| 842 | // `type_of` on a type alias or assoc type should never cause a cycle. | 847 | // `type_of` on a type alias or assoc type should never cause a cycle. |
| 843 | if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: d, .. }) = | 848 | if let ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: d }, .. }) = |
| 844 | *self.tcx().type_of(parent).instantiate_identity().kind() | 849 | *self.tcx().type_of(parent).instantiate_identity().kind() |
| 845 | { | 850 | { |
| 846 | if d == def_id { | 851 | if d == def_id { |
| ... | @@ -1354,9 +1359,9 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { | ... | @@ -1354,9 +1359,9 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { |
| 1354 | let fn_args = if self.tcx().features().return_type_notation() | 1359 | let fn_args = if self.tcx().features().return_type_notation() |
| 1355 | && let Some(ty::ImplTraitInTraitData::Trait { fn_def_id, .. }) = | 1360 | && let Some(ty::ImplTraitInTraitData::Trait { fn_def_id, .. }) = |
| 1356 | self.tcx().opt_rpitit_info(def_id) | 1361 | self.tcx().opt_rpitit_info(def_id) |
| 1357 | && let ty::Alias(_, alias_ty) = | 1362 | && let ty::Alias(alias_ty) = |
| 1358 | self.tcx().fn_sig(fn_def_id).skip_binder().output().skip_binder().kind() | 1363 | self.tcx().fn_sig(fn_def_id).skip_binder().output().skip_binder().kind() |
| 1359 | && alias_ty.def_id == def_id | 1364 | && alias_ty.kind.def_id() == def_id |
| 1360 | && let generics = self.tcx().generics_of(fn_def_id) | 1365 | && let generics = self.tcx().generics_of(fn_def_id) |
| 1361 | // FIXME(return_type_notation): We only support lifetime params for now. | 1366 | // FIXME(return_type_notation): We only support lifetime params for now. |
| 1362 | && generics.own_params.iter().all(|param| matches!(param.kind, ty::GenericParamDefKind::Lifetime)) | 1367 | && generics.own_params.iter().all(|param| matches!(param.kind, ty::GenericParamDefKind::Lifetime)) |
compiler/rustc_middle/src/ty/significant_drop_order.rs+1-1| ... | @@ -133,7 +133,7 @@ pub fn ty_dtor_span<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Span> { | ... | @@ -133,7 +133,7 @@ pub fn ty_dtor_span<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Span> { |
| 133 | | ty::FnPtr(_, _) | 133 | | ty::FnPtr(_, _) |
| 134 | | ty::Tuple(_) | 134 | | ty::Tuple(_) |
| 135 | | ty::Dynamic(_, _) | 135 | | ty::Dynamic(_, _) |
| 136 | | ty::Alias(_, _) | 136 | | ty::Alias(_) |
| 137 | | ty::Bound(_, _) | 137 | | ty::Bound(_, _) |
| 138 | | ty::Pat(_, _) | 138 | | ty::Pat(_, _) |
| 139 | | ty::Placeholder(_) | 139 | | ty::Placeholder(_) |
compiler/rustc_middle/src/ty/structural_impls.rs+3-3| ... | @@ -366,7 +366,7 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for Ty<'tcx> { | ... | @@ -366,7 +366,7 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for Ty<'tcx> { |
| 366 | ty::CoroutineClosure(did, args) => { | 366 | ty::CoroutineClosure(did, args) => { |
| 367 | ty::CoroutineClosure(did, args.try_fold_with(folder)?) | 367 | ty::CoroutineClosure(did, args.try_fold_with(folder)?) |
| 368 | } | 368 | } |
| 369 | ty::Alias(kind, data) => ty::Alias(kind, data.try_fold_with(folder)?), | 369 | ty::Alias(data) => ty::Alias(data.try_fold_with(folder)?), |
| 370 | ty::Pat(ty, pat) => ty::Pat(ty.try_fold_with(folder)?, pat.try_fold_with(folder)?), | 370 | ty::Pat(ty, pat) => ty::Pat(ty.try_fold_with(folder)?, pat.try_fold_with(folder)?), |
| 371 | 371 | ||
| 372 | ty::Bool | 372 | ty::Bool |
| ... | @@ -405,7 +405,7 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for Ty<'tcx> { | ... | @@ -405,7 +405,7 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for Ty<'tcx> { |
| 405 | ty::CoroutineWitness(did, args) => ty::CoroutineWitness(did, args.fold_with(folder)), | 405 | ty::CoroutineWitness(did, args) => ty::CoroutineWitness(did, args.fold_with(folder)), |
| 406 | ty::Closure(did, args) => ty::Closure(did, args.fold_with(folder)), | 406 | ty::Closure(did, args) => ty::Closure(did, args.fold_with(folder)), |
| 407 | ty::CoroutineClosure(did, args) => ty::CoroutineClosure(did, args.fold_with(folder)), | 407 | ty::CoroutineClosure(did, args) => ty::CoroutineClosure(did, args.fold_with(folder)), |
| 408 | ty::Alias(kind, data) => ty::Alias(kind, data.fold_with(folder)), | 408 | ty::Alias(data) => ty::Alias(data.fold_with(folder)), |
| 409 | ty::Pat(ty, pat) => ty::Pat(ty.fold_with(folder), pat.fold_with(folder)), | 409 | ty::Pat(ty, pat) => ty::Pat(ty.fold_with(folder), pat.fold_with(folder)), |
| 410 | 410 | ||
| 411 | ty::Bool | 411 | ty::Bool |
| ... | @@ -453,7 +453,7 @@ impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for Ty<'tcx> { | ... | @@ -453,7 +453,7 @@ impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for Ty<'tcx> { |
| 453 | ty::CoroutineWitness(_did, args) => args.visit_with(visitor), | 453 | ty::CoroutineWitness(_did, args) => args.visit_with(visitor), |
| 454 | ty::Closure(_did, args) => args.visit_with(visitor), | 454 | ty::Closure(_did, args) => args.visit_with(visitor), |
| 455 | ty::CoroutineClosure(_did, args) => args.visit_with(visitor), | 455 | ty::CoroutineClosure(_did, args) => args.visit_with(visitor), |
| 456 | ty::Alias(_, data) => data.visit_with(visitor), | 456 | ty::Alias(data) => data.visit_with(visitor), |
| 457 | 457 | ||
| 458 | ty::Pat(ty, pat) => { | 458 | ty::Pat(ty, pat) => { |
| 459 | try_visit!(ty.visit_with(visitor)); | 459 | try_visit!(ty.visit_with(visitor)); |
compiler/rustc_middle/src/ty/sty.rs+18-22| ... | @@ -35,6 +35,7 @@ use crate::ty::{ | ... | @@ -35,6 +35,7 @@ use crate::ty::{ |
| 35 | pub type TyKind<'tcx> = ir::TyKind<TyCtxt<'tcx>>; | 35 | pub type TyKind<'tcx> = ir::TyKind<TyCtxt<'tcx>>; |
| 36 | pub type TypeAndMut<'tcx> = ir::TypeAndMut<TyCtxt<'tcx>>; | 36 | pub type TypeAndMut<'tcx> = ir::TypeAndMut<TyCtxt<'tcx>>; |
| 37 | pub type AliasTy<'tcx> = ir::AliasTy<TyCtxt<'tcx>>; | 37 | pub type AliasTy<'tcx> = ir::AliasTy<TyCtxt<'tcx>>; |
| 38 | pub type AliasTyKind<'tcx> = ir::AliasTyKind<TyCtxt<'tcx>>; | ||
| 38 | pub type FnSig<'tcx> = ir::FnSig<TyCtxt<'tcx>>; | 39 | pub type FnSig<'tcx> = ir::FnSig<TyCtxt<'tcx>>; |
| 39 | pub type Binder<'tcx, T> = ir::Binder<TyCtxt<'tcx>, T>; | 40 | pub type Binder<'tcx, T> = ir::Binder<TyCtxt<'tcx>, T>; |
| 40 | pub type EarlyBinder<'tcx, T> = ir::EarlyBinder<TyCtxt<'tcx>, T>; | 41 | pub type EarlyBinder<'tcx, T> = ir::EarlyBinder<TyCtxt<'tcx>, T>; |
| ... | @@ -468,18 +469,14 @@ impl<'tcx> Ty<'tcx> { | ... | @@ -468,18 +469,14 @@ impl<'tcx> Ty<'tcx> { |
| 468 | } | 469 | } |
| 469 | 470 | ||
| 470 | #[inline] | 471 | #[inline] |
| 471 | pub fn new_alias( | 472 | pub fn new_alias(tcx: TyCtxt<'tcx>, alias_ty: ty::AliasTy<'tcx>) -> Ty<'tcx> { |
| 472 | tcx: TyCtxt<'tcx>, | ||
| 473 | kind: ty::AliasTyKind, | ||
| 474 | alias_ty: ty::AliasTy<'tcx>, | ||
| 475 | ) -> Ty<'tcx> { | ||
| 476 | debug_assert_matches!( | 473 | debug_assert_matches!( |
| 477 | (kind, tcx.def_kind(alias_ty.def_id)), | 474 | (alias_ty.kind, tcx.def_kind(alias_ty.kind.def_id())), |
| 478 | (ty::Opaque, DefKind::OpaqueTy) | 475 | (ty::Opaque { .. }, DefKind::OpaqueTy) |
| 479 | | (ty::Projection | ty::Inherent, DefKind::AssocTy) | 476 | | (ty::Projection { .. } | ty::Inherent { .. }, DefKind::AssocTy) |
| 480 | | (ty::Free, DefKind::TyAlias) | 477 | | (ty::Free { .. }, DefKind::TyAlias) |
| 481 | ); | 478 | ); |
| 482 | Ty::new(tcx, Alias(kind, alias_ty)) | 479 | Ty::new(tcx, Alias(alias_ty)) |
| 483 | } | 480 | } |
| 484 | 481 | ||
| 485 | #[inline] | 482 | #[inline] |
| ... | @@ -519,7 +516,7 @@ impl<'tcx> Ty<'tcx> { | ... | @@ -519,7 +516,7 @@ impl<'tcx> Ty<'tcx> { |
| 519 | #[inline] | 516 | #[inline] |
| 520 | #[instrument(level = "debug", skip(tcx))] | 517 | #[instrument(level = "debug", skip(tcx))] |
| 521 | pub fn new_opaque(tcx: TyCtxt<'tcx>, def_id: DefId, args: GenericArgsRef<'tcx>) -> Ty<'tcx> { | 518 | pub fn new_opaque(tcx: TyCtxt<'tcx>, def_id: DefId, args: GenericArgsRef<'tcx>) -> Ty<'tcx> { |
| 522 | Ty::new_alias(tcx, ty::Opaque, AliasTy::new_from_args(tcx, def_id, args)) | 519 | Ty::new_alias(tcx, AliasTy::new_from_args(tcx, ty::Opaque { def_id }, args)) |
| 523 | } | 520 | } |
| 524 | 521 | ||
| 525 | /// Constructs a `TyKind::Error` type with current `ErrorGuaranteed` | 522 | /// Constructs a `TyKind::Error` type with current `ErrorGuaranteed` |
| ... | @@ -775,7 +772,10 @@ impl<'tcx> Ty<'tcx> { | ... | @@ -775,7 +772,10 @@ impl<'tcx> Ty<'tcx> { |
| 775 | item_def_id: DefId, | 772 | item_def_id: DefId, |
| 776 | args: ty::GenericArgsRef<'tcx>, | 773 | args: ty::GenericArgsRef<'tcx>, |
| 777 | ) -> Ty<'tcx> { | 774 | ) -> Ty<'tcx> { |
| 778 | Ty::new_alias(tcx, ty::Projection, AliasTy::new_from_args(tcx, item_def_id, args)) | 775 | Ty::new_alias( |
| 776 | tcx, | ||
| 777 | AliasTy::new_from_args(tcx, ty::Projection { def_id: item_def_id }, args), | ||
| 778 | ) | ||
| 779 | } | 779 | } |
| 780 | 780 | ||
| 781 | #[inline] | 781 | #[inline] |
| ... | @@ -784,7 +784,7 @@ impl<'tcx> Ty<'tcx> { | ... | @@ -784,7 +784,7 @@ impl<'tcx> Ty<'tcx> { |
| 784 | item_def_id: DefId, | 784 | item_def_id: DefId, |
| 785 | args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>, | 785 | args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>, |
| 786 | ) -> Ty<'tcx> { | 786 | ) -> Ty<'tcx> { |
| 787 | Ty::new_alias(tcx, ty::Projection, AliasTy::new(tcx, item_def_id, args)) | 787 | Ty::new_alias(tcx, AliasTy::new(tcx, ty::Projection { def_id: item_def_id }, args)) |
| 788 | } | 788 | } |
| 789 | 789 | ||
| 790 | #[inline] | 790 | #[inline] |
| ... | @@ -960,12 +960,8 @@ impl<'tcx> rustc_type_ir::inherent::Ty<TyCtxt<'tcx>> for Ty<'tcx> { | ... | @@ -960,12 +960,8 @@ impl<'tcx> rustc_type_ir::inherent::Ty<TyCtxt<'tcx>> for Ty<'tcx> { |
| 960 | Ty::new_canonical_bound(tcx, var) | 960 | Ty::new_canonical_bound(tcx, var) |
| 961 | } | 961 | } |
| 962 | 962 | ||
| 963 | fn new_alias( | 963 | fn new_alias(interner: TyCtxt<'tcx>, alias_ty: ty::AliasTy<'tcx>) -> Self { |
| 964 | interner: TyCtxt<'tcx>, | 964 | Ty::new_alias(interner, alias_ty) |
| 965 | kind: ty::AliasTyKind, | ||
| 966 | alias_ty: ty::AliasTy<'tcx>, | ||
| 967 | ) -> Self { | ||
| 968 | Ty::new_alias(interner, kind, alias_ty) | ||
| 969 | } | 965 | } |
| 970 | 966 | ||
| 971 | fn new_error(interner: TyCtxt<'tcx>, guar: ErrorGuaranteed) -> Self { | 967 | fn new_error(interner: TyCtxt<'tcx>, guar: ErrorGuaranteed) -> Self { |
| ... | @@ -1599,7 +1595,7 @@ impl<'tcx> Ty<'tcx> { | ... | @@ -1599,7 +1595,7 @@ impl<'tcx> Ty<'tcx> { |
| 1599 | 1595 | ||
| 1600 | #[inline] | 1596 | #[inline] |
| 1601 | pub fn is_impl_trait(self) -> bool { | 1597 | pub fn is_impl_trait(self) -> bool { |
| 1602 | matches!(self.kind(), Alias(ty::Opaque, ..)) | 1598 | matches!(self.kind(), Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. })) |
| 1603 | } | 1599 | } |
| 1604 | 1600 | ||
| 1605 | #[inline] | 1601 | #[inline] |
| ... | @@ -2163,7 +2159,7 @@ mod size_asserts { | ... | @@ -2163,7 +2159,7 @@ mod size_asserts { |
| 2163 | 2159 | ||
| 2164 | use super::*; | 2160 | use super::*; |
| 2165 | // tidy-alphabetical-start | 2161 | // tidy-alphabetical-start |
| 2166 | static_assert_size!(TyKind<'_>, 24); | 2162 | static_assert_size!(TyKind<'_>, 32); |
| 2167 | static_assert_size!(ty::WithCachedTypeInfo<TyKind<'_>>, 48); | 2163 | static_assert_size!(ty::WithCachedTypeInfo<TyKind<'_>>, 56); |
| 2168 | // tidy-alphabetical-end | 2164 | // tidy-alphabetical-end |
| 2169 | } | 2165 | } |
compiler/rustc_middle/src/ty/util.rs+6-6| ... | @@ -913,18 +913,18 @@ impl<'tcx> TyCtxt<'tcx> { | ... | @@ -913,18 +913,18 @@ impl<'tcx> TyCtxt<'tcx> { |
| 913 | /// [free]: ty::Free | 913 | /// [free]: ty::Free |
| 914 | /// [expand_free_alias_tys]: Self::expand_free_alias_tys | 914 | /// [expand_free_alias_tys]: Self::expand_free_alias_tys |
| 915 | pub fn peel_off_free_alias_tys(self, mut ty: Ty<'tcx>) -> Ty<'tcx> { | 915 | pub fn peel_off_free_alias_tys(self, mut ty: Ty<'tcx>) -> Ty<'tcx> { |
| 916 | let ty::Alias(ty::Free, _) = ty.kind() else { return ty }; | 916 | let ty::Alias(ty::AliasTy { kind: ty::Free { .. }, .. }) = ty.kind() else { return ty }; |
| 917 | 917 | ||
| 918 | let limit = self.recursion_limit(); | 918 | let limit = self.recursion_limit(); |
| 919 | let mut depth = 0; | 919 | let mut depth = 0; |
| 920 | 920 | ||
| 921 | while let ty::Alias(ty::Free, alias) = ty.kind() { | 921 | while let &ty::Alias(ty::AliasTy { kind: ty::Free { def_id }, args, .. }) = ty.kind() { |
| 922 | if !limit.value_within_limit(depth) { | 922 | if !limit.value_within_limit(depth) { |
| 923 | let guar = self.dcx().delayed_bug("overflow expanding free alias type"); | 923 | let guar = self.dcx().delayed_bug("overflow expanding free alias type"); |
| 924 | return Ty::new_error(self, guar); | 924 | return Ty::new_error(self, guar); |
| 925 | } | 925 | } |
| 926 | 926 | ||
| 927 | ty = self.type_of(alias.def_id).instantiate(self, alias.args); | 927 | ty = self.type_of(def_id).instantiate(self, args); |
| 928 | depth += 1; | 928 | depth += 1; |
| 929 | } | 929 | } |
| 930 | 930 | ||
| ... | @@ -1013,7 +1013,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for OpaqueTypeExpander<'tcx> { | ... | @@ -1013,7 +1013,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for OpaqueTypeExpander<'tcx> { |
| 1013 | } | 1013 | } |
| 1014 | 1014 | ||
| 1015 | fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { | 1015 | fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { |
| 1016 | if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) = *t.kind() { | 1016 | if let ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) = *t.kind() { |
| 1017 | self.expand_opaque_ty(def_id, args).unwrap_or(t) | 1017 | self.expand_opaque_ty(def_id, args).unwrap_or(t) |
| 1018 | } else if t.has_opaque_types() { | 1018 | } else if t.has_opaque_types() { |
| 1019 | t.super_fold_with(self) | 1019 | t.super_fold_with(self) |
| ... | @@ -1057,7 +1057,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for FreeAliasTypeExpander<'tcx> { | ... | @@ -1057,7 +1057,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for FreeAliasTypeExpander<'tcx> { |
| 1057 | if !ty.has_type_flags(ty::TypeFlags::HAS_TY_FREE_ALIAS) { | 1057 | if !ty.has_type_flags(ty::TypeFlags::HAS_TY_FREE_ALIAS) { |
| 1058 | return ty; | 1058 | return ty; |
| 1059 | } | 1059 | } |
| 1060 | let ty::Alias(ty::Free, alias) = ty.kind() else { | 1060 | let &ty::Alias(ty::AliasTy { kind: ty::Free { def_id }, args, .. }) = ty.kind() else { |
| 1061 | return ty.super_fold_with(self); | 1061 | return ty.super_fold_with(self); |
| 1062 | }; | 1062 | }; |
| 1063 | if !self.tcx.recursion_limit().value_within_limit(self.depth) { | 1063 | if !self.tcx.recursion_limit().value_within_limit(self.depth) { |
| ... | @@ -1067,7 +1067,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for FreeAliasTypeExpander<'tcx> { | ... | @@ -1067,7 +1067,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for FreeAliasTypeExpander<'tcx> { |
| 1067 | 1067 | ||
| 1068 | self.depth += 1; | 1068 | self.depth += 1; |
| 1069 | let ty = ensure_sufficient_stack(|| { | 1069 | let ty = ensure_sufficient_stack(|| { |
| 1070 | self.tcx.type_of(alias.def_id).instantiate(self.tcx, alias.args).fold_with(self) | 1070 | self.tcx.type_of(def_id).instantiate(self.tcx, args).fold_with(self) |
| 1071 | }); | 1071 | }); |
| 1072 | self.depth -= 1; | 1072 | self.depth -= 1; |
| 1073 | ty | 1073 | ty |
compiler/rustc_middle/src/ty/visit.rs+7-2| ... | @@ -181,11 +181,16 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for LateBoundRegionsCollector<'tcx> { | ... | @@ -181,11 +181,16 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for LateBoundRegionsCollector<'tcx> { |
| 181 | match t.kind() { | 181 | match t.kind() { |
| 182 | // If we are only looking for "constrained" regions, we have to ignore the | 182 | // If we are only looking for "constrained" regions, we have to ignore the |
| 183 | // inputs to a projection as they may not appear in the normalized form. | 183 | // inputs to a projection as they may not appear in the normalized form. |
| 184 | ty::Alias(ty::Projection | ty::Inherent | ty::Opaque, _) => { | 184 | ty::Alias(ty::AliasTy { |
| 185 | kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Opaque { .. }, | ||
| 186 | .. | ||
| 187 | }) => { | ||
| 185 | return; | 188 | return; |
| 186 | } | 189 | } |
| 187 | // All free alias types should've been expanded beforehand. | 190 | // All free alias types should've been expanded beforehand. |
| 188 | ty::Alias(ty::Free, _) => bug!("unexpected free alias type"), | 191 | ty::Alias(ty::AliasTy { kind: ty::Free { .. }, .. }) => { |
| 192 | bug!("unexpected free alias type") | ||
| 193 | } | ||
| 189 | _ => {} | 194 | _ => {} |
| 190 | } | 195 | } |
| 191 | } | 196 | } |
compiler/rustc_mir_build/src/builder/block.rs+4-1| ... | @@ -333,7 +333,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { | ... | @@ -333,7 +333,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { |
| 333 | // Opaque types of empty bodies also need this unit assignment, in order to infer that their | 333 | // Opaque types of empty bodies also need this unit assignment, in order to infer that their |
| 334 | // type is actually unit. Otherwise there will be no defining use found in the MIR. | 334 | // type is actually unit. Otherwise there will be no defining use found in the MIR. |
| 335 | if destination_ty.is_unit() | 335 | if destination_ty.is_unit() |
| 336 | || matches!(destination_ty.kind(), ty::Alias(ty::Opaque, ..)) | 336 | || matches!( |
| 337 | destination_ty.kind(), | ||
| 338 | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) | ||
| 339 | ) | ||
| 337 | { | 340 | { |
| 338 | // We only want to assign an implicit `()` as the return value of the block if the | 341 | // We only want to assign an implicit `()` as the return value of the block if the |
| 339 | // block does not diverge. (Otherwise, we may try to assign a unit to a `!`-type.) | 342 | // block does not diverge. (Otherwise, we may try to assign a unit to a `!`-type.) |
compiler/rustc_mir_dataflow/src/move_paths/builder.rs+2-2| ... | @@ -165,7 +165,7 @@ impl<'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> MoveDataBuilder<'a, 'tcx, F> { | ... | @@ -165,7 +165,7 @@ impl<'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> MoveDataBuilder<'a, 'tcx, F> { |
| 165 | | ty::Never | 165 | | ty::Never |
| 166 | | ty::Tuple(_) | 166 | | ty::Tuple(_) |
| 167 | | ty::UnsafeBinder(_) | 167 | | ty::UnsafeBinder(_) |
| 168 | | ty::Alias(_, _) | 168 | | ty::Alias(_) |
| 169 | | ty::Param(_) | 169 | | ty::Param(_) |
| 170 | | ty::Bound(_, _) | 170 | | ty::Bound(_, _) |
| 171 | | ty::Infer(_) | 171 | | ty::Infer(_) |
| ... | @@ -205,7 +205,7 @@ impl<'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> MoveDataBuilder<'a, 'tcx, F> { | ... | @@ -205,7 +205,7 @@ impl<'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> MoveDataBuilder<'a, 'tcx, F> { |
| 205 | | ty::CoroutineWitness(..) | 205 | | ty::CoroutineWitness(..) |
| 206 | | ty::Never | 206 | | ty::Never |
| 207 | | ty::UnsafeBinder(_) | 207 | | ty::UnsafeBinder(_) |
| 208 | | ty::Alias(_, _) | 208 | | ty::Alias(_) |
| 209 | | ty::Param(_) | 209 | | ty::Param(_) |
| 210 | | ty::Bound(_, _) | 210 | | ty::Bound(_, _) |
| 211 | | ty::Infer(_) | 211 | | ty::Infer(_) |
compiler/rustc_mir_transform/src/coroutine.rs+1-1| ... | @@ -1900,7 +1900,7 @@ fn check_must_not_suspend_ty<'tcx>( | ... | @@ -1900,7 +1900,7 @@ fn check_must_not_suspend_ty<'tcx>( |
| 1900 | } | 1900 | } |
| 1901 | ty::Adt(def, _) => check_must_not_suspend_def(tcx, def.did(), hir_id, data), | 1901 | ty::Adt(def, _) => check_must_not_suspend_def(tcx, def.did(), hir_id, data), |
| 1902 | // FIXME: support adding the attribute to TAITs | 1902 | // FIXME: support adding the attribute to TAITs |
| 1903 | ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => { | 1903 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: def }, .. }) => { |
| 1904 | let mut has_emitted = false; | 1904 | let mut has_emitted = false; |
| 1905 | for &(predicate, _) in tcx.explicit_item_bounds(def).skip_binder() { | 1905 | for &(predicate, _) in tcx.explicit_item_bounds(def).skip_binder() { |
| 1906 | // We only look at the `DefId`, so it is safe to skip the binder here. | 1906 | // We only look at the `DefId`, so it is safe to skip the binder here. |
compiler/rustc_mir_transform/src/liveness.rs+1-1| ... | @@ -242,7 +242,7 @@ fn maybe_drop_guard<'tcx>( | ... | @@ -242,7 +242,7 @@ fn maybe_drop_guard<'tcx>( |
| 242 | | ty::Dynamic(..) | 242 | | ty::Dynamic(..) |
| 243 | | ty::Array(..) | 243 | | ty::Array(..) |
| 244 | | ty::Slice(..) | 244 | | ty::Slice(..) |
| 245 | | ty::Alias(ty::Opaque, ..) | 245 | | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) |
| 246 | ) && ty.needs_drop(tcx, typing_env) | 246 | ) && ty.needs_drop(tcx, typing_env) |
| 247 | } else { | 247 | } else { |
| 248 | false | 248 | false |
compiler/rustc_mir_transform/src/validate.rs+4-2| ... | @@ -685,7 +685,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { | ... | @@ -685,7 +685,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { |
| 685 | }; | 685 | }; |
| 686 | 686 | ||
| 687 | let kind = match parent_ty.ty.kind() { | 687 | let kind = match parent_ty.ty.kind() { |
| 688 | &ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => { | 688 | &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { |
| 689 | self.tcx.type_of(def_id).instantiate(self.tcx, args).kind() | 689 | self.tcx.type_of(def_id).instantiate(self.tcx, args).kind() |
| 690 | } | 690 | } |
| 691 | kind => kind, | 691 | kind => kind, |
| ... | @@ -1547,7 +1547,9 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { | ... | @@ -1547,7 +1547,9 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { |
| 1547 | let pty = place.ty(&self.body.local_decls, self.tcx).ty; | 1547 | let pty = place.ty(&self.body.local_decls, self.tcx).ty; |
| 1548 | if !matches!( | 1548 | if !matches!( |
| 1549 | pty.kind(), | 1549 | pty.kind(), |
| 1550 | ty::Adt(..) | ty::Coroutine(..) | ty::Alias(ty::Opaque, ..) | 1550 | ty::Adt(..) |
| 1551 | | ty::Coroutine(..) | ||
| 1552 | | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) | ||
| 1551 | ) { | 1553 | ) { |
| 1552 | self.fail( | 1554 | self.fail( |
| 1553 | location, | 1555 | location, |
compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs+1-1| ... | @@ -391,7 +391,7 @@ impl<'a, D: SolverDelegate<Interner = I>, I: Interner> Canonicalizer<'a, D, I> { | ... | @@ -391,7 +391,7 @@ impl<'a, D: SolverDelegate<Interner = I>, I: Interner> Canonicalizer<'a, D, I> { |
| 391 | | ty::CoroutineWitness(..) | 391 | | ty::CoroutineWitness(..) |
| 392 | | ty::Never | 392 | | ty::Never |
| 393 | | ty::Tuple(_) | 393 | | ty::Tuple(_) |
| 394 | | ty::Alias(_, _) | 394 | | ty::Alias(_) |
| 395 | | ty::Bound(_, _) | 395 | | ty::Bound(_, _) |
| 396 | | ty::Error(_) => { | 396 | | ty::Error(_) => { |
| 397 | return ensure_sufficient_stack(|| t.super_fold_with(self)); | 397 | return ensure_sufficient_stack(|| t.super_fold_with(self)); |
compiler/rustc_next_trait_solver/src/coherence.rs+2-2| ... | @@ -362,7 +362,7 @@ where | ... | @@ -362,7 +362,7 @@ where |
| 362 | // normalize to that, so we have to treat it as an uncovered ty param. | 362 | // normalize to that, so we have to treat it as an uncovered ty param. |
| 363 | // * Otherwise it may normalize to any non-type-generic type | 363 | // * Otherwise it may normalize to any non-type-generic type |
| 364 | // be it local or non-local. | 364 | // be it local or non-local. |
| 365 | ty::Alias(kind, _) => { | 365 | ty::Alias(ty::AliasTy { kind, .. }) => { |
| 366 | if ty.has_type_flags( | 366 | if ty.has_type_flags( |
| 367 | ty::TypeFlags::HAS_TY_PLACEHOLDER | 367 | ty::TypeFlags::HAS_TY_PLACEHOLDER |
| 368 | | ty::TypeFlags::HAS_TY_BOUND | 368 | | ty::TypeFlags::HAS_TY_BOUND |
| ... | @@ -370,7 +370,7 @@ where | ... | @@ -370,7 +370,7 @@ where |
| 370 | ) { | 370 | ) { |
| 371 | match self.in_crate { | 371 | match self.in_crate { |
| 372 | InCrate::Local { mode } => match kind { | 372 | InCrate::Local { mode } => match kind { |
| 373 | ty::Projection => { | 373 | ty::Projection { .. } => { |
| 374 | if let OrphanCheckMode::Compat = mode { | 374 | if let OrphanCheckMode::Compat = mode { |
| 375 | ControlFlow::Continue(()) | 375 | ControlFlow::Continue(()) |
| 376 | } else { | 376 | } else { |
compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs+11-9| ... | @@ -11,7 +11,7 @@ use rustc_type_ir::lang_items::SolverTraitLangItem; | ... | @@ -11,7 +11,7 @@ use rustc_type_ir::lang_items::SolverTraitLangItem; |
| 11 | use rustc_type_ir::search_graph::CandidateHeadUsages; | 11 | use rustc_type_ir::search_graph::CandidateHeadUsages; |
| 12 | use rustc_type_ir::solve::{AliasBoundKind, SizedTraitKind}; | 12 | use rustc_type_ir::solve::{AliasBoundKind, SizedTraitKind}; |
| 13 | use rustc_type_ir::{ | 13 | use rustc_type_ir::{ |
| 14 | self as ty, Interner, TypeFlags, TypeFoldable, TypeFolder, TypeSuperFoldable, | 14 | self as ty, AliasTy, Interner, TypeFlags, TypeFoldable, TypeFolder, TypeSuperFoldable, |
| 15 | TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode, Upcast, | 15 | TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode, Upcast, |
| 16 | elaborate, | 16 | elaborate, |
| 17 | }; | 17 | }; |
| ... | @@ -687,7 +687,7 @@ where | ... | @@ -687,7 +687,7 @@ where |
| 687 | candidates: &mut Vec<Candidate<I>>, | 687 | candidates: &mut Vec<Candidate<I>>, |
| 688 | consider_self_bounds: AliasBoundKind, | 688 | consider_self_bounds: AliasBoundKind, |
| 689 | ) { | 689 | ) { |
| 690 | let (kind, alias_ty) = match self_ty.kind() { | 690 | let alias_ty = match self_ty.kind() { |
| 691 | ty::Bool | 691 | ty::Bool |
| 692 | | ty::Char | 692 | | ty::Char |
| 693 | | ty::Int(_) | 693 | | ty::Int(_) |
| ... | @@ -735,8 +735,10 @@ where | ... | @@ -735,8 +735,10 @@ where |
| 735 | return; | 735 | return; |
| 736 | } | 736 | } |
| 737 | 737 | ||
| 738 | ty::Alias(kind @ (ty::Projection | ty::Opaque), alias_ty) => (kind, alias_ty), | 738 | ty::Alias( |
| 739 | ty::Alias(ty::Inherent | ty::Free, _) => { | 739 | alias_ty @ AliasTy { kind: ty::Projection { .. } | ty::Opaque { .. }, .. }, |
| 740 | ) => alias_ty, | ||
| 741 | ty::Alias(AliasTy { kind: ty::Inherent { .. } | ty::Free { .. }, .. }) => { | ||
| 740 | self.cx().delay_bug(format!("could not normalize {self_ty:?}, it is not WF")); | 742 | self.cx().delay_bug(format!("could not normalize {self_ty:?}, it is not WF")); |
| 741 | return; | 743 | return; |
| 742 | } | 744 | } |
| ... | @@ -746,7 +748,7 @@ where | ... | @@ -746,7 +748,7 @@ where |
| 746 | AliasBoundKind::SelfBounds => { | 748 | AliasBoundKind::SelfBounds => { |
| 747 | for assumption in self | 749 | for assumption in self |
| 748 | .cx() | 750 | .cx() |
| 749 | .item_self_bounds(alias_ty.def_id) | 751 | .item_self_bounds(alias_ty.kind.def_id()) |
| 750 | .iter_instantiated(self.cx(), alias_ty.args) | 752 | .iter_instantiated(self.cx(), alias_ty.args) |
| 751 | { | 753 | { |
| 752 | candidates.extend(G::probe_and_consider_implied_clause( | 754 | candidates.extend(G::probe_and_consider_implied_clause( |
| ... | @@ -761,7 +763,7 @@ where | ... | @@ -761,7 +763,7 @@ where |
| 761 | AliasBoundKind::NonSelfBounds => { | 763 | AliasBoundKind::NonSelfBounds => { |
| 762 | for assumption in self | 764 | for assumption in self |
| 763 | .cx() | 765 | .cx() |
| 764 | .item_non_self_bounds(alias_ty.def_id) | 766 | .item_non_self_bounds(alias_ty.kind.def_id()) |
| 765 | .iter_instantiated(self.cx(), alias_ty.args) | 767 | .iter_instantiated(self.cx(), alias_ty.args) |
| 766 | { | 768 | { |
| 767 | candidates.extend(G::probe_and_consider_implied_clause( | 769 | candidates.extend(G::probe_and_consider_implied_clause( |
| ... | @@ -777,7 +779,7 @@ where | ... | @@ -777,7 +779,7 @@ where |
| 777 | 779 | ||
| 778 | candidates.extend(G::consider_additional_alias_assumptions(self, goal, alias_ty)); | 780 | candidates.extend(G::consider_additional_alias_assumptions(self, goal, alias_ty)); |
| 779 | 781 | ||
| 780 | if kind != ty::Projection { | 782 | if !matches!(alias_ty.kind, ty::Projection { .. }) { |
| 781 | return; | 783 | return; |
| 782 | } | 784 | } |
| 783 | 785 | ||
| ... | @@ -1023,7 +1025,7 @@ where | ... | @@ -1023,7 +1025,7 @@ where |
| 1023 | self.cx | 1025 | self.cx |
| 1024 | } | 1026 | } |
| 1025 | fn fold_ty(&mut self, ty: I::Ty) -> I::Ty { | 1027 | fn fold_ty(&mut self, ty: I::Ty) -> I::Ty { |
| 1026 | if let ty::Alias(ty::Opaque, alias_ty) = ty.kind() { | 1028 | if let ty::Alias(alias_ty) = ty.kind() { |
| 1027 | if alias_ty == self.alias_ty { | 1029 | if alias_ty == self.alias_ty { |
| 1028 | return self.self_ty; | 1030 | return self.self_ty; |
| 1029 | } | 1031 | } |
| ... | @@ -1041,7 +1043,7 @@ where | ... | @@ -1041,7 +1043,7 @@ where |
| 1041 | // in a `?x: Trait<u32>` alias-bound candidate. | 1043 | // in a `?x: Trait<u32>` alias-bound candidate. |
| 1042 | for item_bound in self | 1044 | for item_bound in self |
| 1043 | .cx() | 1045 | .cx() |
| 1044 | .item_self_bounds(alias_ty.def_id) | 1046 | .item_self_bounds(alias_ty.kind.def_id()) |
| 1045 | .iter_instantiated(self.cx(), alias_ty.args) | 1047 | .iter_instantiated(self.cx(), alias_ty.args) |
| 1046 | { | 1048 | { |
| 1047 | let assumption = | 1049 | let assumption = |
compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs+10-7| ... | @@ -49,7 +49,10 @@ where | ... | @@ -49,7 +49,10 @@ where |
| 49 | 49 | ||
| 50 | ty::Dynamic(..) | 50 | ty::Dynamic(..) |
| 51 | | ty::Param(..) | 51 | | ty::Param(..) |
| 52 | | ty::Alias(ty::Projection | ty::Inherent | ty::Free, ..) | 52 | | ty::Alias(ty::AliasTy { |
| 53 | kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Free { .. }, | ||
| 54 | .. | ||
| 55 | }) | ||
| 53 | | ty::Placeholder(..) | 56 | | ty::Placeholder(..) |
| 54 | | ty::Bound(..) | 57 | | ty::Bound(..) |
| 55 | | ty::Infer(_) => { | 58 | | ty::Infer(_) => { |
| ... | @@ -95,7 +98,7 @@ where | ... | @@ -95,7 +98,7 @@ where |
| 95 | Ok(ty::Binder::dummy(def.all_field_tys(cx).iter_instantiated(cx, args).collect())) | 98 | Ok(ty::Binder::dummy(def.all_field_tys(cx).iter_instantiated(cx, args).collect())) |
| 96 | } | 99 | } |
| 97 | 100 | ||
| 98 | ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => { | 101 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { |
| 99 | // We can resolve the `impl Trait` to its concrete type, | 102 | // We can resolve the `impl Trait` to its concrete type, |
| 100 | // which enforces a DAG between the functions requiring | 103 | // which enforces a DAG between the functions requiring |
| 101 | // the auto trait bounds in question. | 104 | // the auto trait bounds in question. |
| ... | @@ -218,7 +221,7 @@ where | ... | @@ -218,7 +221,7 @@ where |
| 218 | | ty::Foreign(..) | 221 | | ty::Foreign(..) |
| 219 | | ty::Ref(_, _, Mutability::Mut) | 222 | | ty::Ref(_, _, Mutability::Mut) |
| 220 | | ty::Adt(_, _) | 223 | | ty::Adt(_, _) |
| 221 | | ty::Alias(_, _) | 224 | | ty::Alias(_) |
| 222 | | ty::Param(_) | 225 | | ty::Param(_) |
| 223 | | ty::Placeholder(..) => Err(NoSolution), | 226 | | ty::Placeholder(..) => Err(NoSolution), |
| 224 | 227 | ||
| ... | @@ -390,7 +393,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_callable<I: Intern | ... | @@ -390,7 +393,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_callable<I: Intern |
| 390 | | ty::Tuple(_) | 393 | | ty::Tuple(_) |
| 391 | | ty::Pat(_, _) | 394 | | ty::Pat(_, _) |
| 392 | | ty::UnsafeBinder(_) | 395 | | ty::UnsafeBinder(_) |
| 393 | | ty::Alias(_, _) | 396 | | ty::Alias(_) |
| 394 | | ty::Param(_) | 397 | | ty::Param(_) |
| 395 | | ty::Placeholder(..) | 398 | | ty::Placeholder(..) |
| 396 | | ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) | 399 | | ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) |
| ... | @@ -563,7 +566,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I: | ... | @@ -563,7 +566,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I: |
| 563 | | ty::Never | 566 | | ty::Never |
| 564 | | ty::UnsafeBinder(_) | 567 | | ty::UnsafeBinder(_) |
| 565 | | ty::Tuple(_) | 568 | | ty::Tuple(_) |
| 566 | | ty::Alias(_, _) | 569 | | ty::Alias(_) |
| 567 | | ty::Param(_) | 570 | | ty::Param(_) |
| 568 | | ty::Placeholder(..) | 571 | | ty::Placeholder(..) |
| 569 | | ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) | 572 | | ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) |
| ... | @@ -724,7 +727,7 @@ pub(in crate::solve) fn extract_fn_def_from_const_callable<I: Interner>( | ... | @@ -724,7 +727,7 @@ pub(in crate::solve) fn extract_fn_def_from_const_callable<I: Interner>( |
| 724 | | ty::Never | 727 | | ty::Never |
| 725 | | ty::Tuple(_) | 728 | | ty::Tuple(_) |
| 726 | | ty::Pat(_, _) | 729 | | ty::Pat(_, _) |
| 727 | | ty::Alias(_, _) | 730 | | ty::Alias(_) |
| 728 | | ty::Param(_) | 731 | | ty::Param(_) |
| 729 | | ty::Placeholder(..) | 732 | | ty::Placeholder(..) |
| 730 | | ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) | 733 | | ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) |
| ... | @@ -1014,7 +1017,7 @@ where | ... | @@ -1014,7 +1017,7 @@ where |
| 1014 | } | 1017 | } |
| 1015 | 1018 | ||
| 1016 | fn try_fold_ty(&mut self, ty: I::Ty) -> Result<I::Ty, Ambiguous> { | 1019 | fn try_fold_ty(&mut self, ty: I::Ty) -> Result<I::Ty, Ambiguous> { |
| 1017 | if let ty::Alias(ty::Projection, alias_ty) = ty.kind() | 1020 | if let ty::Alias(alias_ty @ ty::AliasTy { kind: ty::Projection { .. }, .. }) = ty.kind() |
| 1018 | && let Some(term) = self.try_eagerly_replace_alias(alias_ty.into())? | 1021 | && let Some(term) = self.try_eagerly_replace_alias(alias_ty.into())? |
| 1019 | { | 1022 | { |
| 1020 | Ok(term.expect_ty()) | 1023 | Ok(term.expect_ty()) |
compiler/rustc_next_trait_solver/src/solve/effect_goals.rs+3-3| ... | @@ -84,13 +84,13 @@ where | ... | @@ -84,13 +84,13 @@ where |
| 84 | let cx = ecx.cx(); | 84 | let cx = ecx.cx(); |
| 85 | let mut candidates = vec![]; | 85 | let mut candidates = vec![]; |
| 86 | 86 | ||
| 87 | if !ecx.cx().alias_has_const_conditions(alias_ty.def_id) { | 87 | if !ecx.cx().alias_has_const_conditions(alias_ty.kind.def_id()) { |
| 88 | return vec![]; | 88 | return vec![]; |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | for clause in elaborate::elaborate( | 91 | for clause in elaborate::elaborate( |
| 92 | cx, | 92 | cx, |
| 93 | cx.explicit_implied_const_bounds(alias_ty.def_id) | 93 | cx.explicit_implied_const_bounds(alias_ty.kind.def_id()) |
| 94 | .iter_instantiated(cx, alias_ty.args) | 94 | .iter_instantiated(cx, alias_ty.args) |
| 95 | .map(|trait_ref| trait_ref.to_host_effect_clause(cx, goal.predicate.constness)), | 95 | .map(|trait_ref| trait_ref.to_host_effect_clause(cx, goal.predicate.constness)), |
| 96 | ) { | 96 | ) { |
| ... | @@ -103,7 +103,7 @@ where | ... | @@ -103,7 +103,7 @@ where |
| 103 | // Const conditions must hold for the implied const bound to hold. | 103 | // Const conditions must hold for the implied const bound to hold. |
| 104 | ecx.add_goals( | 104 | ecx.add_goals( |
| 105 | GoalSource::AliasBoundConstCondition, | 105 | GoalSource::AliasBoundConstCondition, |
| 106 | cx.const_conditions(alias_ty.def_id) | 106 | cx.const_conditions(alias_ty.kind.def_id()) |
| 107 | .iter_instantiated(cx, alias_ty.args) | 107 | .iter_instantiated(cx, alias_ty.args) |
| 108 | .map(|trait_ref| { | 108 | .map(|trait_ref| { |
| 109 | goal.with( | 109 | goal.with( |
compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs+2-2| ... | @@ -653,7 +653,7 @@ where | ... | @@ -653,7 +653,7 @@ where |
| 653 | .instantiate(cx, &[I::GenericArg::from(goal.predicate.self_ty())]) | 653 | .instantiate(cx, &[I::GenericArg::from(goal.predicate.self_ty())]) |
| 654 | } | 654 | } |
| 655 | 655 | ||
| 656 | ty::Alias(_, _) | ty::Param(_) | ty::Placeholder(..) => { | 656 | ty::Alias(_) | ty::Param(_) | ty::Placeholder(..) => { |
| 657 | // This is the "fallback impl" for type parameters, unnormalizable projections | 657 | // This is the "fallback impl" for type parameters, unnormalizable projections |
| 658 | // and opaque types: If the `self_ty` is `Sized`, then the metadata is `()`. | 658 | // and opaque types: If the `self_ty` is `Sized`, then the metadata is `()`. |
| 659 | // FIXME(ptr_metadata): This impl overlaps with the other impls and shouldn't | 659 | // FIXME(ptr_metadata): This impl overlaps with the other impls and shouldn't |
| ... | @@ -910,7 +910,7 @@ where | ... | @@ -910,7 +910,7 @@ where |
| 910 | // Given an alias, parameter, or placeholder we add an impl candidate normalizing to a rigid | 910 | // Given an alias, parameter, or placeholder we add an impl candidate normalizing to a rigid |
| 911 | // alias. In case there's a where-bound further constraining this alias it is preferred over | 911 | // alias. In case there's a where-bound further constraining this alias it is preferred over |
| 912 | // this impl candidate anyways. It's still a bit scuffed. | 912 | // this impl candidate anyways. It's still a bit scuffed. |
| 913 | ty::Alias(_, _) | ty::Param(_) | ty::Placeholder(..) => { | 913 | ty::Alias(_) | ty::Param(_) | ty::Placeholder(..) => { |
| 914 | return ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| { | 914 | return ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| { |
| 915 | ecx.structurally_instantiate_normalizes_to_term(goal, goal.predicate.alias); | 915 | ecx.structurally_instantiate_normalizes_to_term(goal, goal.predicate.alias); |
| 916 | ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) | 916 | ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
compiler/rustc_next_trait_solver/src/solve/trait_goals.rs+9-4| ... | @@ -230,9 +230,11 @@ where | ... | @@ -230,9 +230,11 @@ where |
| 230 | // when merging candidates anyways. | 230 | // when merging candidates anyways. |
| 231 | // | 231 | // |
| 232 | // See tests/ui/impl-trait/auto-trait-leakage/avoid-query-cycle-via-item-bound.rs. | 232 | // See tests/ui/impl-trait/auto-trait-leakage/avoid-query-cycle-via-item-bound.rs. |
| 233 | if let ty::Alias(ty::Opaque, opaque_ty) = goal.predicate.self_ty().kind() { | 233 | if let ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }) = |
| 234 | debug_assert!(ecx.opaque_type_is_rigid(opaque_ty.def_id)); | 234 | goal.predicate.self_ty().kind() |
| 235 | for item_bound in cx.item_self_bounds(opaque_ty.def_id).skip_binder() { | 235 | { |
| 236 | debug_assert!(ecx.opaque_type_is_rigid(def_id)); | ||
| 237 | for item_bound in cx.item_self_bounds(def_id).skip_binder() { | ||
| 236 | if item_bound | 238 | if item_bound |
| 237 | .as_trait_clause() | 239 | .as_trait_clause() |
| 238 | .is_some_and(|b| b.def_id() == goal.predicate.def_id()) | 240 | .is_some_and(|b| b.def_id() == goal.predicate.def_id()) |
| ... | @@ -1249,7 +1251,10 @@ where | ... | @@ -1249,7 +1251,10 @@ where |
| 1249 | ty::Dynamic(..) | 1251 | ty::Dynamic(..) |
| 1250 | | ty::Param(..) | 1252 | | ty::Param(..) |
| 1251 | | ty::Foreign(..) | 1253 | | ty::Foreign(..) |
| 1252 | | ty::Alias(ty::Projection | ty::Free | ty::Inherent, ..) | 1254 | | ty::Alias(ty::AliasTy { |
| 1255 | kind: ty::Projection { .. } | ty::Free { .. } | ty::Inherent { .. }, | ||
| 1256 | .. | ||
| 1257 | }) | ||
| 1253 | | ty::Placeholder(..) => Some(Err(NoSolution)), | 1258 | | ty::Placeholder(..) => Some(Err(NoSolution)), |
| 1254 | 1259 | ||
| 1255 | ty::Infer(_) | ty::Bound(_, _) => panic!("unexpected type `{self_ty:?}`"), | 1260 | ty::Infer(_) | ty::Bound(_, _) => panic!("unexpected type `{self_ty:?}`"), |
compiler/rustc_passes/src/check_export.rs+1-1| ... | @@ -308,7 +308,7 @@ impl<'tcx, 'a> TypeVisitor<TyCtxt<'tcx>> for ExportableItemsChecker<'tcx, 'a> { | ... | @@ -308,7 +308,7 @@ impl<'tcx, 'a> TypeVisitor<TyCtxt<'tcx>> for ExportableItemsChecker<'tcx, 'a> { |
| 308 | | ty::CoroutineWitness(_, _) | 308 | | ty::CoroutineWitness(_, _) |
| 309 | | ty::Never | 309 | | ty::Never |
| 310 | | ty::UnsafeBinder(_) | 310 | | ty::UnsafeBinder(_) |
| 311 | | ty::Alias(ty::AliasTyKind::Opaque, _) => { | 311 | | ty::Alias(ty::AliasTy { kind: ty::AliasTyKind::Opaque { .. }, .. }) => { |
| 312 | return ControlFlow::Break(ty); | 312 | return ControlFlow::Break(ty); |
| 313 | } | 313 | } |
| 314 | 314 |
compiler/rustc_pattern_analysis/src/rustc.rs+7-4| ... | @@ -126,8 +126,11 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { | ... | @@ -126,8 +126,11 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { |
| 126 | #[inline] | 126 | #[inline] |
| 127 | pub fn reveal_opaque_ty(&self, ty: Ty<'tcx>) -> RevealedTy<'tcx> { | 127 | pub fn reveal_opaque_ty(&self, ty: Ty<'tcx>) -> RevealedTy<'tcx> { |
| 128 | fn reveal_inner<'tcx>(cx: &RustcPatCtxt<'_, 'tcx>, ty: Ty<'tcx>) -> RevealedTy<'tcx> { | 128 | fn reveal_inner<'tcx>(cx: &RustcPatCtxt<'_, 'tcx>, ty: Ty<'tcx>) -> RevealedTy<'tcx> { |
| 129 | let ty::Alias(ty::Opaque, alias_ty) = *ty.kind() else { bug!() }; | 129 | let ty::Alias(alias_ty @ ty::AliasTy { kind: ty::Opaque { .. }, .. }) = *ty.kind() |
| 130 | if let Some(local_def_id) = alias_ty.def_id.as_local() { | 130 | else { |
| 131 | bug!() | ||
| 132 | }; | ||
| 133 | if let Some(local_def_id) = alias_ty.kind.def_id().as_local() { | ||
| 131 | let key = ty::OpaqueTypeKey { def_id: local_def_id, args: alias_ty.args }; | 134 | let key = ty::OpaqueTypeKey { def_id: local_def_id, args: alias_ty.args }; |
| 132 | if let Some(ty) = cx.reveal_opaque_key(key) { | 135 | if let Some(ty) = cx.reveal_opaque_key(key) { |
| 133 | return RevealedTy(ty); | 136 | return RevealedTy(ty); |
| ... | @@ -135,7 +138,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { | ... | @@ -135,7 +138,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { |
| 135 | } | 138 | } |
| 136 | RevealedTy(ty) | 139 | RevealedTy(ty) |
| 137 | } | 140 | } |
| 138 | if let ty::Alias(ty::Opaque, _) = ty.kind() { | 141 | if let ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) = ty.kind() { |
| 139 | reveal_inner(self, ty) | 142 | reveal_inner(self, ty) |
| 140 | } else { | 143 | } else { |
| 141 | RevealedTy(ty) | 144 | RevealedTy(ty) |
| ... | @@ -423,7 +426,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { | ... | @@ -423,7 +426,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { |
| 423 | | ty::CoroutineClosure(..) | 426 | | ty::CoroutineClosure(..) |
| 424 | | ty::Coroutine(_, _) | 427 | | ty::Coroutine(_, _) |
| 425 | | ty::UnsafeBinder(_) | 428 | | ty::UnsafeBinder(_) |
| 426 | | ty::Alias(_, _) | 429 | | ty::Alias(_) |
| 427 | | ty::Param(_) | 430 | | ty::Param(_) |
| 428 | | ty::Error(_) => ConstructorSet::Unlistable, | 431 | | ty::Error(_) => ConstructorSet::Unlistable, |
| 429 | ty::CoroutineWitness(_, _) | ty::Bound(_, _) | ty::Placeholder(_) | ty::Infer(_) => { | 432 | ty::CoroutineWitness(_, _) | ty::Bound(_, _) | ty::Placeholder(_) | ty::Infer(_) => { |
compiler/rustc_privacy/src/lib.rs+16-8| ... | @@ -209,7 +209,15 @@ where | ... | @@ -209,7 +209,15 @@ where |
| 209 | try_visit!(tcx.type_of(impl_def_id).instantiate_identity().visit_with(self)); | 209 | try_visit!(tcx.type_of(impl_def_id).instantiate_identity().visit_with(self)); |
| 210 | } | 210 | } |
| 211 | } | 211 | } |
| 212 | ty::Alias(kind @ (ty::Inherent | ty::Free | ty::Projection), data) => { | 212 | ty::Alias( |
| 213 | data @ ty::AliasTy { | ||
| 214 | kind: | ||
| 215 | kind @ (ty::Inherent { def_id } | ||
| 216 | | ty::Free { def_id } | ||
| 217 | | ty::Projection { def_id }), | ||
| 218 | .. | ||
| 219 | }, | ||
| 220 | ) => { | ||
| 213 | if self.def_id_visitor.skip_assoc_tys() { | 221 | if self.def_id_visitor.skip_assoc_tys() { |
| 214 | // Visitors searching for minimal visibility/reachability want to | 222 | // Visitors searching for minimal visibility/reachability want to |
| 215 | // conservatively approximate associated types like `Type::Alias` | 223 | // conservatively approximate associated types like `Type::Alias` |
| ... | @@ -226,19 +234,19 @@ where | ... | @@ -226,19 +234,19 @@ where |
| 226 | } | 234 | } |
| 227 | 235 | ||
| 228 | try_visit!(self.def_id_visitor.visit_def_id( | 236 | try_visit!(self.def_id_visitor.visit_def_id( |
| 229 | data.def_id, | 237 | def_id, |
| 230 | match kind { | 238 | match kind { |
| 231 | ty::Inherent | ty::Projection => "associated type", | 239 | ty::Inherent { .. } | ty::Projection { .. } => "associated type", |
| 232 | ty::Free => "type alias", | 240 | ty::Free { .. } => "type alias", |
| 233 | ty::Opaque => unreachable!(), | 241 | ty::Opaque { .. } => unreachable!(), |
| 234 | }, | 242 | }, |
| 235 | &LazyDefPathStr { def_id: data.def_id, tcx }, | 243 | &LazyDefPathStr { def_id, tcx }, |
| 236 | )); | 244 | )); |
| 237 | 245 | ||
| 238 | // This will also visit args if necessary, so we don't need to recurse. | 246 | // This will also visit args if necessary, so we don't need to recurse. |
| 239 | return if V::SHALLOW { | 247 | return if V::SHALLOW { |
| 240 | V::Result::output() | 248 | V::Result::output() |
| 241 | } else if kind == ty::Projection { | 249 | } else if matches!(kind, ty::Projection { .. }) { |
| 242 | self.visit_projection_term(data.into()) | 250 | self.visit_projection_term(data.into()) |
| 243 | } else { | 251 | } else { |
| 244 | V::Result::from_branch( | 252 | V::Result::from_branch( |
| ... | @@ -261,7 +269,7 @@ where | ... | @@ -261,7 +269,7 @@ where |
| 261 | try_visit!(self.def_id_visitor.visit_def_id(def_id, "trait", &trait_ref)); | 269 | try_visit!(self.def_id_visitor.visit_def_id(def_id, "trait", &trait_ref)); |
| 262 | } | 270 | } |
| 263 | } | 271 | } |
| 264 | ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => { | 272 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }) => { |
| 265 | // Skip repeated `Opaque`s to avoid infinite recursion. | 273 | // Skip repeated `Opaque`s to avoid infinite recursion. |
| 266 | if self.visited_tys.insert(ty) { | 274 | if self.visited_tys.insert(ty) { |
| 267 | // The intent is to treat `impl Trait1 + Trait2` identically to | 275 | // The intent is to treat `impl Trait1 + Trait2` identically to |
compiler/rustc_public/src/unstable/convert/stable/ty.rs+12-9| ... | @@ -12,14 +12,14 @@ use crate::ty::{ | ... | @@ -12,14 +12,14 @@ use crate::ty::{ |
| 12 | }; | 12 | }; |
| 13 | use crate::unstable::Stable; | 13 | use crate::unstable::Stable; |
| 14 | 14 | ||
| 15 | impl<'tcx> Stable<'tcx> for ty::AliasTyKind { | 15 | impl<'tcx> Stable<'tcx> for ty::AliasTyKind<'tcx> { |
| 16 | type T = crate::ty::AliasKind; | 16 | type T = crate::ty::AliasKind; |
| 17 | fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T { | 17 | fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T { |
| 18 | match self { | 18 | match self { |
| 19 | ty::Projection => crate::ty::AliasKind::Projection, | 19 | ty::Projection { .. } => crate::ty::AliasKind::Projection, |
| 20 | ty::Inherent => crate::ty::AliasKind::Inherent, | 20 | ty::Inherent { .. } => crate::ty::AliasKind::Inherent, |
| 21 | ty::Opaque => crate::ty::AliasKind::Opaque, | 21 | ty::Opaque { .. } => crate::ty::AliasKind::Opaque, |
| 22 | ty::Free => crate::ty::AliasKind::Free, | 22 | ty::Free { .. } => crate::ty::AliasKind::Free, |
| 23 | } | 23 | } |
| 24 | } | 24 | } |
| 25 | } | 25 | } |
| ... | @@ -31,8 +31,11 @@ impl<'tcx> Stable<'tcx> for ty::AliasTy<'tcx> { | ... | @@ -31,8 +31,11 @@ impl<'tcx> Stable<'tcx> for ty::AliasTy<'tcx> { |
| 31 | tables: &mut Tables<'cx, BridgeTys>, | 31 | tables: &mut Tables<'cx, BridgeTys>, |
| 32 | cx: &CompilerCtxt<'cx, BridgeTys>, | 32 | cx: &CompilerCtxt<'cx, BridgeTys>, |
| 33 | ) -> Self::T { | 33 | ) -> Self::T { |
| 34 | let ty::AliasTy { args, def_id, .. } = self; | 34 | let ty::AliasTy { args, kind, .. } = self; |
| 35 | crate::ty::AliasTy { def_id: tables.alias_def(*def_id), args: args.stable(tables, cx) } | 35 | crate::ty::AliasTy { |
| 36 | def_id: tables.alias_def(kind.def_id()), | ||
| 37 | args: args.stable(tables, cx), | ||
| 38 | } | ||
| 36 | } | 39 | } |
| 37 | } | 40 | } |
| 38 | 41 | ||
| ... | @@ -451,8 +454,8 @@ impl<'tcx> Stable<'tcx> for ty::TyKind<'tcx> { | ... | @@ -451,8 +454,8 @@ impl<'tcx> Stable<'tcx> for ty::TyKind<'tcx> { |
| 451 | ty::Tuple(fields) => TyKind::RigidTy(RigidTy::Tuple( | 454 | ty::Tuple(fields) => TyKind::RigidTy(RigidTy::Tuple( |
| 452 | fields.iter().map(|ty| ty.stable(tables, cx)).collect(), | 455 | fields.iter().map(|ty| ty.stable(tables, cx)).collect(), |
| 453 | )), | 456 | )), |
| 454 | ty::Alias(alias_kind, alias_ty) => { | 457 | ty::Alias(_alias_ty) => { |
| 455 | TyKind::Alias(alias_kind.stable(tables, cx), alias_ty.stable(tables, cx)) | 458 | todo!() |
| 456 | } | 459 | } |
| 457 | ty::Param(param_ty) => TyKind::Param(param_ty.stable(tables, cx)), | 460 | ty::Param(param_ty) => TyKind::Param(param_ty.stable(tables, cx)), |
| 458 | ty::Bound(ty::BoundVarIndexKind::Canonical, _) => { | 461 | ty::Bound(ty::BoundVarIndexKind::Canonical, _) => { |
compiler/rustc_symbol_mangling/src/export.rs+1-1| ... | @@ -117,7 +117,7 @@ impl<'tcx> AbiHashStable<'tcx> for Ty<'tcx> { | ... | @@ -117,7 +117,7 @@ impl<'tcx> AbiHashStable<'tcx> for Ty<'tcx> { |
| 117 | | ty::CoroutineWitness(_, _) | 117 | | ty::CoroutineWitness(_, _) |
| 118 | | ty::Never | 118 | | ty::Never |
| 119 | | ty::Tuple(_) | 119 | | ty::Tuple(_) |
| 120 | | ty::Alias(_, _) | 120 | | ty::Alias(_) |
| 121 | | ty::Param(_) | 121 | | ty::Param(_) |
| 122 | | ty::Bound(_, _) | 122 | | ty::Bound(_, _) |
| 123 | | ty::Placeholder(_) | 123 | | ty::Placeholder(_) |
compiler/rustc_symbol_mangling/src/legacy.rs+8-2| ... | @@ -242,7 +242,11 @@ impl<'tcx> Printer<'tcx> for LegacySymbolMangler<'tcx> { | ... | @@ -242,7 +242,11 @@ impl<'tcx> Printer<'tcx> for LegacySymbolMangler<'tcx> { |
| 242 | match *ty.kind() { | 242 | match *ty.kind() { |
| 243 | // Print all nominal types as paths (unlike `pretty_print_type`). | 243 | // Print all nominal types as paths (unlike `pretty_print_type`). |
| 244 | ty::FnDef(def_id, args) | 244 | ty::FnDef(def_id, args) |
| 245 | | ty::Alias(ty::Projection | ty::Opaque, ty::AliasTy { def_id, args, .. }) | 245 | | ty::Alias(ty::AliasTy { |
| 246 | kind: ty::Projection { def_id } | ty::Opaque { def_id }, | ||
| 247 | args, | ||
| 248 | .. | ||
| 249 | }) | ||
| 246 | | ty::Closure(def_id, args) | 250 | | ty::Closure(def_id, args) |
| 247 | | ty::CoroutineClosure(def_id, args) | 251 | | ty::CoroutineClosure(def_id, args) |
| 248 | | ty::Coroutine(def_id, args) => self.print_def_path(def_id, args), | 252 | | ty::Coroutine(def_id, args) => self.print_def_path(def_id, args), |
| ... | @@ -264,7 +268,9 @@ impl<'tcx> Printer<'tcx> for LegacySymbolMangler<'tcx> { | ... | @@ -264,7 +268,9 @@ impl<'tcx> Printer<'tcx> for LegacySymbolMangler<'tcx> { |
| 264 | Ok(()) | 268 | Ok(()) |
| 265 | } | 269 | } |
| 266 | 270 | ||
| 267 | ty::Alias(ty::Inherent, _) => panic!("unexpected inherent projection"), | 271 | ty::Alias(ty::AliasTy { kind: ty::Inherent { .. }, .. }) => { |
| 272 | panic!("unexpected inherent projection") | ||
| 273 | } | ||
| 268 | 274 | ||
| 269 | _ => self.pretty_print_type(ty), | 275 | _ => self.pretty_print_type(ty), |
| 270 | } | 276 | } |
compiler/rustc_symbol_mangling/src/v0.rs+1-1| ... | @@ -539,7 +539,7 @@ impl<'tcx> Printer<'tcx> for V0SymbolMangler<'tcx> { | ... | @@ -539,7 +539,7 @@ impl<'tcx> Printer<'tcx> for V0SymbolMangler<'tcx> { |
| 539 | 539 | ||
| 540 | // We may still encounter projections here due to the printing | 540 | // We may still encounter projections here due to the printing |
| 541 | // logic sometimes passing identity-substituted impl headers. | 541 | // logic sometimes passing identity-substituted impl headers. |
| 542 | ty::Alias(ty::Projection, ty::AliasTy { def_id, args, .. }) => { | 542 | ty::Alias(ty::AliasTy { kind: ty::Projection { def_id }, args, .. }) => { |
| 543 | self.print_def_path(def_id, args)?; | 543 | self.print_def_path(def_id, args)?; |
| 544 | } | 544 | } |
| 545 | 545 |
compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs+18-20| ... | @@ -54,7 +54,6 @@ use rustc_abi::ExternAbi; | ... | @@ -54,7 +54,6 @@ use rustc_abi::ExternAbi; |
| 54 | use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; | 54 | use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; |
| 55 | use rustc_errors::{Applicability, Diag, DiagStyledString, IntoDiagArg, StringPart, pluralize}; | 55 | use rustc_errors::{Applicability, Diag, DiagStyledString, IntoDiagArg, StringPart, pluralize}; |
| 56 | use rustc_hir as hir; | 56 | use rustc_hir as hir; |
| 57 | use rustc_hir::def::DefKind; | ||
| 58 | use rustc_hir::def_id::{CRATE_DEF_ID, DefId}; | 57 | use rustc_hir::def_id::{CRATE_DEF_ID, DefId}; |
| 59 | use rustc_hir::intravisit::Visitor; | 58 | use rustc_hir::intravisit::Visitor; |
| 60 | use rustc_hir::lang_items::LangItem; | 59 | use rustc_hir::lang_items::LangItem; |
| ... | @@ -182,15 +181,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { | ... | @@ -182,15 +181,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 182 | 181 | ||
| 183 | pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> { | 182 | pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> { |
| 184 | let (def_id, args) = match *ty.kind() { | 183 | let (def_id, args) = match *ty.kind() { |
| 185 | ty::Alias(_, ty::AliasTy { def_id, args, .. }) | 184 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => (def_id, args), |
| 186 | if self.tcx.def_kind(def_id) == DefKind::OpaqueTy => | 185 | ty::Alias(ty::AliasTy { kind, args, .. }) |
| 186 | if self.tcx.is_impl_trait_in_trait(kind.def_id()) => | ||
| 187 | { | 187 | { |
| 188 | (def_id, args) | 188 | (kind.def_id(), args) |
| 189 | } | ||
| 190 | ty::Alias(_, ty::AliasTy { def_id, args, .. }) | ||
| 191 | if self.tcx.is_impl_trait_in_trait(def_id) => | ||
| 192 | { | ||
| 193 | (def_id, args) | ||
| 194 | } | 189 | } |
| 195 | _ => return None, | 190 | _ => return None, |
| 196 | }; | 191 | }; |
| ... | @@ -256,9 +251,13 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { | ... | @@ -256,9 +251,13 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 256 | found: Ty<'tcx>, | 251 | found: Ty<'tcx>, |
| 257 | param_env: ty::ParamEnv<'tcx>, | 252 | param_env: ty::ParamEnv<'tcx>, |
| 258 | ) { | 253 | ) { |
| 259 | let (alias, concrete) = match (expected.kind(), found.kind()) { | 254 | let (alias, &def_id, concrete) = match (expected.kind(), found.kind()) { |
| 260 | (ty::Alias(ty::Projection, proj), _) => (proj, found), | 255 | (ty::Alias(proj @ ty::AliasTy { kind: ty::Projection { def_id }, .. }), _) => { |
| 261 | (_, ty::Alias(ty::Projection, proj)) => (proj, expected), | 256 | (proj, def_id, found) |
| 257 | } | ||
| 258 | (_, ty::Alias(proj @ ty::AliasTy { kind: ty::Projection { def_id }, .. })) => { | ||
| 259 | (proj, def_id, expected) | ||
| 260 | } | ||
| 262 | _ => return, | 261 | _ => return, |
| 263 | }; | 262 | }; |
| 264 | 263 | ||
| ... | @@ -290,8 +289,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { | ... | @@ -290,8 +289,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 290 | return false; | 289 | return false; |
| 291 | } | 290 | } |
| 292 | 291 | ||
| 293 | let leaf_def = match specialization_graph::assoc_def(tcx, impl_def_id, alias.def_id) | 292 | let leaf_def = match specialization_graph::assoc_def(tcx, impl_def_id, def_id) { |
| 294 | { | ||
| 295 | Ok(leaf) => leaf, | 293 | Ok(leaf) => leaf, |
| 296 | Err(_) => return false, | 294 | Err(_) => return false, |
| 297 | }; | 295 | }; |
| ... | @@ -319,7 +317,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { | ... | @@ -319,7 +317,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 319 | "the associated type `{}` is defined as `{}` in the implementation, \ | 317 | "the associated type `{}` is defined as `{}` in the implementation, \ |
| 320 | but the where-bound `{}` shadows this definition\n\ | 318 | but the where-bound `{}` shadows this definition\n\ |
| 321 | see issue #152409 <https://github.com/rust-lang/rust/issues/152409> for more information", | 319 | see issue #152409 <https://github.com/rust-lang/rust/issues/152409> for more information", |
| 322 | self.ty_to_string(tcx.mk_ty_from_kind(ty::Alias(ty::Projection, *alias))), | 320 | self.ty_to_string(tcx.mk_ty_from_kind(ty::Alias(*alias))), |
| 323 | self.ty_to_string(concrete), | 321 | self.ty_to_string(concrete), |
| 324 | self.ty_to_string(alias.self_ty()) | 322 | self.ty_to_string(alias.self_ty()) |
| 325 | )); | 323 | )); |
| ... | @@ -1666,7 +1664,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { | ... | @@ -1666,7 +1664,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 1666 | && values.expected.sort_string(self.tcx) | 1664 | && values.expected.sort_string(self.tcx) |
| 1667 | != values.found.sort_string(self.tcx); | 1665 | != values.found.sort_string(self.tcx); |
| 1668 | let sort_string = |ty: Ty<'tcx>| match (extra, ty.kind()) { | 1666 | let sort_string = |ty: Ty<'tcx>| match (extra, ty.kind()) { |
| 1669 | (true, ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. })) => { | 1667 | (true, ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. })) => { |
| 1670 | let sm = self.tcx.sess.source_map(); | 1668 | let sm = self.tcx.sess.source_map(); |
| 1671 | let pos = sm.lookup_char_pos(self.tcx.def_span(*def_id).lo()); | 1669 | let pos = sm.lookup_char_pos(self.tcx.def_span(*def_id).lo()); |
| 1672 | DiagStyledString::normal(format!( | 1670 | DiagStyledString::normal(format!( |
| ... | @@ -1676,11 +1674,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { | ... | @@ -1676,11 +1674,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 1676 | pos.col.to_usize() + 1, | 1674 | pos.col.to_usize() + 1, |
| 1677 | )) | 1675 | )) |
| 1678 | } | 1676 | } |
| 1679 | (true, ty::Alias(ty::Projection, proj)) | 1677 | (true, &ty::Alias(ty::AliasTy { kind: ty::Projection { def_id }, .. })) |
| 1680 | if self.tcx.is_impl_trait_in_trait(proj.def_id) => | 1678 | if self.tcx.is_impl_trait_in_trait(def_id) => |
| 1681 | { | 1679 | { |
| 1682 | let sm = self.tcx.sess.source_map(); | 1680 | let sm = self.tcx.sess.source_map(); |
| 1683 | let pos = sm.lookup_char_pos(self.tcx.def_span(proj.def_id).lo()); | 1681 | let pos = sm.lookup_char_pos(self.tcx.def_span(def_id).lo()); |
| 1684 | DiagStyledString::normal(format!( | 1682 | DiagStyledString::normal(format!( |
| 1685 | " (trait associated opaque type at <{}:{}:{}>)", | 1683 | " (trait associated opaque type at <{}:{}:{}>)", |
| 1686 | sm.filename_for_diagnostics(&pos.file.name), | 1684 | sm.filename_for_diagnostics(&pos.file.name), |
| ... | @@ -2418,7 +2416,7 @@ impl TyCategory { | ... | @@ -2418,7 +2416,7 @@ impl TyCategory { |
| 2418 | pub fn from_ty(tcx: TyCtxt<'_>, ty: Ty<'_>) -> Option<(Self, DefId)> { | 2416 | pub fn from_ty(tcx: TyCtxt<'_>, ty: Ty<'_>) -> Option<(Self, DefId)> { |
| 2419 | match *ty.kind() { | 2417 | match *ty.kind() { |
| 2420 | ty::Closure(def_id, _) => Some((Self::Closure, def_id)), | 2418 | ty::Closure(def_id, _) => Some((Self::Closure, def_id)), |
| 2421 | ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => { | 2419 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }) => { |
| 2422 | let kind = | 2420 | let kind = |
| 2423 | if tcx.ty_is_opaque_future(ty) { Self::OpaqueFuture } else { Self::Opaque }; | 2421 | if tcx.ty_is_opaque_future(ty) { Self::OpaqueFuture } else { Self::Opaque }; |
| 2424 | Some((kind, def_id)) | 2422 | Some((kind, def_id)) |
compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs+1-1| ... | @@ -1021,7 +1021,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> { | ... | @@ -1021,7 +1021,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> { |
| 1021 | GenericArgKind::Type(ty) => { | 1021 | GenericArgKind::Type(ty) => { |
| 1022 | if matches!( | 1022 | if matches!( |
| 1023 | ty.kind(), | 1023 | ty.kind(), |
| 1024 | ty::Alias(ty::Opaque, ..) | 1024 | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) |
| 1025 | | ty::Closure(..) | 1025 | | ty::Closure(..) |
| 1026 | | ty::CoroutineClosure(..) | 1026 | | ty::CoroutineClosure(..) |
| 1027 | | ty::Coroutine(..) | 1027 | | ty::Coroutine(..) |
compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs+105-68| ... | @@ -46,7 +46,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { | ... | @@ -46,7 +46,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { |
| 46 | "consider pinning your async block and casting it to a trait object", | 46 | "consider pinning your async block and casting it to a trait object", |
| 47 | ); | 47 | ); |
| 48 | } | 48 | } |
| 49 | (ty::Alias(ty::Opaque, ..), ty::Alias(ty::Opaque, ..)) => { | 49 | ( |
| 50 | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }), | ||
| 51 | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }), | ||
| 52 | ) => { | ||
| 50 | // Issue #63167 | 53 | // Issue #63167 |
| 51 | diag.note("distinct uses of `impl Trait` result in different opaque types"); | 54 | diag.note("distinct uses of `impl Trait` result in different opaque types"); |
| 52 | } | 55 | } |
| ... | @@ -87,16 +90,27 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { | ... | @@ -87,16 +90,27 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { |
| 87 | ); | 90 | ); |
| 88 | } | 91 | } |
| 89 | ( | 92 | ( |
| 90 | ty::Alias(ty::Projection | ty::Inherent, _), | 93 | ty::Alias(ty::AliasTy { |
| 91 | ty::Alias(ty::Projection | ty::Inherent, _), | 94 | kind: ty::Projection { .. } | ty::Inherent { .. }, |
| 95 | .. | ||
| 96 | }), | ||
| 97 | ty::Alias(ty::AliasTy { | ||
| 98 | kind: ty::Projection { .. } | ty::Inherent { .. }, | ||
| 99 | .. | ||
| 100 | }), | ||
| 92 | ) => { | 101 | ) => { |
| 93 | diag.note("an associated type was expected, but a different one was found"); | 102 | diag.note("an associated type was expected, but a different one was found"); |
| 94 | } | 103 | } |
| 95 | // FIXME(inherent_associated_types): Extend this to support `ty::Inherent`, too. | 104 | // FIXME(inherent_associated_types): Extend this to support `ty::Inherent`, too. |
| 96 | (ty::Param(p), ty::Alias(ty::Projection, proj)) | 105 | ( |
| 97 | | (ty::Alias(ty::Projection, proj), ty::Param(p)) | 106 | ty::Param(p), |
| 98 | if !tcx.is_impl_trait_in_trait(proj.def_id) | 107 | ty::Alias(proj @ ty::AliasTy { kind: ty::Projection { def_id }, .. }), |
| 99 | && let Some(generics) = body_generics => | 108 | ) |
| 109 | | ( | ||
| 110 | ty::Alias(proj @ ty::AliasTy { kind: ty::Projection { def_id }, .. }), | ||
| 111 | ty::Param(p), | ||
| 112 | ) if !tcx.is_impl_trait_in_trait(def_id) | ||
| 113 | && let Some(generics) = body_generics => | ||
| 100 | { | 114 | { |
| 101 | let param = generics.type_param(p, tcx); | 115 | let param = generics.type_param(p, tcx); |
| 102 | let p_def_id = param.def_id; | 116 | let p_def_id = param.def_id; |
| ... | @@ -123,7 +137,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { | ... | @@ -123,7 +137,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { |
| 123 | // Synthesize the associated type restriction `Add<Output = Expected>`. | 137 | // Synthesize the associated type restriction `Add<Output = Expected>`. |
| 124 | // FIXME: extract this logic for use in other diagnostics. | 138 | // FIXME: extract this logic for use in other diagnostics. |
| 125 | let (trait_ref, assoc_args) = proj.trait_ref_and_own_args(tcx); | 139 | let (trait_ref, assoc_args) = proj.trait_ref_and_own_args(tcx); |
| 126 | let item_name = tcx.item_name(proj.def_id); | 140 | let item_name = tcx.item_name(def_id); |
| 127 | let item_args = self.format_generic_args(assoc_args); | 141 | let item_args = self.format_generic_args(assoc_args); |
| 128 | 142 | ||
| 129 | // Here, we try to see if there's an existing | 143 | // Here, we try to see if there's an existing |
| ... | @@ -188,8 +202,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { | ... | @@ -188,8 +202,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { |
| 188 | diag.note("you might be missing a type parameter or trait bound"); | 202 | diag.note("you might be missing a type parameter or trait bound"); |
| 189 | } | 203 | } |
| 190 | } | 204 | } |
| 191 | (ty::Param(p), ty::Dynamic(..) | ty::Alias(ty::Opaque, ..)) | 205 | ( |
| 192 | | (ty::Dynamic(..) | ty::Alias(ty::Opaque, ..), ty::Param(p)) => { | 206 | ty::Param(p), |
| 207 | ty::Dynamic(..) | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }), | ||
| 208 | ) | ||
| 209 | | ( | ||
| 210 | ty::Dynamic(..) | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }), | ||
| 211 | ty::Param(p), | ||
| 212 | ) => { | ||
| 193 | if let Some(generics) = body_generics { | 213 | if let Some(generics) = body_generics { |
| 194 | let p_span = tcx.def_span(generics.type_param(p, tcx).def_id); | 214 | let p_span = tcx.def_span(generics.type_param(p, tcx).def_id); |
| 195 | let expected = match (values.expected.kind(), values.found.kind()) { | 215 | let expected = match (values.expected.kind(), values.found.kind()) { |
| ... | @@ -261,9 +281,15 @@ impl<T> Trait<T> for X { | ... | @@ -261,9 +281,15 @@ impl<T> Trait<T> for X { |
| 261 | diag.span_label(p_span, format!("{expected}this type parameter")); | 281 | diag.span_label(p_span, format!("{expected}this type parameter")); |
| 262 | } | 282 | } |
| 263 | } | 283 | } |
| 264 | (ty::Alias(ty::Projection | ty::Inherent, proj_ty), _) | 284 | ( |
| 265 | if !tcx.is_impl_trait_in_trait(proj_ty.def_id) => | 285 | ty::Alias( |
| 266 | { | 286 | proj_ty @ ty::AliasTy { |
| 287 | kind: ty::Projection { def_id } | ty::Inherent { def_id }, | ||
| 288 | .. | ||
| 289 | }, | ||
| 290 | ), | ||
| 291 | _, | ||
| 292 | ) if !tcx.is_impl_trait_in_trait(def_id) => { | ||
| 267 | self.expected_projection( | 293 | self.expected_projection( |
| 268 | diag, | 294 | diag, |
| 269 | proj_ty, | 295 | proj_ty, |
| ... | @@ -274,11 +300,18 @@ impl<T> Trait<T> for X { | ... | @@ -274,11 +300,18 @@ impl<T> Trait<T> for X { |
| 274 | } | 300 | } |
| 275 | // Don't suggest constraining a projection to something | 301 | // Don't suggest constraining a projection to something |
| 276 | // containing itself, e.g. `Item = &<I as Iterator>::Item`. | 302 | // containing itself, e.g. `Item = &<I as Iterator>::Item`. |
| 277 | (_, ty::Alias(ty::Projection | ty::Inherent, proj_ty)) | 303 | ( |
| 278 | if !tcx.is_impl_trait_in_trait(proj_ty.def_id) | 304 | _, |
| 279 | && !tcx | 305 | ty::Alias( |
| 280 | .erase_and_anonymize_regions(values.expected) | 306 | proj_ty @ ty::AliasTy { |
| 281 | .contains(tcx.erase_and_anonymize_regions(values.found)) => | 307 | kind: ty::Projection { def_id } | ty::Inherent { def_id }, |
| 308 | .. | ||
| 309 | }, | ||
| 310 | ), | ||
| 311 | ) if !tcx.is_impl_trait_in_trait(def_id) | ||
| 312 | && !tcx | ||
| 313 | .erase_and_anonymize_regions(values.expected) | ||
| 314 | .contains(tcx.erase_and_anonymize_regions(values.found)) => | ||
| 282 | { | 315 | { |
| 283 | let msg = || { | 316 | let msg = || { |
| 284 | format!( | 317 | format!( |
| ... | @@ -286,20 +319,20 @@ impl<T> Trait<T> for X { | ... | @@ -286,20 +319,20 @@ impl<T> Trait<T> for X { |
| 286 | values.found, values.expected, | 319 | values.found, values.expected, |
| 287 | ) | 320 | ) |
| 288 | }; | 321 | }; |
| 289 | let suggested_projection_constraint = proj_ty.kind(tcx) | 322 | let suggested_projection_constraint = |
| 290 | == ty::AliasTyKind::Projection | 323 | matches!(proj_ty.kind, ty::Projection { .. }) |
| 291 | && (self.suggest_constraining_opaque_associated_type( | 324 | && (self.suggest_constraining_opaque_associated_type( |
| 292 | diag, | 325 | diag, |
| 293 | msg, | 326 | msg, |
| 294 | proj_ty, | 327 | proj_ty, |
| 295 | values.expected, | 328 | values.expected, |
| 296 | ) || self.suggest_constraint( | 329 | ) || self.suggest_constraint( |
| 297 | diag, | 330 | diag, |
| 298 | &msg, | 331 | &msg, |
| 299 | body_owner_def_id, | 332 | body_owner_def_id, |
| 300 | proj_ty, | 333 | proj_ty, |
| 301 | values.expected, | 334 | values.expected, |
| 302 | )); | 335 | )); |
| 303 | if !suggested_projection_constraint { | 336 | if !suggested_projection_constraint { |
| 304 | diag.help(msg()); | 337 | diag.help(msg()); |
| 305 | diag.note( | 338 | diag.note( |
| ... | @@ -308,21 +341,25 @@ impl<T> Trait<T> for X { | ... | @@ -308,21 +341,25 @@ impl<T> Trait<T> for X { |
| 308 | ); | 341 | ); |
| 309 | } | 342 | } |
| 310 | } | 343 | } |
| 311 | (ty::Dynamic(t, _), ty::Alias(ty::Opaque, alias)) | 344 | ( |
| 312 | if let Some(def_id) = t.principal_def_id() | 345 | ty::Dynamic(t, _), |
| 313 | && tcx | 346 | ty::Alias(ty::AliasTy { |
| 314 | .explicit_item_self_bounds(alias.def_id) | 347 | kind: ty::Opaque { def_id: opaque_def_id }, .. |
| 315 | .skip_binder() | 348 | }), |
| 316 | .iter() | 349 | ) if let Some(def_id) = t.principal_def_id() |
| 317 | .any(|(pred, _span)| match pred.kind().skip_binder() { | 350 | && tcx |
| 318 | ty::ClauseKind::Trait(trait_predicate) | 351 | .explicit_item_self_bounds(opaque_def_id) |
| 319 | if trait_predicate.polarity | 352 | .skip_binder() |
| 320 | == ty::PredicatePolarity::Positive => | 353 | .iter() |
| 321 | { | 354 | .any(|(pred, _span)| match pred.kind().skip_binder() { |
| 322 | trait_predicate.def_id() == def_id | 355 | ty::ClauseKind::Trait(trait_predicate) |
| 323 | } | 356 | if trait_predicate.polarity |
| 324 | _ => false, | 357 | == ty::PredicatePolarity::Positive => |
| 325 | }) => | 358 | { |
| 359 | trait_predicate.def_id() == def_id | ||
| 360 | } | ||
| 361 | _ => false, | ||
| 362 | }) => | ||
| 326 | { | 363 | { |
| 327 | diag.help(format!( | 364 | diag.help(format!( |
| 328 | "you can box the `{}` to coerce it to `Box<{}>`, but you'll have to \ | 365 | "you can box the `{}` to coerce it to `Box<{}>`, but you'll have to \ |
| ... | @@ -367,10 +404,10 @@ impl<T> Trait<T> for X { | ... | @@ -367,10 +404,10 @@ impl<T> Trait<T> for X { |
| 367 | )); | 404 | )); |
| 368 | } | 405 | } |
| 369 | } | 406 | } |
| 370 | (_, ty::Alias(ty::Opaque, opaque_ty)) | 407 | (_, ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. })) |
| 371 | | (ty::Alias(ty::Opaque, opaque_ty), _) => { | 408 | | (ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }), _) => { |
| 372 | if let Some(body_owner_def_id) = body_owner_def_id | 409 | if let Some(body_owner_def_id) = body_owner_def_id |
| 373 | && opaque_ty.def_id.is_local() | 410 | && def_id.is_local() |
| 374 | && matches!( | 411 | && matches!( |
| 375 | tcx.def_kind(body_owner_def_id), | 412 | tcx.def_kind(body_owner_def_id), |
| 376 | DefKind::Fn | 413 | DefKind::Fn |
| ... | @@ -380,23 +417,23 @@ impl<T> Trait<T> for X { | ... | @@ -380,23 +417,23 @@ impl<T> Trait<T> for X { |
| 380 | | DefKind::AssocConst { .. } | 417 | | DefKind::AssocConst { .. } |
| 381 | ) | 418 | ) |
| 382 | && matches!( | 419 | && matches!( |
| 383 | tcx.opaque_ty_origin(opaque_ty.def_id), | 420 | tcx.opaque_ty_origin(def_id), |
| 384 | hir::OpaqueTyOrigin::TyAlias { .. } | 421 | hir::OpaqueTyOrigin::TyAlias { .. } |
| 385 | ) | 422 | ) |
| 386 | && !tcx | 423 | && !tcx |
| 387 | .opaque_types_defined_by(body_owner_def_id.expect_local()) | 424 | .opaque_types_defined_by(body_owner_def_id.expect_local()) |
| 388 | .contains(&opaque_ty.def_id.expect_local()) | 425 | .contains(&def_id.expect_local()) |
| 389 | { | 426 | { |
| 390 | let sp = tcx | 427 | let sp = tcx |
| 391 | .def_ident_span(body_owner_def_id) | 428 | .def_ident_span(body_owner_def_id) |
| 392 | .unwrap_or_else(|| tcx.def_span(body_owner_def_id)); | 429 | .unwrap_or_else(|| tcx.def_span(body_owner_def_id)); |
| 393 | let mut alias_def_id = opaque_ty.def_id; | 430 | let mut alias_def_id = def_id; |
| 394 | while let DefKind::OpaqueTy = tcx.def_kind(alias_def_id) { | 431 | while let DefKind::OpaqueTy = tcx.def_kind(alias_def_id) { |
| 395 | alias_def_id = tcx.parent(alias_def_id); | 432 | alias_def_id = tcx.parent(alias_def_id); |
| 396 | } | 433 | } |
| 397 | let opaque_path = tcx.def_path_str(alias_def_id); | 434 | let opaque_path = tcx.def_path_str(alias_def_id); |
| 398 | // FIXME(type_alias_impl_trait): make this a structured suggestion | 435 | // FIXME(type_alias_impl_trait): make this a structured suggestion |
| 399 | match tcx.opaque_ty_origin(opaque_ty.def_id) { | 436 | match tcx.opaque_ty_origin(def_id) { |
| 400 | rustc_hir::OpaqueTyOrigin::FnReturn { .. } => {} | 437 | rustc_hir::OpaqueTyOrigin::FnReturn { .. } => {} |
| 401 | rustc_hir::OpaqueTyOrigin::AsyncFn { .. } => {} | 438 | rustc_hir::OpaqueTyOrigin::AsyncFn { .. } => {} |
| 402 | rustc_hir::OpaqueTyOrigin::TyAlias { | 439 | rustc_hir::OpaqueTyOrigin::TyAlias { |
| ... | @@ -448,7 +485,7 @@ impl<T> Trait<T> for X { | ... | @@ -448,7 +485,7 @@ impl<T> Trait<T> for X { |
| 448 | ty::Alias(..) => values.expected, | 485 | ty::Alias(..) => values.expected, |
| 449 | _ => values.found, | 486 | _ => values.found, |
| 450 | }; | 487 | }; |
| 451 | let preds = tcx.explicit_item_self_bounds(opaque_ty.def_id); | 488 | let preds = tcx.explicit_item_self_bounds(def_id); |
| 452 | for (pred, _span) in preds.skip_binder() { | 489 | for (pred, _span) in preds.skip_binder() { |
| 453 | let ty::ClauseKind::Trait(trait_predicate) = pred.kind().skip_binder() | 490 | let ty::ClauseKind::Trait(trait_predicate) = pred.kind().skip_binder() |
| 454 | else { | 491 | else { |
| ... | @@ -572,7 +609,7 @@ impl<T> Trait<T> for X { | ... | @@ -572,7 +609,7 @@ impl<T> Trait<T> for X { |
| 572 | let Some(body_owner_def_id) = body_owner_def_id else { | 609 | let Some(body_owner_def_id) = body_owner_def_id else { |
| 573 | return false; | 610 | return false; |
| 574 | }; | 611 | }; |
| 575 | let assoc = tcx.associated_item(proj_ty.def_id); | 612 | let assoc = tcx.associated_item(proj_ty.kind.def_id()); |
| 576 | let (trait_ref, assoc_args) = proj_ty.trait_ref_and_own_args(tcx); | 613 | let (trait_ref, assoc_args) = proj_ty.trait_ref_and_own_args(tcx); |
| 577 | let Some(item) = tcx.hir_get_if_local(body_owner_def_id) else { | 614 | let Some(item) = tcx.hir_get_if_local(body_owner_def_id) else { |
| 578 | return false; | 615 | return false; |
| ... | @@ -680,9 +717,9 @@ impl<T> Trait<T> for X { | ... | @@ -680,9 +717,9 @@ impl<T> Trait<T> for X { |
| 680 | let point_at_assoc_fn = if callable_scope | 717 | let point_at_assoc_fn = if callable_scope |
| 681 | && self.point_at_methods_that_satisfy_associated_type( | 718 | && self.point_at_methods_that_satisfy_associated_type( |
| 682 | diag, | 719 | diag, |
| 683 | tcx.parent(proj_ty.def_id), | 720 | tcx.parent(proj_ty.kind.def_id()), |
| 684 | current_method_ident, | 721 | current_method_ident, |
| 685 | proj_ty.def_id, | 722 | proj_ty.kind.def_id(), |
| 686 | values.expected, | 723 | values.expected, |
| 687 | ) { | 724 | ) { |
| 688 | // If we find a suitable associated function that returns the expected type, we | 725 | // If we find a suitable associated function that returns the expected type, we |
| ... | @@ -755,8 +792,10 @@ fn foo(&self) -> Self::T { String::new() } | ... | @@ -755,8 +792,10 @@ fn foo(&self) -> Self::T { String::new() } |
| 755 | ) -> bool { | 792 | ) -> bool { |
| 756 | let tcx = self.tcx; | 793 | let tcx = self.tcx; |
| 757 | 794 | ||
| 758 | let assoc = tcx.associated_item(proj_ty.def_id); | 795 | let assoc = tcx.associated_item(proj_ty.kind.def_id()); |
| 759 | if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *proj_ty.self_ty().kind() { | 796 | if let ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }) = |
| 797 | *proj_ty.self_ty().kind() | ||
| 798 | { | ||
| 760 | let opaque_local_def_id = def_id.as_local(); | 799 | let opaque_local_def_id = def_id.as_local(); |
| 761 | let opaque_hir_ty = if let Some(opaque_local_def_id) = opaque_local_def_id { | 800 | let opaque_hir_ty = if let Some(opaque_local_def_id) = opaque_local_def_id { |
| 762 | tcx.hir_expect_opaque_ty(opaque_local_def_id) | 801 | tcx.hir_expect_opaque_ty(opaque_local_def_id) |
| ... | @@ -805,14 +844,12 @@ fn foo(&self) -> Self::T { String::new() } | ... | @@ -805,14 +844,12 @@ fn foo(&self) -> Self::T { String::new() } |
| 805 | .filter_map(|item| { | 844 | .filter_map(|item| { |
| 806 | let method = tcx.fn_sig(item.def_id).instantiate_identity(); | 845 | let method = tcx.fn_sig(item.def_id).instantiate_identity(); |
| 807 | match *method.output().skip_binder().kind() { | 846 | match *method.output().skip_binder().kind() { |
| 808 | ty::Alias(ty::Projection, ty::AliasTy { def_id: item_def_id, .. }) | 847 | ty::Alias(ty::AliasTy { |
| 809 | if item_def_id == proj_ty_item_def_id => | 848 | kind: ty::Projection { def_id: item_def_id }, .. |
| 810 | { | 849 | }) if item_def_id == proj_ty_item_def_id => Some(( |
| 811 | Some(( | 850 | tcx.def_span(item.def_id), |
| 812 | tcx.def_span(item.def_id), | 851 | format!("consider calling `{}`", tcx.def_path_str(item.def_id)), |
| 813 | format!("consider calling `{}`", tcx.def_path_str(item.def_id)), | 852 | )), |
| 814 | )) | ||
| 815 | } | ||
| 816 | _ => None, | 853 | _ => None, |
| 817 | } | 854 | } |
| 818 | }) | 855 | }) |
compiler/rustc_trait_selection/src/error_reporting/infer/region.rs+7-7| ... | @@ -719,12 +719,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { | ... | @@ -719,12 +719,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 719 | let labeled_user_string = match bound_kind { | 719 | let labeled_user_string = match bound_kind { |
| 720 | GenericKind::Param(_) => format!("the parameter type `{bound_kind}`"), | 720 | GenericKind::Param(_) => format!("the parameter type `{bound_kind}`"), |
| 721 | GenericKind::Placeholder(_) => format!("the placeholder type `{bound_kind}`"), | 721 | GenericKind::Placeholder(_) => format!("the placeholder type `{bound_kind}`"), |
| 722 | GenericKind::Alias(p) => match p.kind(self.tcx) { | 722 | GenericKind::Alias(p) => match p.kind { |
| 723 | ty::Projection | ty::Inherent => { | 723 | ty::Projection { .. } | ty::Inherent { .. } => { |
| 724 | format!("the associated type `{bound_kind}`") | 724 | format!("the associated type `{bound_kind}`") |
| 725 | } | 725 | } |
| 726 | ty::Free => format!("the type alias `{bound_kind}`"), | 726 | ty::Free { .. } => format!("the type alias `{bound_kind}`"), |
| 727 | ty::Opaque => format!("the opaque type `{bound_kind}`"), | 727 | ty::Opaque { .. } => format!("the opaque type `{bound_kind}`"), |
| 728 | }, | 728 | }, |
| 729 | }; | 729 | }; |
| 730 | 730 | ||
| ... | @@ -846,10 +846,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { | ... | @@ -846,10 +846,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 846 | LifetimeSuggestion::HasColon => suggs.push((sp, format!(" {lt_name}"))), | 846 | LifetimeSuggestion::HasColon => suggs.push((sp, format!(" {lt_name}"))), |
| 847 | } | 847 | } |
| 848 | } else if let GenericKind::Alias(ref p) = bound_kind | 848 | } else if let GenericKind::Alias(ref p) = bound_kind |
| 849 | && let ty::Projection = p.kind(self.tcx) | 849 | && let ty::Projection { def_id } = p.kind |
| 850 | && let DefKind::AssocTy = self.tcx.def_kind(p.def_id) | 850 | && let DefKind::AssocTy = self.tcx.def_kind(def_id) |
| 851 | && let Some(ty::ImplTraitInTraitData::Trait { .. }) = | 851 | && let Some(ty::ImplTraitInTraitData::Trait { .. }) = |
| 852 | self.tcx.opt_rpitit_info(p.def_id) | 852 | self.tcx.opt_rpitit_info(def_id) |
| 853 | { | 853 | { |
| 854 | // The lifetime found in the `impl` is longer than the one on the RPITIT. | 854 | // The lifetime found in the `impl` is longer than the one on the RPITIT. |
| 855 | // Do not suggest `<Type as Trait>::{opaque}: 'static`. | 855 | // Do not suggest `<Type as Trait>::{opaque}: 'static`. |
compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs+12-4| ... | @@ -767,12 +767,20 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { | ... | @@ -767,12 +767,20 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { |
| 767 | StatementAsExpression::CorrectType | 767 | StatementAsExpression::CorrectType |
| 768 | } | 768 | } |
| 769 | ( | 769 | ( |
| 770 | ty::Alias(ty::Opaque, ty::AliasTy { def_id: last_def_id, .. }), | 770 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: last_def_id }, .. }), |
| 771 | ty::Alias(ty::Opaque, ty::AliasTy { def_id: exp_def_id, .. }), | 771 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: exp_def_id }, .. }), |
| 772 | ) if last_def_id == exp_def_id => StatementAsExpression::CorrectType, | 772 | ) if last_def_id == exp_def_id => StatementAsExpression::CorrectType, |
| 773 | ( | 773 | ( |
| 774 | ty::Alias(ty::Opaque, ty::AliasTy { def_id: last_def_id, args: last_bounds, .. }), | 774 | ty::Alias(ty::AliasTy { |
| 775 | ty::Alias(ty::Opaque, ty::AliasTy { def_id: exp_def_id, args: exp_bounds, .. }), | 775 | kind: ty::Opaque { def_id: last_def_id }, |
| 776 | args: last_bounds, | ||
| 777 | .. | ||
| 778 | }), | ||
| 779 | ty::Alias(ty::AliasTy { | ||
| 780 | kind: ty::Opaque { def_id: exp_def_id }, | ||
| 781 | args: exp_bounds, | ||
| 782 | .. | ||
| 783 | }), | ||
| 776 | ) => { | 784 | ) => { |
| 777 | debug!( | 785 | debug!( |
| 778 | "both opaque, likely future {:?} {:?} {:?} {:?}", | 786 | "both opaque, likely future {:?} {:?} {:?} {:?}", |
compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs+4-4| ... | @@ -1876,10 +1876,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { | ... | @@ -1876,10 +1876,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 1876 | ty::Closure(..) => Some(9), | 1876 | ty::Closure(..) => Some(9), |
| 1877 | ty::Tuple(..) => Some(10), | 1877 | ty::Tuple(..) => Some(10), |
| 1878 | ty::Param(..) => Some(11), | 1878 | ty::Param(..) => Some(11), |
| 1879 | ty::Alias(ty::Projection, ..) => Some(12), | 1879 | ty::Alias(ty::AliasTy { kind: ty::Projection { .. }, .. }) => Some(12), |
| 1880 | ty::Alias(ty::Inherent, ..) => Some(13), | 1880 | ty::Alias(ty::AliasTy { kind: ty::Inherent { .. }, .. }) => Some(13), |
| 1881 | ty::Alias(ty::Opaque, ..) => Some(14), | 1881 | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) => Some(14), |
| 1882 | ty::Alias(ty::Free, ..) => Some(15), | 1882 | ty::Alias(ty::AliasTy { kind: ty::Free { .. }, .. }) => Some(15), |
| 1883 | ty::Never => Some(16), | 1883 | ty::Never => Some(16), |
| 1884 | ty::Adt(..) => Some(17), | 1884 | ty::Adt(..) => Some(17), |
| 1885 | ty::Coroutine(..) => Some(18), | 1885 | ty::Coroutine(..) => Some(18), |
compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs+19-11| ... | @@ -139,9 +139,11 @@ pub fn suggest_restriction<'tcx, G: EmissionGuarantee>( | ... | @@ -139,9 +139,11 @@ pub fn suggest_restriction<'tcx, G: EmissionGuarantee>( |
| 139 | if hir_generics.where_clause_span.from_expansion() | 139 | if hir_generics.where_clause_span.from_expansion() |
| 140 | || hir_generics.where_clause_span.desugaring_kind().is_some() | 140 | || hir_generics.where_clause_span.desugaring_kind().is_some() |
| 141 | || projection.is_some_and(|projection| { | 141 | || projection.is_some_and(|projection| { |
| 142 | (tcx.is_impl_trait_in_trait(projection.def_id) | 142 | (tcx.is_impl_trait_in_trait(projection.kind.def_id()) |
| 143 | && !tcx.features().return_type_notation()) | 143 | && !tcx.features().return_type_notation()) |
| 144 | || tcx.lookup_stability(projection.def_id).is_some_and(|stab| stab.is_unstable()) | 144 | || tcx |
| 145 | .lookup_stability(projection.kind.def_id()) | ||
| 146 | .is_some_and(|stab| stab.is_unstable()) | ||
| 145 | }) | 147 | }) |
| 146 | { | 148 | { |
| 147 | return; | 149 | return; |
| ... | @@ -467,7 +469,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { | ... | @@ -467,7 +469,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 467 | let self_ty = trait_pred.skip_binder().self_ty(); | 469 | let self_ty = trait_pred.skip_binder().self_ty(); |
| 468 | let (param_ty, projection) = match *self_ty.kind() { | 470 | let (param_ty, projection) = match *self_ty.kind() { |
| 469 | ty::Param(_) => (true, None), | 471 | ty::Param(_) => (true, None), |
| 470 | ty::Alias(ty::Projection, projection) => (false, Some(projection)), | 472 | ty::Alias(projection @ ty::AliasTy { kind: ty::Projection { .. }, .. }) => { |
| 473 | (false, Some(projection)) | ||
| 474 | } | ||
| 471 | _ => (false, None), | 475 | _ => (false, None), |
| 472 | }; | 476 | }; |
| 473 | 477 | ||
| ... | @@ -1365,7 +1369,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { | ... | @@ -1365,7 +1369,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 1365 | sig_parts.map_bound(|sig| sig.tupled_inputs_ty.tuple_fields().as_slice()), | 1369 | sig_parts.map_bound(|sig| sig.tupled_inputs_ty.tuple_fields().as_slice()), |
| 1366 | )) | 1370 | )) |
| 1367 | } | 1371 | } |
| 1368 | ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => { | 1372 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { |
| 1369 | self.tcx.item_self_bounds(def_id).instantiate(self.tcx, args).iter().find_map( | 1373 | self.tcx.item_self_bounds(def_id).instantiate(self.tcx, args).iter().find_map( |
| 1370 | |pred| { | 1374 | |pred| { |
| 1371 | if let ty::ClauseKind::Projection(proj) = pred.kind().skip_binder() | 1375 | if let ty::ClauseKind::Projection(proj) = pred.kind().skip_binder() |
| ... | @@ -3702,7 +3706,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { | ... | @@ -3702,7 +3706,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 3702 | } | 3706 | } |
| 3703 | } | 3707 | } |
| 3704 | } | 3708 | } |
| 3705 | ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => { | 3709 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }) => { |
| 3706 | // If the previous type is async fn, this is the future generated by the body of an async function. | 3710 | // If the previous type is async fn, this is the future generated by the body of an async function. |
| 3707 | // Avoid printing it twice (it was already printed in the `ty::Coroutine` arm below). | 3711 | // Avoid printing it twice (it was already printed in the `ty::Coroutine` arm below). |
| 3708 | let is_future = tcx.ty_is_opaque_future(ty); | 3712 | let is_future = tcx.ty_is_opaque_future(ty); |
| ... | @@ -4987,14 +4991,16 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { | ... | @@ -4987,14 +4991,16 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 4987 | let TypeError::Sorts(expected_found) = diff else { | 4991 | let TypeError::Sorts(expected_found) = diff else { |
| 4988 | continue; | 4992 | continue; |
| 4989 | }; | 4993 | }; |
| 4990 | let ty::Alias(ty::Projection, proj) = expected_found.expected.kind() else { | 4994 | let ty::Alias(ty::AliasTy { kind: ty::Projection { def_id }, .. }) = |
| 4995 | expected_found.expected.kind() | ||
| 4996 | else { | ||
| 4991 | continue; | 4997 | continue; |
| 4992 | }; | 4998 | }; |
| 4993 | 4999 | ||
| 4994 | // Make `Self` be equivalent to the type of the call chain | 5000 | // Make `Self` be equivalent to the type of the call chain |
| 4995 | // expression we're looking at now, so that we can tell what | 5001 | // expression we're looking at now, so that we can tell what |
| 4996 | // for example `Iterator::Item` is at this point in the chain. | 5002 | // for example `Iterator::Item` is at this point in the chain. |
| 4997 | let args = GenericArgs::for_item(self.tcx, proj.def_id, |param, _| { | 5003 | let args = GenericArgs::for_item(self.tcx, *def_id, |param, _| { |
| 4998 | if param.index == 0 { | 5004 | if param.index == 0 { |
| 4999 | debug_assert_matches!(param.kind, ty::GenericParamDefKind::Type { .. }); | 5005 | debug_assert_matches!(param.kind, ty::GenericParamDefKind::Type { .. }); |
| 5000 | return prev_ty.into(); | 5006 | return prev_ty.into(); |
| ... | @@ -5008,7 +5014,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { | ... | @@ -5008,7 +5014,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 5008 | // This corresponds to `<ExprTy as Iterator>::Item = _`. | 5014 | // This corresponds to `<ExprTy as Iterator>::Item = _`. |
| 5009 | let projection = ty::Binder::dummy(ty::PredicateKind::Clause( | 5015 | let projection = ty::Binder::dummy(ty::PredicateKind::Clause( |
| 5010 | ty::ClauseKind::Projection(ty::ProjectionPredicate { | 5016 | ty::ClauseKind::Projection(ty::ProjectionPredicate { |
| 5011 | projection_term: ty::AliasTerm::new_from_args(self.tcx, proj.def_id, args), | 5017 | projection_term: ty::AliasTerm::new_from_args(self.tcx, *def_id, args), |
| 5012 | term: ty.into(), | 5018 | term: ty.into(), |
| 5013 | }), | 5019 | }), |
| 5014 | )); | 5020 | )); |
| ... | @@ -5025,7 +5031,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { | ... | @@ -5025,7 +5031,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 5025 | && let ty = self.resolve_vars_if_possible(ty) | 5031 | && let ty = self.resolve_vars_if_possible(ty) |
| 5026 | && !ty.is_ty_var() | 5032 | && !ty.is_ty_var() |
| 5027 | { | 5033 | { |
| 5028 | assocs_in_this_method.push(Some((span, (proj.def_id, ty)))); | 5034 | assocs_in_this_method.push(Some((span, (*def_id, ty)))); |
| 5029 | } else { | 5035 | } else { |
| 5030 | // `<ExprTy as Iterator>` didn't select, so likely we've | 5036 | // `<ExprTy as Iterator>` didn't select, so likely we've |
| 5031 | // reached the end of the iterator chain, like the originating | 5037 | // reached the end of the iterator chain, like the originating |
| ... | @@ -5309,11 +5315,13 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { | ... | @@ -5309,11 +5315,13 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 5309 | } | 5315 | } |
| 5310 | 5316 | ||
| 5311 | // Look for an RPITIT | 5317 | // Look for an RPITIT |
| 5312 | let ty::Alias(ty::Projection, alias_ty) = trait_pred.self_ty().skip_binder().kind() else { | 5318 | let ty::Alias(alias_ty @ ty::AliasTy { kind: ty::Projection { def_id }, .. }) = |
| 5319 | trait_pred.self_ty().skip_binder().kind() | ||
| 5320 | else { | ||
| 5313 | return; | 5321 | return; |
| 5314 | }; | 5322 | }; |
| 5315 | let Some(ty::ImplTraitInTraitData::Trait { fn_def_id, opaque_def_id }) = | 5323 | let Some(ty::ImplTraitInTraitData::Trait { fn_def_id, opaque_def_id }) = |
| 5316 | self.tcx.opt_rpitit_info(alias_ty.def_id) | 5324 | self.tcx.opt_rpitit_info(*def_id) |
| 5317 | else { | 5325 | else { |
| 5318 | return; | 5326 | return; |
| 5319 | }; | 5327 | }; |
compiler/rustc_trait_selection/src/traits/auto_trait.rs+4-2| ... | @@ -546,14 +546,16 @@ impl<'tcx> AutoTraitFinder<'tcx> { | ... | @@ -546,14 +546,16 @@ impl<'tcx> AutoTraitFinder<'tcx> { |
| 546 | pub fn is_of_param(&self, ty: Ty<'tcx>) -> bool { | 546 | pub fn is_of_param(&self, ty: Ty<'tcx>) -> bool { |
| 547 | match ty.kind() { | 547 | match ty.kind() { |
| 548 | ty::Param(_) => true, | 548 | ty::Param(_) => true, |
| 549 | ty::Alias(ty::Projection, p) => self.is_of_param(p.self_ty()), | 549 | ty::Alias(p @ ty::AliasTy { kind: ty::Projection { .. }, .. }) => { |
| 550 | self.is_of_param(p.self_ty()) | ||
| 551 | } | ||
| 550 | _ => false, | 552 | _ => false, |
| 551 | } | 553 | } |
| 552 | } | 554 | } |
| 553 | 555 | ||
| 554 | fn is_self_referential_projection(&self, p: ty::PolyProjectionPredicate<'tcx>) -> bool { | 556 | fn is_self_referential_projection(&self, p: ty::PolyProjectionPredicate<'tcx>) -> bool { |
| 555 | if let Some(ty) = p.term().skip_binder().as_type() { | 557 | if let Some(ty) = p.term().skip_binder().as_type() { |
| 556 | matches!(ty.kind(), ty::Alias(ty::Projection, proj) if proj == &p.skip_binder().projection_term.expect_ty(self.tcx)) | 558 | matches!(ty.kind(), ty::Alias(proj @ ty::AliasTy { kind: ty::Projection { .. }, .. }) if proj == &p.skip_binder().projection_term.expect_ty(self.tcx)) |
| 557 | } else { | 559 | } else { |
| 558 | false | 560 | false |
| 559 | } | 561 | } |
compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs+7-5| ... | @@ -811,11 +811,13 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IllegalSelfTypeVisitor<'tcx> { | ... | @@ -811,11 +811,13 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IllegalSelfTypeVisitor<'tcx> { |
| 811 | ControlFlow::Continue(()) | 811 | ControlFlow::Continue(()) |
| 812 | } | 812 | } |
| 813 | } | 813 | } |
| 814 | ty::Alias(ty::Projection, proj) if self.tcx.is_impl_trait_in_trait(proj.def_id) => { | 814 | ty::Alias(ty::AliasTy { kind: ty::Projection { def_id }, .. }) |
| 815 | if self.tcx.is_impl_trait_in_trait(*def_id) => | ||
| 816 | { | ||
| 815 | // We'll deny these later in their own pass | 817 | // We'll deny these later in their own pass |
| 816 | ControlFlow::Continue(()) | 818 | ControlFlow::Continue(()) |
| 817 | } | 819 | } |
| 818 | ty::Alias(ty::Projection, proj) => { | 820 | ty::Alias(proj @ ty::AliasTy { kind: ty::Projection { .. }, .. }) => { |
| 819 | match self.allow_self_projections { | 821 | match self.allow_self_projections { |
| 820 | AllowSelfProjections::Yes => { | 822 | AllowSelfProjections::Yes => { |
| 821 | // Only walk contained types if the parent trait is not a supertrait. | 823 | // Only walk contained types if the parent trait is not a supertrait. |
| ... | @@ -914,12 +916,12 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IllegalRpititVisitor<'tcx> { | ... | @@ -914,12 +916,12 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IllegalRpititVisitor<'tcx> { |
| 914 | type Result = ControlFlow<MethodViolation>; | 916 | type Result = ControlFlow<MethodViolation>; |
| 915 | 917 | ||
| 916 | fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result { | 918 | fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result { |
| 917 | if let ty::Alias(ty::Projection, proj) = *ty.kind() | 919 | if let ty::Alias(proj @ ty::AliasTy { kind: ty::Projection { def_id }, .. }) = *ty.kind() |
| 918 | && Some(proj) != self.allowed | 920 | && Some(proj) != self.allowed |
| 919 | && self.tcx.is_impl_trait_in_trait(proj.def_id) | 921 | && self.tcx.is_impl_trait_in_trait(def_id) |
| 920 | { | 922 | { |
| 921 | ControlFlow::Break(MethodViolation::ReferencesImplTraitInTrait( | 923 | ControlFlow::Break(MethodViolation::ReferencesImplTraitInTrait( |
| 922 | self.tcx.def_span(proj.def_id), | 924 | self.tcx.def_span(def_id), |
| 923 | )) | 925 | )) |
| 924 | } else { | 926 | } else { |
| 925 | ty.super_visit_with(self) | 927 | ty.super_visit_with(self) |
compiler/rustc_trait_selection/src/traits/effects.rs+21-9| ... | @@ -178,11 +178,17 @@ fn evaluate_host_effect_from_conditionally_const_item_bounds<'tcx>( | ... | @@ -178,11 +178,17 @@ fn evaluate_host_effect_from_conditionally_const_item_bounds<'tcx>( |
| 178 | let mut candidate = None; | 178 | let mut candidate = None; |
| 179 | 179 | ||
| 180 | let mut consider_ty = obligation.predicate.self_ty(); | 180 | let mut consider_ty = obligation.predicate.self_ty(); |
| 181 | while let ty::Alias(kind @ (ty::Projection | ty::Opaque), alias_ty) = *consider_ty.kind() { | 181 | while let ty::Alias( |
| 182 | if tcx.is_conditionally_const(alias_ty.def_id) { | 182 | alias_ty @ ty::AliasTy { |
| 183 | kind: kind @ (ty::Projection { def_id } | ty::Opaque { def_id }), | ||
| 184 | .. | ||
| 185 | }, | ||
| 186 | ) = *consider_ty.kind() | ||
| 187 | { | ||
| 188 | if tcx.is_conditionally_const(def_id) { | ||
| 183 | for clause in elaborate( | 189 | for clause in elaborate( |
| 184 | tcx, | 190 | tcx, |
| 185 | tcx.explicit_implied_const_bounds(alias_ty.def_id) | 191 | tcx.explicit_implied_const_bounds(def_id) |
| 186 | .iter_instantiated_copied(tcx, alias_ty.args) | 192 | .iter_instantiated_copied(tcx, alias_ty.args) |
| 187 | .map(|(trait_ref, _)| { | 193 | .map(|(trait_ref, _)| { |
| 188 | trait_ref.to_host_effect_clause(tcx, obligation.predicate.constness) | 194 | trait_ref.to_host_effect_clause(tcx, obligation.predicate.constness) |
| ... | @@ -217,7 +223,7 @@ fn evaluate_host_effect_from_conditionally_const_item_bounds<'tcx>( | ... | @@ -217,7 +223,7 @@ fn evaluate_host_effect_from_conditionally_const_item_bounds<'tcx>( |
| 217 | } | 223 | } |
| 218 | } | 224 | } |
| 219 | 225 | ||
| 220 | if kind != ty::Projection { | 226 | if !matches!(kind, ty::Projection { .. }) { |
| 221 | break; | 227 | break; |
| 222 | } | 228 | } |
| 223 | 229 | ||
| ... | @@ -233,7 +239,7 @@ fn evaluate_host_effect_from_conditionally_const_item_bounds<'tcx>( | ... | @@ -233,7 +239,7 @@ fn evaluate_host_effect_from_conditionally_const_item_bounds<'tcx>( |
| 233 | obligation.param_env, | 239 | obligation.param_env, |
| 234 | obligation.cause.clone(), | 240 | obligation.cause.clone(), |
| 235 | obligation.recursion_depth, | 241 | obligation.recursion_depth, |
| 236 | tcx.const_conditions(alias_ty.def_id).instantiate(tcx, alias_ty.args), | 242 | tcx.const_conditions(alias_ty.kind.def_id()).instantiate(tcx, alias_ty.args), |
| 237 | nested, | 243 | nested, |
| 238 | ); | 244 | ); |
| 239 | nested.extend(const_conditions.into_iter().map(|(trait_ref, _)| { | 245 | nested.extend(const_conditions.into_iter().map(|(trait_ref, _)| { |
| ... | @@ -259,8 +265,14 @@ fn evaluate_host_effect_from_item_bounds<'tcx>( | ... | @@ -259,8 +265,14 @@ fn evaluate_host_effect_from_item_bounds<'tcx>( |
| 259 | let mut candidate = None; | 265 | let mut candidate = None; |
| 260 | 266 | ||
| 261 | let mut consider_ty = obligation.predicate.self_ty(); | 267 | let mut consider_ty = obligation.predicate.self_ty(); |
| 262 | while let ty::Alias(kind @ (ty::Projection | ty::Opaque), alias_ty) = *consider_ty.kind() { | 268 | while let ty::Alias( |
| 263 | for clause in tcx.item_bounds(alias_ty.def_id).iter_instantiated(tcx, alias_ty.args) { | 269 | alias_ty @ ty::AliasTy { |
| 270 | kind: kind @ (ty::Projection { def_id } | ty::Opaque { def_id }), | ||
| 271 | .. | ||
| 272 | }, | ||
| 273 | ) = *consider_ty.kind() | ||
| 274 | { | ||
| 275 | for clause in tcx.item_bounds(def_id).iter_instantiated(tcx, alias_ty.args) { | ||
| 264 | let bound_clause = clause.kind(); | 276 | let bound_clause = clause.kind(); |
| 265 | let ty::ClauseKind::HostEffect(data) = bound_clause.skip_binder() else { | 277 | let ty::ClauseKind::HostEffect(data) = bound_clause.skip_binder() else { |
| 266 | continue; | 278 | continue; |
| ... | @@ -289,7 +301,7 @@ fn evaluate_host_effect_from_item_bounds<'tcx>( | ... | @@ -289,7 +301,7 @@ fn evaluate_host_effect_from_item_bounds<'tcx>( |
| 289 | } | 301 | } |
| 290 | } | 302 | } |
| 291 | 303 | ||
| 292 | if kind != ty::Projection { | 304 | if !matches!(kind, ty::Projection { .. }) { |
| 293 | break; | 305 | break; |
| 294 | } | 306 | } |
| 295 | 307 | ||
| ... | @@ -352,7 +364,7 @@ fn evaluate_host_effect_for_copy_clone_goal<'tcx>( | ... | @@ -352,7 +364,7 @@ fn evaluate_host_effect_for_copy_clone_goal<'tcx>( |
| 352 | | ty::Foreign(..) | 364 | | ty::Foreign(..) |
| 353 | | ty::Ref(_, _, ty::Mutability::Mut) | 365 | | ty::Ref(_, _, ty::Mutability::Mut) |
| 354 | | ty::Adt(_, _) | 366 | | ty::Adt(_, _) |
| 355 | | ty::Alias(_, _) | 367 | | ty::Alias(_) |
| 356 | | ty::Param(_) | 368 | | ty::Param(_) |
| 357 | | ty::Placeholder(..) => Err(EvaluationFailure::NoSolution), | 369 | | ty::Placeholder(..) => Err(EvaluationFailure::NoSolution), |
| 358 | 370 |
compiler/rustc_trait_selection/src/traits/normalize.rs+7-10| ... | @@ -366,10 +366,7 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx | ... | @@ -366,10 +366,7 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx |
| 366 | return ty; | 366 | return ty; |
| 367 | } | 367 | } |
| 368 | 368 | ||
| 369 | let (kind, data) = match *ty.kind() { | 369 | let ty::Alias(data) = *ty.kind() else { return ty.super_fold_with(self) }; |
| 370 | ty::Alias(kind, data) => (kind, data), | ||
| 371 | _ => return ty.super_fold_with(self), | ||
| 372 | }; | ||
| 373 | 370 | ||
| 374 | // We try to be a little clever here as a performance optimization in | 371 | // We try to be a little clever here as a performance optimization in |
| 375 | // cases where there are nested projections under binders. | 372 | // cases where there are nested projections under binders. |
| ... | @@ -394,8 +391,8 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx | ... | @@ -394,8 +391,8 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx |
| 394 | // replace bound vars if the current type is a `Projection` and we need | 391 | // replace bound vars if the current type is a `Projection` and we need |
| 395 | // to make sure we don't forget to fold the args regardless. | 392 | // to make sure we don't forget to fold the args regardless. |
| 396 | 393 | ||
| 397 | match kind { | 394 | match data.kind { |
| 398 | ty::Opaque => { | 395 | ty::Opaque { def_id } => { |
| 399 | // Only normalize `impl Trait` outside of type inference, usually in codegen. | 396 | // Only normalize `impl Trait` outside of type inference, usually in codegen. |
| 400 | match self.selcx.infcx.typing_mode() { | 397 | match self.selcx.infcx.typing_mode() { |
| 401 | // FIXME(#132279): We likely want to reveal opaques during post borrowck analysis | 398 | // FIXME(#132279): We likely want to reveal opaques during post borrowck analysis |
| ... | @@ -415,7 +412,7 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx | ... | @@ -415,7 +412,7 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx |
| 415 | } | 412 | } |
| 416 | 413 | ||
| 417 | let args = data.args.fold_with(self); | 414 | let args = data.args.fold_with(self); |
| 418 | let generic_ty = self.cx().type_of(data.def_id); | 415 | let generic_ty = self.cx().type_of(def_id); |
| 419 | let concrete_ty = generic_ty.instantiate(self.cx(), args); | 416 | let concrete_ty = generic_ty.instantiate(self.cx(), args); |
| 420 | self.depth += 1; | 417 | self.depth += 1; |
| 421 | let folded_ty = self.fold_ty(concrete_ty); | 418 | let folded_ty = self.fold_ty(concrete_ty); |
| ... | @@ -425,9 +422,9 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx | ... | @@ -425,9 +422,9 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx |
| 425 | } | 422 | } |
| 426 | } | 423 | } |
| 427 | 424 | ||
| 428 | ty::Projection => self.normalize_trait_projection(data.into()).expect_type(), | 425 | ty::Projection { .. } => self.normalize_trait_projection(data.into()).expect_type(), |
| 429 | ty::Inherent => self.normalize_inherent_projection(data.into()).expect_type(), | 426 | ty::Inherent { .. } => self.normalize_inherent_projection(data.into()).expect_type(), |
| 430 | ty::Free => self.normalize_free_alias(data.into()).expect_type(), | 427 | ty::Free { .. } => self.normalize_free_alias(data.into()).expect_type(), |
| 431 | } | 428 | } |
| 432 | } | 429 | } |
| 433 | 430 |
compiler/rustc_trait_selection/src/traits/query/normalize.rs+9-12| ... | @@ -202,19 +202,16 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'a, 'tcx> { | ... | @@ -202,19 +202,16 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'a, 'tcx> { |
| 202 | return Ok(*ty); | 202 | return Ok(*ty); |
| 203 | } | 203 | } |
| 204 | 204 | ||
| 205 | let (kind, data) = match *ty.kind() { | 205 | let &ty::Alias(data) = ty.kind() else { |
| 206 | ty::Alias(kind, data) => (kind, data), | 206 | let res = ty.try_super_fold_with(self)?; |
| 207 | _ => { | 207 | self.cache.insert(ty, res); |
| 208 | let res = ty.try_super_fold_with(self)?; | 208 | return Ok(res); |
| 209 | self.cache.insert(ty, res); | ||
| 210 | return Ok(res); | ||
| 211 | } | ||
| 212 | }; | 209 | }; |
| 213 | 210 | ||
| 214 | // See note in `rustc_trait_selection::traits::project` about why we | 211 | // See note in `rustc_trait_selection::traits::project` about why we |
| 215 | // wait to fold the args. | 212 | // wait to fold the args. |
| 216 | let res = match kind { | 213 | let res = match data.kind { |
| 217 | ty::Opaque => { | 214 | ty::Opaque { .. } => { |
| 218 | // Only normalize `impl Trait` outside of type inference, usually in codegen. | 215 | // Only normalize `impl Trait` outside of type inference, usually in codegen. |
| 219 | match self.infcx.typing_mode() { | 216 | match self.infcx.typing_mode() { |
| 220 | TypingMode::Coherence | 217 | TypingMode::Coherence |
| ... | @@ -239,7 +236,7 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'a, 'tcx> { | ... | @@ -239,7 +236,7 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'a, 'tcx> { |
| 239 | return Ok(Ty::new_error(self.cx(), guar)); | 236 | return Ok(Ty::new_error(self.cx(), guar)); |
| 240 | } | 237 | } |
| 241 | 238 | ||
| 242 | let generic_ty = self.cx().type_of(data.def_id); | 239 | let generic_ty = self.cx().type_of(data.kind.def_id()); |
| 243 | let mut concrete_ty = generic_ty.instantiate(self.cx(), args); | 240 | let mut concrete_ty = generic_ty.instantiate(self.cx(), args); |
| 244 | self.anon_depth += 1; | 241 | self.anon_depth += 1; |
| 245 | if concrete_ty == ty { | 242 | if concrete_ty == ty { |
| ... | @@ -256,8 +253,8 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'a, 'tcx> { | ... | @@ -256,8 +253,8 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'a, 'tcx> { |
| 256 | } | 253 | } |
| 257 | } | 254 | } |
| 258 | 255 | ||
| 259 | ty::Projection | ty::Inherent | ty::Free => self | 256 | ty::Projection { def_id } | ty::Inherent { def_id } | ty::Free { def_id } => self |
| 260 | .try_fold_free_or_assoc(ty::AliasTerm::new(self.cx(), data.def_id, data.args))? | 257 | .try_fold_free_or_assoc(ty::AliasTerm::new(self.cx(), def_id, data.args))? |
| 261 | .expect_type(), | 258 | .expect_type(), |
| 262 | }; | 259 | }; |
| 263 | 260 |
compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs+8-5| ... | @@ -194,7 +194,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | ... | @@ -194,7 +194,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { |
| 194 | // quickly check if the self-type is a projection at all. | 194 | // quickly check if the self-type is a projection at all. |
| 195 | match obligation.predicate.skip_binder().trait_ref.self_ty().kind() { | 195 | match obligation.predicate.skip_binder().trait_ref.self_ty().kind() { |
| 196 | // Excluding IATs and type aliases here as they don't have meaningful item bounds. | 196 | // Excluding IATs and type aliases here as they don't have meaningful item bounds. |
| 197 | ty::Alias(ty::Projection | ty::Opaque, _) => {} | 197 | ty::Alias(ty::AliasTy { kind: ty::Projection { .. } | ty::Opaque { .. }, .. }) => {} |
| 198 | ty::Infer(ty::TyVar(_)) => { | 198 | ty::Infer(ty::TyVar(_)) => { |
| 199 | span_bug!( | 199 | span_bug!( |
| 200 | obligation.cause.span, | 200 | obligation.cause.span, |
| ... | @@ -681,7 +681,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | ... | @@ -681,7 +681,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { |
| 681 | // These may potentially implement `FnPtr` | 681 | // These may potentially implement `FnPtr` |
| 682 | ty::Placeholder(..) | 682 | ty::Placeholder(..) |
| 683 | | ty::Dynamic(_, _) | 683 | | ty::Dynamic(_, _) |
| 684 | | ty::Alias(_, _) | 684 | | ty::Alias(_) |
| 685 | | ty::Infer(_) | 685 | | ty::Infer(_) |
| 686 | | ty::Param(..) | 686 | | ty::Param(..) |
| 687 | | ty::Bound(_, _) => {} | 687 | | ty::Bound(_, _) => {} |
| ... | @@ -784,7 +784,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | ... | @@ -784,7 +784,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { |
| 784 | } | 784 | } |
| 785 | } | 785 | } |
| 786 | ty::Param(..) | 786 | ty::Param(..) |
| 787 | | ty::Alias(ty::Projection | ty::Inherent | ty::Free, ..) | 787 | | ty::Alias(ty::AliasTy { |
| 788 | kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Free { .. }, | ||
| 789 | .. | ||
| 790 | }) | ||
| 788 | | ty::Placeholder(..) | 791 | | ty::Placeholder(..) |
| 789 | | ty::Bound(..) => { | 792 | | ty::Bound(..) => { |
| 790 | // In these cases, we don't know what the actual | 793 | // In these cases, we don't know what the actual |
| ... | @@ -835,7 +838,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | ... | @@ -835,7 +838,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { |
| 835 | ); | 838 | ); |
| 836 | } | 839 | } |
| 837 | 840 | ||
| 838 | ty::Alias(ty::Opaque, alias) => { | 841 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }) => { |
| 839 | if candidates.vec.iter().any(|c| matches!(c, ProjectionCandidate { .. })) { | 842 | if candidates.vec.iter().any(|c| matches!(c, ProjectionCandidate { .. })) { |
| 840 | // We do not generate an auto impl candidate for `impl Trait`s which already | 843 | // We do not generate an auto impl candidate for `impl Trait`s which already |
| 841 | // reference our auto trait. | 844 | // reference our auto trait. |
| ... | @@ -850,7 +853,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | ... | @@ -850,7 +853,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { |
| 850 | // We do not emit auto trait candidates for opaque types in coherence. | 853 | // We do not emit auto trait candidates for opaque types in coherence. |
| 851 | // Doing so can result in weird dependency cycles. | 854 | // Doing so can result in weird dependency cycles. |
| 852 | candidates.ambiguous = true; | 855 | candidates.ambiguous = true; |
| 853 | } else if self.infcx.can_define_opaque_ty(alias.def_id) { | 856 | } else if self.infcx.can_define_opaque_ty(def_id) { |
| 854 | // We do not emit auto trait candidates for opaque types in their defining scope, as | 857 | // We do not emit auto trait candidates for opaque types in their defining scope, as |
| 855 | // we need to know the hidden type first, which we can't reliably know within the defining | 858 | // we need to know the hidden type first, which we can't reliably know within the defining |
| 856 | // scope. | 859 | // scope. |
compiler/rustc_trait_selection/src/traits/select/mod.rs+15-7| ... | @@ -1643,8 +1643,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | ... | @@ -1643,8 +1643,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { |
| 1643 | let mut alias_bound_kind = AliasBoundKind::SelfBounds; | 1643 | let mut alias_bound_kind = AliasBoundKind::SelfBounds; |
| 1644 | 1644 | ||
| 1645 | loop { | 1645 | loop { |
| 1646 | let (kind, alias_ty) = match *self_ty.kind() { | 1646 | let (alias_ty, def_id) = match *self_ty.kind() { |
| 1647 | ty::Alias(kind @ (ty::Projection | ty::Opaque), alias_ty) => (kind, alias_ty), | 1647 | ty::Alias( |
| 1648 | alias_ty @ ty::AliasTy { | ||
| 1649 | kind: ty::Projection { def_id } | ty::Opaque { def_id }, | ||
| 1650 | .. | ||
| 1651 | }, | ||
| 1652 | ) => (alias_ty, def_id), | ||
| 1648 | ty::Infer(ty::TyVar(_)) => { | 1653 | ty::Infer(ty::TyVar(_)) => { |
| 1649 | on_ambiguity(); | 1654 | on_ambiguity(); |
| 1650 | return ControlFlow::Continue(()); | 1655 | return ControlFlow::Continue(()); |
| ... | @@ -1657,9 +1662,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | ... | @@ -1657,9 +1662,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { |
| 1657 | // projections, we will never be able to equate, e.g. `<T as Tr>::A` | 1662 | // projections, we will never be able to equate, e.g. `<T as Tr>::A` |
| 1658 | // with `<<T as Tr>::A as Tr>::A`. | 1663 | // with `<<T as Tr>::A as Tr>::A`. |
| 1659 | let relevant_bounds = if alias_bound_kind == AliasBoundKind::NonSelfBounds { | 1664 | let relevant_bounds = if alias_bound_kind == AliasBoundKind::NonSelfBounds { |
| 1660 | self.tcx().item_non_self_bounds(alias_ty.def_id) | 1665 | self.tcx().item_non_self_bounds(def_id) |
| 1661 | } else { | 1666 | } else { |
| 1662 | self.tcx().item_self_bounds(alias_ty.def_id) | 1667 | self.tcx().item_self_bounds(def_id) |
| 1663 | }; | 1668 | }; |
| 1664 | 1669 | ||
| 1665 | for bound in relevant_bounds.instantiate(self.tcx(), alias_ty.args) { | 1670 | for bound in relevant_bounds.instantiate(self.tcx(), alias_ty.args) { |
| ... | @@ -1667,7 +1672,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | ... | @@ -1667,7 +1672,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { |
| 1667 | idx += 1; | 1672 | idx += 1; |
| 1668 | } | 1673 | } |
| 1669 | 1674 | ||
| 1670 | if kind == ty::Projection { | 1675 | if matches!(alias_ty.kind, ty::Projection { .. }) { |
| 1671 | self_ty = alias_ty.self_ty(); | 1676 | self_ty = alias_ty.self_ty(); |
| 1672 | } else { | 1677 | } else { |
| 1673 | return ControlFlow::Continue(()); | 1678 | return ControlFlow::Continue(()); |
| ... | @@ -2328,7 +2333,10 @@ impl<'tcx> SelectionContext<'_, 'tcx> { | ... | @@ -2328,7 +2333,10 @@ impl<'tcx> SelectionContext<'_, 'tcx> { |
| 2328 | ty::Placeholder(..) | 2333 | ty::Placeholder(..) |
| 2329 | | ty::Dynamic(..) | 2334 | | ty::Dynamic(..) |
| 2330 | | ty::Param(..) | 2335 | | ty::Param(..) |
| 2331 | | ty::Alias(ty::Projection | ty::Inherent | ty::Free, ..) | 2336 | | ty::Alias(ty::AliasTy { |
| 2337 | kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Free { .. }, | ||
| 2338 | .. | ||
| 2339 | }) | ||
| 2332 | | ty::Bound(..) | 2340 | | ty::Bound(..) |
| 2333 | | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { | 2341 | | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { |
| 2334 | bug!("asked to assemble constituent types of unexpected type: {:?}", t); | 2342 | bug!("asked to assemble constituent types of unexpected type: {:?}", t); |
| ... | @@ -2396,7 +2404,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { | ... | @@ -2396,7 +2404,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { |
| 2396 | assumptions: vec![], | 2404 | assumptions: vec![], |
| 2397 | }), | 2405 | }), |
| 2398 | 2406 | ||
| 2399 | ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => { | 2407 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { |
| 2400 | if self.infcx.can_define_opaque_ty(def_id) { | 2408 | if self.infcx.can_define_opaque_ty(def_id) { |
| 2401 | unreachable!() | 2409 | unreachable!() |
| 2402 | } else { | 2410 | } else { |
compiler/rustc_trait_selection/src/traits/wf.rs+9-6| ... | @@ -285,9 +285,8 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>( | ... | @@ -285,9 +285,8 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>( |
| 285 | }; | 285 | }; |
| 286 | 286 | ||
| 287 | let ty_to_impl_span = |ty: Ty<'_>| { | 287 | let ty_to_impl_span = |ty: Ty<'_>| { |
| 288 | if let ty::Alias(ty::Projection, projection_ty) = ty.kind() | 288 | if let ty::Alias(ty::AliasTy { kind: ty::Projection { def_id }, .. }) = ty.kind() |
| 289 | && let Some(&impl_item_id) = | 289 | && let Some(&impl_item_id) = tcx.impl_item_implementor_ids(impl_def_id).get(def_id) |
| 290 | tcx.impl_item_implementor_ids(impl_def_id).get(&projection_ty.def_id) | ||
| 291 | && let Some(impl_item) = | 290 | && let Some(impl_item) = |
| 292 | items.iter().find(|item| item.owner_id.to_def_id() == impl_item_id) | 291 | items.iter().find(|item| item.owner_id.to_def_id() == impl_item_id) |
| 293 | { | 292 | { |
| ... | @@ -798,11 +797,15 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> { | ... | @@ -798,11 +797,15 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> { |
| 798 | // Simple cases that are WF if their type args are WF. | 797 | // Simple cases that are WF if their type args are WF. |
| 799 | } | 798 | } |
| 800 | 799 | ||
| 801 | ty::Alias(ty::Projection | ty::Opaque | ty::Free, data) => { | 800 | ty::Alias(ty::AliasTy { |
| 802 | let obligations = self.nominal_obligations(data.def_id, data.args); | 801 | kind: ty::Projection { def_id } | ty::Opaque { def_id } | ty::Free { def_id }, |
| 802 | args, | ||
| 803 | .. | ||
| 804 | }) => { | ||
| 805 | let obligations = self.nominal_obligations(def_id, args); | ||
| 803 | self.out.extend(obligations); | 806 | self.out.extend(obligations); |
| 804 | } | 807 | } |
| 805 | ty::Alias(ty::Inherent, data) => { | 808 | ty::Alias(data @ ty::AliasTy { kind: ty::Inherent { .. }, .. }) => { |
| 806 | self.add_wf_preds_for_inherent_projection(data.into()); | 809 | self.add_wf_preds_for_inherent_projection(data.into()); |
| 807 | return; // Subtree handled by compute_inherent_projection. | 810 | return; // Subtree handled by compute_inherent_projection. |
| 808 | } | 811 | } |
compiler/rustc_ty_utils/src/opaque_types.rs+25-18| ... | @@ -92,12 +92,12 @@ impl<'tcx> OpaqueTypeCollector<'tcx> { | ... | @@ -92,12 +92,12 @@ impl<'tcx> OpaqueTypeCollector<'tcx> { |
| 92 | 92 | ||
| 93 | #[instrument(level = "debug", skip(self))] | 93 | #[instrument(level = "debug", skip(self))] |
| 94 | fn visit_opaque_ty(&mut self, alias_ty: ty::AliasTy<'tcx>) { | 94 | fn visit_opaque_ty(&mut self, alias_ty: ty::AliasTy<'tcx>) { |
| 95 | if !self.seen.insert(alias_ty.def_id.expect_local()) { | 95 | if !self.seen.insert(alias_ty.kind.def_id().expect_local()) { |
| 96 | return; | 96 | return; |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | // TAITs outside their defining scopes are ignored. | 99 | // TAITs outside their defining scopes are ignored. |
| 100 | match self.tcx.local_opaque_ty_origin(alias_ty.def_id.expect_local()) { | 100 | match self.tcx.local_opaque_ty_origin(alias_ty.kind.def_id().expect_local()) { |
| 101 | rustc_hir::OpaqueTyOrigin::FnReturn { .. } | 101 | rustc_hir::OpaqueTyOrigin::FnReturn { .. } |
| 102 | | rustc_hir::OpaqueTyOrigin::AsyncFn { .. } => {} | 102 | | rustc_hir::OpaqueTyOrigin::AsyncFn { .. } => {} |
| 103 | rustc_hir::OpaqueTyOrigin::TyAlias { in_assoc_ty, .. } => match self.mode { | 103 | rustc_hir::OpaqueTyOrigin::TyAlias { in_assoc_ty, .. } => match self.mode { |
| ... | @@ -122,9 +122,9 @@ impl<'tcx> OpaqueTypeCollector<'tcx> { | ... | @@ -122,9 +122,9 @@ impl<'tcx> OpaqueTypeCollector<'tcx> { |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | trace!(?alias_ty, "adding"); | 124 | trace!(?alias_ty, "adding"); |
| 125 | self.opaques.push(alias_ty.def_id.expect_local()); | 125 | self.opaques.push(alias_ty.kind.def_id().expect_local()); |
| 126 | 126 | ||
| 127 | let parent_count = self.tcx.generics_of(alias_ty.def_id).parent_count; | 127 | let parent_count = self.tcx.generics_of(alias_ty.kind.def_id()).parent_count; |
| 128 | // Only check that the parent generics of the TAIT/RPIT are unique. | 128 | // Only check that the parent generics of the TAIT/RPIT are unique. |
| 129 | // the args owned by the opaque are going to always be duplicate | 129 | // the args owned by the opaque are going to always be duplicate |
| 130 | // lifetime params for RPITs, and empty for TAITs. | 130 | // lifetime params for RPITs, and empty for TAITs. |
| ... | @@ -141,7 +141,7 @@ impl<'tcx> OpaqueTypeCollector<'tcx> { | ... | @@ -141,7 +141,7 @@ impl<'tcx> OpaqueTypeCollector<'tcx> { |
| 141 | // We use identity args here, because we already know that the opaque type uses | 141 | // We use identity args here, because we already know that the opaque type uses |
| 142 | // only generic parameters, and thus instantiating would not give us more information. | 142 | // only generic parameters, and thus instantiating would not give us more information. |
| 143 | for (pred, span) in | 143 | for (pred, span) in |
| 144 | self.tcx.explicit_item_bounds(alias_ty.def_id).iter_identity_copied() | 144 | self.tcx.explicit_item_bounds(alias_ty.kind.def_id()).iter_identity_copied() |
| 145 | { | 145 | { |
| 146 | trace!(?pred); | 146 | trace!(?pred); |
| 147 | self.visit_spanned(span, pred); | 147 | self.visit_spanned(span, pred); |
| ... | @@ -151,14 +151,14 @@ impl<'tcx> OpaqueTypeCollector<'tcx> { | ... | @@ -151,14 +151,14 @@ impl<'tcx> OpaqueTypeCollector<'tcx> { |
| 151 | self.tcx.dcx().emit_err(NotParam { | 151 | self.tcx.dcx().emit_err(NotParam { |
| 152 | arg, | 152 | arg, |
| 153 | span: self.span(), | 153 | span: self.span(), |
| 154 | opaque_span: self.tcx.def_span(alias_ty.def_id), | 154 | opaque_span: self.tcx.def_span(alias_ty.kind.def_id()), |
| 155 | }); | 155 | }); |
| 156 | } | 156 | } |
| 157 | Err(NotUniqueParam::DuplicateParam(arg)) => { | 157 | Err(NotUniqueParam::DuplicateParam(arg)) => { |
| 158 | self.tcx.dcx().emit_err(DuplicateArg { | 158 | self.tcx.dcx().emit_err(DuplicateArg { |
| 159 | arg, | 159 | arg, |
| 160 | span: self.span(), | 160 | span: self.span(), |
| 161 | opaque_span: self.tcx.def_span(alias_ty.def_id), | 161 | opaque_span: self.tcx.def_span(alias_ty.kind.def_id()), |
| 162 | }); | 162 | }); |
| 163 | } | 163 | } |
| 164 | } | 164 | } |
| ... | @@ -203,21 +203,24 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> { | ... | @@ -203,21 +203,24 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> { |
| 203 | fn visit_ty(&mut self, t: Ty<'tcx>) { | 203 | fn visit_ty(&mut self, t: Ty<'tcx>) { |
| 204 | t.super_visit_with(self); | 204 | t.super_visit_with(self); |
| 205 | match *t.kind() { | 205 | match *t.kind() { |
| 206 | ty::Alias(ty::Opaque, alias_ty) if alias_ty.def_id.is_local() => { | 206 | ty::Alias(alias_ty @ ty::AliasTy { kind: ty::Opaque { def_id }, .. }) |
| 207 | if def_id.is_local() => | ||
| 208 | { | ||
| 207 | self.visit_opaque_ty(alias_ty); | 209 | self.visit_opaque_ty(alias_ty); |
| 208 | } | 210 | } |
| 209 | // Skips type aliases, as they are meant to be transparent. | 211 | // Skips type aliases, as they are meant to be transparent. |
| 210 | // FIXME(type_alias_impl_trait): can we require mentioning nested type aliases explicitly? | 212 | // FIXME(type_alias_impl_trait): can we require mentioning nested type aliases explicitly? |
| 211 | ty::Alias(ty::Free, alias_ty) if let Some(def_id) = alias_ty.def_id.as_local() => { | 213 | ty::Alias(alias_ty @ ty::AliasTy { kind: ty::Free { def_id }, .. }) |
| 214 | if let Some(def_id) = def_id.as_local() => | ||
| 215 | { | ||
| 212 | if !self.seen.insert(def_id) { | 216 | if !self.seen.insert(def_id) { |
| 213 | return; | 217 | return; |
| 214 | } | 218 | } |
| 215 | self.tcx | 219 | self.tcx.type_of(def_id).instantiate(self.tcx, alias_ty.args).visit_with(self); |
| 216 | .type_of(alias_ty.def_id) | ||
| 217 | .instantiate(self.tcx, alias_ty.args) | ||
| 218 | .visit_with(self); | ||
| 219 | } | 220 | } |
| 220 | ty::Alias(ty::Projection, alias_ty) => { | 221 | ty::Alias( |
| 222 | alias_ty @ ty::AliasTy { kind: ty::Projection { def_id: alias_def_id }, .. }, | ||
| 223 | ) => { | ||
| 221 | // This avoids having to do normalization of `Self::AssocTy` by only | 224 | // This avoids having to do normalization of `Self::AssocTy` by only |
| 222 | // supporting the case of a method defining opaque types from assoc types | 225 | // supporting the case of a method defining opaque types from assoc types |
| 223 | // in the same impl block. | 226 | // in the same impl block. |
| ... | @@ -229,7 +232,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> { | ... | @@ -229,7 +232,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> { |
| 229 | if alias_ty.trait_ref(self.tcx) == impl_trait_ref { | 232 | if alias_ty.trait_ref(self.tcx) == impl_trait_ref { |
| 230 | for &assoc in self.tcx.associated_items(parent).in_definition_order() { | 233 | for &assoc in self.tcx.associated_items(parent).in_definition_order() { |
| 231 | trace!(?assoc); | 234 | trace!(?assoc); |
| 232 | if assoc.expect_trait_impl() != Ok(alias_ty.def_id) { | 235 | if assoc.expect_trait_impl() != Ok(alias_def_id) { |
| 233 | continue; | 236 | continue; |
| 234 | } | 237 | } |
| 235 | 238 | ||
| ... | @@ -264,7 +267,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> { | ... | @@ -264,7 +267,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> { |
| 264 | } | 267 | } |
| 265 | } | 268 | } |
| 266 | } else if let Some(ty::ImplTraitInTraitData::Trait { fn_def_id, .. }) = | 269 | } else if let Some(ty::ImplTraitInTraitData::Trait { fn_def_id, .. }) = |
| 267 | self.tcx.opt_rpitit_info(alias_ty.def_id) | 270 | self.tcx.opt_rpitit_info(alias_def_id) |
| 268 | && fn_def_id == self.item.into() | 271 | && fn_def_id == self.item.into() |
| 269 | { | 272 | { |
| 270 | // RPITIT in trait definitions get desugared to an associated type. For | 273 | // RPITIT in trait definitions get desugared to an associated type. For |
| ... | @@ -278,8 +281,12 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> { | ... | @@ -278,8 +281,12 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> { |
| 278 | // `Projection(<Self as Trait>::synthetic_assoc_ty, trait_def::opaque)` | 281 | // `Projection(<Self as Trait>::synthetic_assoc_ty, trait_def::opaque)` |
| 279 | // assumption to the `param_env` of the default method. We also separately | 282 | // assumption to the `param_env` of the default method. We also separately |
| 280 | // rely on that assumption here. | 283 | // rely on that assumption here. |
| 281 | let ty = self.tcx.type_of(alias_ty.def_id).instantiate(self.tcx, alias_ty.args); | 284 | let ty = self.tcx.type_of(alias_def_id).instantiate(self.tcx, alias_ty.args); |
| 282 | let ty::Alias(ty::Opaque, alias_ty) = *ty.kind() else { bug!("{ty:?}") }; | 285 | let ty::Alias(alias_ty @ ty::AliasTy { kind: ty::Opaque { .. }, .. }) = |
| 286 | *ty.kind() | ||
| 287 | else { | ||
| 288 | bug!("{ty:?}") | ||
| 289 | }; | ||
| 283 | self.visit_opaque_ty(alias_ty); | 290 | self.visit_opaque_ty(alias_ty); |
| 284 | } | 291 | } |
| 285 | } | 292 | } |
compiler/rustc_ty_utils/src/ty.rs+11-6| ... | @@ -222,13 +222,18 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> { | ... | @@ -222,13 +222,18 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> { |
| 222 | } | 222 | } |
| 223 | 223 | ||
| 224 | fn visit_ty(&mut self, ty: Ty<'tcx>) { | 224 | fn visit_ty(&mut self, ty: Ty<'tcx>) { |
| 225 | if let ty::Alias(ty::Projection, unshifted_alias_ty) = *ty.kind() | 225 | if let ty::Alias( |
| 226 | unshifted_alias_ty @ ty::AliasTy { | ||
| 227 | kind: ty::Projection { def_id: unshifted_alias_ty_def_id }, | ||
| 228 | .. | ||
| 229 | }, | ||
| 230 | ) = *ty.kind() | ||
| 226 | && let Some( | 231 | && let Some( |
| 227 | ty::ImplTraitInTraitData::Trait { fn_def_id, .. } | 232 | ty::ImplTraitInTraitData::Trait { fn_def_id, .. } |
| 228 | | ty::ImplTraitInTraitData::Impl { fn_def_id, .. }, | 233 | | ty::ImplTraitInTraitData::Impl { fn_def_id, .. }, |
| 229 | ) = self.tcx.opt_rpitit_info(unshifted_alias_ty.def_id) | 234 | ) = self.tcx.opt_rpitit_info(unshifted_alias_ty_def_id) |
| 230 | && fn_def_id == self.fn_def_id | 235 | && fn_def_id == self.fn_def_id |
| 231 | && self.seen.insert(unshifted_alias_ty.def_id) | 236 | && self.seen.insert(unshifted_alias_ty_def_id) |
| 232 | { | 237 | { |
| 233 | // We have entered some binders as we've walked into the | 238 | // We have entered some binders as we've walked into the |
| 234 | // bounds of the RPITIT. Shift these binders back out when | 239 | // bounds of the RPITIT. Shift these binders back out when |
| ... | @@ -253,7 +258,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> { | ... | @@ -253,7 +258,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> { |
| 253 | // strategy, then just reinterpret the associated type like an opaque :^) | 258 | // strategy, then just reinterpret the associated type like an opaque :^) |
| 254 | let default_ty = self | 259 | let default_ty = self |
| 255 | .tcx | 260 | .tcx |
| 256 | .type_of(shifted_alias_ty.def_id) | 261 | .type_of(shifted_alias_ty.kind.def_id()) |
| 257 | .instantiate(self.tcx, shifted_alias_ty.args); | 262 | .instantiate(self.tcx, shifted_alias_ty.args); |
| 258 | 263 | ||
| 259 | self.predicates.push( | 264 | self.predicates.push( |
| ... | @@ -273,7 +278,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> { | ... | @@ -273,7 +278,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> { |
| 273 | // easier to just do this. | 278 | // easier to just do this. |
| 274 | for bound in self | 279 | for bound in self |
| 275 | .tcx | 280 | .tcx |
| 276 | .item_bounds(unshifted_alias_ty.def_id) | 281 | .item_bounds(unshifted_alias_ty_def_id) |
| 277 | .iter_instantiated(self.tcx, unshifted_alias_ty.args) | 282 | .iter_instantiated(self.tcx, unshifted_alias_ty.args) |
| 278 | { | 283 | { |
| 279 | bound.visit_with(self); | 284 | bound.visit_with(self); |
| ... | @@ -387,7 +392,7 @@ fn impl_self_is_guaranteed_unsized<'tcx>(tcx: TyCtxt<'tcx>, impl_def_id: DefId) | ... | @@ -387,7 +392,7 @@ fn impl_self_is_guaranteed_unsized<'tcx>(tcx: TyCtxt<'tcx>, impl_def_id: DefId) |
| 387 | | ty::CoroutineWitness(_, _) | 392 | | ty::CoroutineWitness(_, _) |
| 388 | | ty::Never | 393 | | ty::Never |
| 389 | | ty::Tuple(_) | 394 | | ty::Tuple(_) |
| 390 | | ty::Alias(_, _) | 395 | | ty::Alias(_) |
| 391 | | ty::Param(_) | 396 | | ty::Param(_) |
| 392 | | ty::Bound(_, _) | 397 | | ty::Bound(_, _) |
| 393 | | ty::Placeholder(_) | 398 | | ty::Placeholder(_) |
compiler/rustc_type_ir/src/flags.rs+7-7| ... | @@ -290,15 +290,15 @@ impl<I: Interner> FlagComputation<I> { | ... | @@ -290,15 +290,15 @@ impl<I: Interner> FlagComputation<I> { |
| 290 | self.add_args(args.as_slice()); | 290 | self.add_args(args.as_slice()); |
| 291 | } | 291 | } |
| 292 | 292 | ||
| 293 | ty::Alias(kind, data) => { | 293 | ty::Alias(alias) => { |
| 294 | self.add_flags(match kind { | 294 | self.add_flags(match alias.kind { |
| 295 | ty::Projection => TypeFlags::HAS_TY_PROJECTION, | 295 | ty::Projection { .. } => TypeFlags::HAS_TY_PROJECTION, |
| 296 | ty::Free => TypeFlags::HAS_TY_FREE_ALIAS, | 296 | ty::Free { .. } => TypeFlags::HAS_TY_FREE_ALIAS, |
| 297 | ty::Opaque => TypeFlags::HAS_TY_OPAQUE, | 297 | ty::Opaque { .. } => TypeFlags::HAS_TY_OPAQUE, |
| 298 | ty::Inherent => TypeFlags::HAS_TY_INHERENT, | 298 | ty::Inherent { .. } => TypeFlags::HAS_TY_INHERENT, |
| 299 | }); | 299 | }); |
| 300 | 300 | ||
| 301 | self.add_alias_ty(data); | 301 | self.add_alias_ty(alias); |
| 302 | } | 302 | } |
| 303 | 303 | ||
| 304 | ty::Dynamic(obj, r) => { | 304 | ty::Dynamic(obj, r) => { |
compiler/rustc_type_ir/src/inherent.rs+5-7| ... | @@ -52,13 +52,12 @@ pub trait Ty<I: Interner<Ty = Self>>: | ... | @@ -52,13 +52,12 @@ pub trait Ty<I: Interner<Ty = Self>>: |
| 52 | 52 | ||
| 53 | fn new_canonical_bound(interner: I, var: ty::BoundVar) -> Self; | 53 | fn new_canonical_bound(interner: I, var: ty::BoundVar) -> Self; |
| 54 | 54 | ||
| 55 | fn new_alias(interner: I, kind: ty::AliasTyKind, alias_ty: ty::AliasTy<I>) -> Self; | 55 | fn new_alias(interner: I, alias_ty: ty::AliasTy<I>) -> Self; |
| 56 | 56 | ||
| 57 | fn new_projection_from_args(interner: I, def_id: I::DefId, args: I::GenericArgs) -> Self { | 57 | fn new_projection_from_args(interner: I, def_id: I::DefId, args: I::GenericArgs) -> Self { |
| 58 | Self::new_alias( | 58 | Self::new_alias( |
| 59 | interner, | 59 | interner, |
| 60 | ty::AliasTyKind::Projection, | 60 | ty::AliasTy::new_from_args(interner, ty::AliasTyKind::Projection { def_id }, args), |
| 61 | ty::AliasTy::new_from_args(interner, def_id, args), | ||
| 62 | ) | 61 | ) |
| 63 | } | 62 | } |
| 64 | 63 | ||
| ... | @@ -69,8 +68,7 @@ pub trait Ty<I: Interner<Ty = Self>>: | ... | @@ -69,8 +68,7 @@ pub trait Ty<I: Interner<Ty = Self>>: |
| 69 | ) -> Self { | 68 | ) -> Self { |
| 70 | Self::new_alias( | 69 | Self::new_alias( |
| 71 | interner, | 70 | interner, |
| 72 | ty::AliasTyKind::Projection, | 71 | ty::AliasTy::new(interner, ty::AliasTyKind::Projection { def_id }, args), |
| 73 | ty::AliasTy::new(interner, def_id, args), | ||
| 74 | ) | 72 | ) |
| 75 | } | 73 | } |
| 76 | 74 | ||
| ... | @@ -187,7 +185,7 @@ pub trait Ty<I: Interner<Ty = Self>>: | ... | @@ -187,7 +185,7 @@ pub trait Ty<I: Interner<Ty = Self>>: |
| 187 | | ty::CoroutineWitness(_, _) | 185 | | ty::CoroutineWitness(_, _) |
| 188 | | ty::Never | 186 | | ty::Never |
| 189 | | ty::Tuple(_) | 187 | | ty::Tuple(_) |
| 190 | | ty::Alias(_, _) | 188 | | ty::Alias(_) |
| 191 | | ty::Param(_) | 189 | | ty::Param(_) |
| 192 | | ty::Bound(_, _) | 190 | | ty::Bound(_, _) |
| 193 | | ty::Placeholder(_) | 191 | | ty::Placeholder(_) |
| ... | @@ -392,7 +390,7 @@ pub trait Term<I: Interner<Term = Self>>: | ... | @@ -392,7 +390,7 @@ pub trait Term<I: Interner<Term = Self>>: |
| 392 | fn to_alias_term(self) -> Option<ty::AliasTerm<I>> { | 390 | fn to_alias_term(self) -> Option<ty::AliasTerm<I>> { |
| 393 | match self.kind() { | 391 | match self.kind() { |
| 394 | ty::TermKind::Ty(ty) => match ty.kind() { | 392 | ty::TermKind::Ty(ty) => match ty.kind() { |
| 395 | ty::Alias(_kind, alias_ty) => Some(alias_ty.into()), | 393 | ty::Alias(alias_ty) => Some(alias_ty.into()), |
| 396 | _ => None, | 394 | _ => None, |
| 397 | }, | 395 | }, |
| 398 | ty::TermKind::Const(ct) => match ct.kind() { | 396 | ty::TermKind::Const(ct) => match ct.kind() { |
compiler/rustc_type_ir/src/interner.rs+2-1| ... | @@ -196,6 +196,7 @@ pub trait Interner: | ... | @@ -196,6 +196,7 @@ pub trait Interner: |
| 196 | type VariancesOf: Copy + Debug + SliceLike<Item = ty::Variance>; | 196 | type VariancesOf: Copy + Debug + SliceLike<Item = ty::Variance>; |
| 197 | fn variances_of(self, def_id: Self::DefId) -> Self::VariancesOf; | 197 | fn variances_of(self, def_id: Self::DefId) -> Self::VariancesOf; |
| 198 | 198 | ||
| 199 | // FIXME: remove `def_id` param after `AliasTermKind` contains `def_id` within | ||
| 199 | fn opt_alias_variances( | 200 | fn opt_alias_variances( |
| 200 | self, | 201 | self, |
| 201 | kind: impl Into<ty::AliasTermKind>, | 202 | kind: impl Into<ty::AliasTermKind>, |
| ... | @@ -211,7 +212,7 @@ pub trait Interner: | ... | @@ -211,7 +212,7 @@ pub trait Interner: |
| 211 | type AdtDef: AdtDef<Self>; | 212 | type AdtDef: AdtDef<Self>; |
| 212 | fn adt_def(self, adt_def_id: Self::AdtId) -> Self::AdtDef; | 213 | fn adt_def(self, adt_def_id: Self::AdtId) -> Self::AdtDef; |
| 213 | 214 | ||
| 214 | fn alias_ty_kind(self, alias: ty::AliasTy<Self>) -> ty::AliasTyKind; | 215 | fn alias_ty_kind_from_def_id(self, def_id: Self::DefId) -> ty::AliasTyKind<Self>; |
| 215 | 216 | ||
| 216 | fn alias_term_kind(self, alias: ty::AliasTerm<Self>) -> ty::AliasTermKind; | 217 | fn alias_term_kind(self, alias: ty::AliasTerm<Self>) -> ty::AliasTermKind; |
| 217 | 218 |
compiler/rustc_type_ir/src/outlives.rs+3-4| ... | @@ -148,7 +148,7 @@ impl<I: Interner> TypeVisitor<I> for OutlivesCollector<'_, I> { | ... | @@ -148,7 +148,7 @@ impl<I: Interner> TypeVisitor<I> for OutlivesCollector<'_, I> { |
| 148 | // trait-ref. Therefore, if we see any higher-ranked regions, | 148 | // trait-ref. Therefore, if we see any higher-ranked regions, |
| 149 | // we simply fallback to the most restrictive rule, which | 149 | // we simply fallback to the most restrictive rule, which |
| 150 | // requires that `Pi: 'a` for all `i`. | 150 | // requires that `Pi: 'a` for all `i`. |
| 151 | ty::Alias(kind, alias_ty) => { | 151 | ty::Alias(alias_ty) => { |
| 152 | if !alias_ty.has_escaping_bound_vars() { | 152 | if !alias_ty.has_escaping_bound_vars() { |
| 153 | // best case: no escaping regions, so push the | 153 | // best case: no escaping regions, so push the |
| 154 | // projection and skip the subtree (thus generating no | 154 | // projection and skip the subtree (thus generating no |
| ... | @@ -162,7 +162,7 @@ impl<I: Interner> TypeVisitor<I> for OutlivesCollector<'_, I> { | ... | @@ -162,7 +162,7 @@ impl<I: Interner> TypeVisitor<I> for OutlivesCollector<'_, I> { |
| 162 | // OutlivesProjectionComponents. Continue walking | 162 | // OutlivesProjectionComponents. Continue walking |
| 163 | // through and constrain Pi. | 163 | // through and constrain Pi. |
| 164 | let mut subcomponents = smallvec![]; | 164 | let mut subcomponents = smallvec![]; |
| 165 | compute_alias_components_recursive(self.cx, kind, alias_ty, &mut subcomponents); | 165 | compute_alias_components_recursive(self.cx, alias_ty, &mut subcomponents); |
| 166 | self.out.push(Component::EscapingAlias(subcomponents.into_iter().collect())); | 166 | self.out.push(Component::EscapingAlias(subcomponents.into_iter().collect())); |
| 167 | } | 167 | } |
| 168 | } | 168 | } |
| ... | @@ -223,11 +223,10 @@ impl<I: Interner> TypeVisitor<I> for OutlivesCollector<'_, I> { | ... | @@ -223,11 +223,10 @@ impl<I: Interner> TypeVisitor<I> for OutlivesCollector<'_, I> { |
| 223 | /// Use [push_outlives_components] instead. | 223 | /// Use [push_outlives_components] instead. |
| 224 | pub fn compute_alias_components_recursive<I: Interner>( | 224 | pub fn compute_alias_components_recursive<I: Interner>( |
| 225 | cx: I, | 225 | cx: I, |
| 226 | kind: ty::AliasTyKind, | ||
| 227 | alias_ty: ty::AliasTy<I>, | 226 | alias_ty: ty::AliasTy<I>, |
| 228 | out: &mut SmallVec<[Component<I>; 4]>, | 227 | out: &mut SmallVec<[Component<I>; 4]>, |
| 229 | ) { | 228 | ) { |
| 230 | let opt_variances = cx.opt_alias_variances(kind, alias_ty.def_id); | 229 | let opt_variances = cx.opt_alias_variances(alias_ty.kind, alias_ty.kind.def_id()); |
| 231 | 230 | ||
| 232 | let mut visitor = OutlivesCollector { cx, out, visited: Default::default() }; | 231 | let mut visitor = OutlivesCollector { cx, out, visited: Default::default() }; |
| 233 | 232 |
compiler/rustc_type_ir/src/predicate.rs+32-46| ... | @@ -14,7 +14,7 @@ use crate::inherent::*; | ... | @@ -14,7 +14,7 @@ use crate::inherent::*; |
| 14 | use crate::lift::Lift; | 14 | use crate::lift::Lift; |
| 15 | use crate::upcast::{Upcast, UpcastFrom}; | 15 | use crate::upcast::{Upcast, UpcastFrom}; |
| 16 | use crate::visit::TypeVisitableExt as _; | 16 | use crate::visit::TypeVisitableExt as _; |
| 17 | use crate::{self as ty, Interner}; | 17 | use crate::{self as ty, AliasTyKind, Interner}; |
| 18 | 18 | ||
| 19 | /// `A: 'region` | 19 | /// `A: 'region` |
| 20 | #[derive_where(Clone, Hash, PartialEq, Debug; I: Interner, A)] | 20 | #[derive_where(Clone, Hash, PartialEq, Debug; I: Interner, A)] |
| ... | @@ -554,13 +554,13 @@ impl AliasTermKind { | ... | @@ -554,13 +554,13 @@ impl AliasTermKind { |
| 554 | } | 554 | } |
| 555 | } | 555 | } |
| 556 | 556 | ||
| 557 | impl From<ty::AliasTyKind> for AliasTermKind { | 557 | impl<I: Interner> From<ty::AliasTyKind<I>> for AliasTermKind { |
| 558 | fn from(value: ty::AliasTyKind) -> Self { | 558 | fn from(value: ty::AliasTyKind<I>) -> Self { |
| 559 | match value { | 559 | match value { |
| 560 | ty::Projection => AliasTermKind::ProjectionTy, | 560 | ty::Projection { .. } => AliasTermKind::ProjectionTy, |
| 561 | ty::Opaque => AliasTermKind::OpaqueTy, | 561 | ty::Opaque { .. } => AliasTermKind::OpaqueTy, |
| 562 | ty::Free => AliasTermKind::FreeTy, | 562 | ty::Free { .. } => AliasTermKind::FreeTy, |
| 563 | ty::Inherent => AliasTermKind::InherentTy, | 563 | ty::Inherent { .. } => AliasTermKind::InherentTy, |
| 564 | } | 564 | } |
| 565 | } | 565 | } |
| 566 | } | 566 | } |
| ... | @@ -624,19 +624,19 @@ impl<I: Interner> AliasTerm<I> { | ... | @@ -624,19 +624,19 @@ impl<I: Interner> AliasTerm<I> { |
| 624 | } | 624 | } |
| 625 | 625 | ||
| 626 | pub fn expect_ty(self, interner: I) -> ty::AliasTy<I> { | 626 | pub fn expect_ty(self, interner: I) -> ty::AliasTy<I> { |
| 627 | match self.kind(interner) { | 627 | let kind = match self.kind(interner) { |
| 628 | AliasTermKind::ProjectionTy | 628 | AliasTermKind::ProjectionTy => AliasTyKind::Projection { def_id: self.def_id }, |
| 629 | | AliasTermKind::InherentTy | 629 | AliasTermKind::InherentTy => AliasTyKind::Inherent { def_id: self.def_id }, |
| 630 | | AliasTermKind::OpaqueTy | 630 | AliasTermKind::OpaqueTy => AliasTyKind::Opaque { def_id: self.def_id }, |
| 631 | | AliasTermKind::FreeTy => {} | 631 | AliasTermKind::FreeTy => AliasTyKind::Free { def_id: self.def_id }, |
| 632 | AliasTermKind::InherentConst | 632 | AliasTermKind::InherentConst |
| 633 | | AliasTermKind::FreeConst | 633 | | AliasTermKind::FreeConst |
| 634 | | AliasTermKind::UnevaluatedConst | 634 | | AliasTermKind::UnevaluatedConst |
| 635 | | AliasTermKind::ProjectionConst => { | 635 | | AliasTermKind::ProjectionConst => { |
| 636 | panic!("Cannot turn `UnevaluatedConst` into `AliasTy`") | 636 | panic!("Cannot turn `UnevaluatedConst` into `AliasTy`") |
| 637 | } | 637 | } |
| 638 | } | 638 | }; |
| 639 | ty::AliasTy { def_id: self.def_id, args: self.args, _use_alias_ty_new_instead: () } | 639 | ty::AliasTy { kind, args: self.args, _use_alias_ty_new_instead: () } |
| 640 | } | 640 | } |
| 641 | 641 | ||
| 642 | pub fn kind(self, interner: I) -> AliasTermKind { | 642 | pub fn kind(self, interner: I) -> AliasTermKind { |
| ... | @@ -644,40 +644,26 @@ impl<I: Interner> AliasTerm<I> { | ... | @@ -644,40 +644,26 @@ impl<I: Interner> AliasTerm<I> { |
| 644 | } | 644 | } |
| 645 | 645 | ||
| 646 | pub fn to_term(self, interner: I) -> I::Term { | 646 | pub fn to_term(self, interner: I) -> I::Term { |
| 647 | match self.kind(interner) { | 647 | let alias_ty_kind = match self.kind(interner) { |
| 648 | AliasTermKind::ProjectionTy => Ty::new_alias( | ||
| 649 | interner, | ||
| 650 | ty::AliasTyKind::Projection, | ||
| 651 | ty::AliasTy { def_id: self.def_id, args: self.args, _use_alias_ty_new_instead: () }, | ||
| 652 | ) | ||
| 653 | .into(), | ||
| 654 | AliasTermKind::InherentTy => Ty::new_alias( | ||
| 655 | interner, | ||
| 656 | ty::AliasTyKind::Inherent, | ||
| 657 | ty::AliasTy { def_id: self.def_id, args: self.args, _use_alias_ty_new_instead: () }, | ||
| 658 | ) | ||
| 659 | .into(), | ||
| 660 | AliasTermKind::OpaqueTy => Ty::new_alias( | ||
| 661 | interner, | ||
| 662 | ty::AliasTyKind::Opaque, | ||
| 663 | ty::AliasTy { def_id: self.def_id, args: self.args, _use_alias_ty_new_instead: () }, | ||
| 664 | ) | ||
| 665 | .into(), | ||
| 666 | AliasTermKind::FreeTy => Ty::new_alias( | ||
| 667 | interner, | ||
| 668 | ty::AliasTyKind::Free, | ||
| 669 | ty::AliasTy { def_id: self.def_id, args: self.args, _use_alias_ty_new_instead: () }, | ||
| 670 | ) | ||
| 671 | .into(), | ||
| 672 | AliasTermKind::FreeConst | 648 | AliasTermKind::FreeConst |
| 673 | | AliasTermKind::InherentConst | 649 | | AliasTermKind::InherentConst |
| 674 | | AliasTermKind::UnevaluatedConst | 650 | | AliasTermKind::UnevaluatedConst |
| 675 | | AliasTermKind::ProjectionConst => I::Const::new_unevaluated( | 651 | | AliasTermKind::ProjectionConst => { |
| 676 | interner, | 652 | return I::Const::new_unevaluated( |
| 677 | ty::UnevaluatedConst::new(self.def_id.try_into().unwrap(), self.args), | 653 | interner, |
| 678 | ) | 654 | ty::UnevaluatedConst::new(self.def_id.try_into().unwrap(), self.args), |
| 679 | .into(), | 655 | ) |
| 680 | } | 656 | .into(); |
| 657 | } | ||
| 658 | |||
| 659 | AliasTermKind::ProjectionTy => ty::Projection { def_id: self.def_id }, | ||
| 660 | AliasTermKind::InherentTy => ty::Inherent { def_id: self.def_id }, | ||
| 661 | AliasTermKind::OpaqueTy => ty::Opaque { def_id: self.def_id }, | ||
| 662 | AliasTermKind::FreeTy => ty::Free { def_id: self.def_id }, | ||
| 663 | }; | ||
| 664 | |||
| 665 | Ty::new_alias(interner, ty::AliasTy::new_from_args(interner, alias_ty_kind, self.args)) | ||
| 666 | .into() | ||
| 681 | } | 667 | } |
| 682 | } | 668 | } |
| 683 | 669 | ||
| ... | @@ -760,7 +746,7 @@ impl<I: Interner> AliasTerm<I> { | ... | @@ -760,7 +746,7 @@ impl<I: Interner> AliasTerm<I> { |
| 760 | 746 | ||
| 761 | impl<I: Interner> From<ty::AliasTy<I>> for AliasTerm<I> { | 747 | impl<I: Interner> From<ty::AliasTy<I>> for AliasTerm<I> { |
| 762 | fn from(ty: ty::AliasTy<I>) -> Self { | 748 | fn from(ty: ty::AliasTy<I>) -> Self { |
| 763 | AliasTerm { args: ty.args, def_id: ty.def_id, _use_alias_term_new_instead: () } | 749 | AliasTerm { args: ty.args, def_id: ty.kind.def_id(), _use_alias_term_new_instead: () } |
| 764 | } | 750 | } |
| 765 | } | 751 | } |
| 766 | 752 |
compiler/rustc_type_ir/src/relate.rs+10-8| ... | @@ -215,16 +215,19 @@ impl<I: Interner> Relate<I> for ty::AliasTy<I> { | ... | @@ -215,16 +215,19 @@ impl<I: Interner> Relate<I> for ty::AliasTy<I> { |
| 215 | a: ty::AliasTy<I>, | 215 | a: ty::AliasTy<I>, |
| 216 | b: ty::AliasTy<I>, | 216 | b: ty::AliasTy<I>, |
| 217 | ) -> RelateResult<I, ty::AliasTy<I>> { | 217 | ) -> RelateResult<I, ty::AliasTy<I>> { |
| 218 | if a.def_id != b.def_id { | 218 | if a.kind.def_id() != b.kind.def_id() { |
| 219 | Err(TypeError::ProjectionMismatched(ExpectedFound::new(a.def_id, b.def_id))) | 219 | Err(TypeError::ProjectionMismatched(ExpectedFound::new( |
| 220 | a.kind.def_id(), | ||
| 221 | b.kind.def_id(), | ||
| 222 | ))) | ||
| 220 | } else { | 223 | } else { |
| 221 | let cx = relation.cx(); | 224 | let cx = relation.cx(); |
| 222 | let args = if let Some(variances) = cx.opt_alias_variances(a.kind(cx), a.def_id) { | 225 | let args = if let Some(variances) = cx.opt_alias_variances(a.kind, a.kind.def_id()) { |
| 223 | relate_args_with_variances(relation, variances, a.args, b.args)? | 226 | relate_args_with_variances(relation, variances, a.args, b.args)? |
| 224 | } else { | 227 | } else { |
| 225 | relate_args_invariantly(relation, a.args, b.args)? | 228 | relate_args_invariantly(relation, a.args, b.args)? |
| 226 | }; | 229 | }; |
| 227 | Ok(ty::AliasTy::new_from_args(relation.cx(), a.def_id, args)) | 230 | Ok(ty::AliasTy::new_from_args(relation.cx(), a.kind, args)) |
| 228 | } | 231 | } |
| 229 | } | 232 | } |
| 230 | } | 233 | } |
| ... | @@ -499,10 +502,9 @@ pub fn structurally_relate_tys<I: Interner, R: TypeRelation<I>>( | ... | @@ -499,10 +502,9 @@ pub fn structurally_relate_tys<I: Interner, R: TypeRelation<I>>( |
| 499 | } | 502 | } |
| 500 | 503 | ||
| 501 | // Alias tend to mostly already be handled downstream due to normalization. | 504 | // Alias tend to mostly already be handled downstream due to normalization. |
| 502 | (ty::Alias(a_kind, a_data), ty::Alias(b_kind, b_data)) => { | 505 | (ty::Alias(a), ty::Alias(b)) => { |
| 503 | let alias_ty = relation.relate(a_data, b_data)?; | 506 | let alias_ty = relation.relate(a, b)?; |
| 504 | assert_eq!(a_kind, b_kind); | 507 | Ok(Ty::new_alias(cx, alias_ty)) |
| 505 | Ok(Ty::new_alias(cx, a_kind, alias_ty)) | ||
| 506 | } | 508 | } |
| 507 | 509 | ||
| 508 | (ty::Pat(a_ty, a_pat), ty::Pat(b_ty, b_pat)) => { | 510 | (ty::Pat(a_ty, a_pat), ty::Pat(b_ty, b_pat)) => { |
compiler/rustc_type_ir/src/relate/combine.rs+2-1| ... | @@ -128,7 +128,8 @@ where | ... | @@ -128,7 +128,8 @@ where |
| 128 | // All other cases of inference are errors | 128 | // All other cases of inference are errors |
| 129 | (ty::Infer(_), _) | (_, ty::Infer(_)) => Err(TypeError::Sorts(ExpectedFound::new(a, b))), | 129 | (ty::Infer(_), _) | (_, ty::Infer(_)) => Err(TypeError::Sorts(ExpectedFound::new(a, b))), |
| 130 | 130 | ||
| 131 | (ty::Alias(ty::Opaque, _), _) | (_, ty::Alias(ty::Opaque, _)) => { | 131 | (ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }), _) |
| 132 | | (_, ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. })) => { | ||
| 132 | assert!(!infcx.next_trait_solver()); | 133 | assert!(!infcx.next_trait_solver()); |
| 133 | match infcx.typing_mode() { | 134 | match infcx.typing_mode() { |
| 134 | // During coherence, opaque types should be treated as *possibly* | 135 | // During coherence, opaque types should be treated as *possibly* |
compiler/rustc_type_ir/src/ty_kind.rs+65-44| ... | @@ -21,39 +21,69 @@ use crate::{self as ty, BoundVarIndexKind, FloatTy, IntTy, Interner, UintTy}; | ... | @@ -21,39 +21,69 @@ use crate::{self as ty, BoundVarIndexKind, FloatTy, IntTy, Interner, UintTy}; |
| 21 | 21 | ||
| 22 | mod closure; | 22 | mod closure; |
| 23 | 23 | ||
| 24 | #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] | 24 | #[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] |
| 25 | #[derive(GenericTypeVisitable)] | 25 | #[derive(GenericTypeVisitable, Lift_Generic)] |
| 26 | #[cfg_attr( | 26 | #[cfg_attr( |
| 27 | feature = "nightly", | 27 | feature = "nightly", |
| 28 | derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) | 28 | derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) |
| 29 | )] | 29 | )] |
| 30 | pub enum AliasTyKind { | 30 | pub enum AliasTyKind<I: Interner> { |
| 31 | /// A projection `<Type as Trait>::AssocType`. | 31 | /// A projection `<Type as Trait>::AssocType`. |
| 32 | /// | 32 | /// |
| 33 | /// Can get normalized away if monomorphic enough. | 33 | /// Can get normalized away if monomorphic enough. |
| 34 | Projection, | 34 | /// |
| 35 | /// The `def_id` is the `DefId` of the `TraitItem` for the associated type. | ||
| 36 | /// | ||
| 37 | /// Note that the `def_id` is not the `DefId` of the `TraitRef` containing this | ||
| 38 | /// associated type, which is in `interner.associated_item(def_id).container`, | ||
| 39 | /// aka. `interner.parent(def_id)`. | ||
| 40 | Projection { def_id: I::DefId }, | ||
| 41 | |||
| 35 | /// An associated type in an inherent `impl` | 42 | /// An associated type in an inherent `impl` |
| 36 | Inherent, | 43 | /// |
| 44 | /// The `def_id` is the `DefId` of the `ImplItem` for the associated type. | ||
| 45 | Inherent { def_id: I::DefId }, | ||
| 46 | |||
| 37 | /// An opaque type (usually from `impl Trait` in type aliases or function return types) | 47 | /// An opaque type (usually from `impl Trait` in type aliases or function return types) |
| 38 | /// | 48 | /// |
| 39 | /// Can only be normalized away in PostAnalysis mode or its defining scope. | 49 | /// `def_id` is the `DefId` of the `OpaqueType` item. |
| 40 | Opaque, | 50 | /// |
| 51 | /// | ||
| 52 | /// Can only be normalized away in `PostAnalysis` mode or its defining scope. | ||
| 53 | /// | ||
| 54 | /// During codegen, `interner.type_of(def_id)` can be used to get the type of the | ||
| 55 | /// underlying type if the type is an opaque. | ||
| 56 | Opaque { def_id: I::DefId }, | ||
| 57 | |||
| 41 | /// A type alias that actually checks its trait bounds. | 58 | /// A type alias that actually checks its trait bounds. |
| 42 | /// | 59 | /// |
| 43 | /// Currently only used if the type alias references opaque types. | 60 | /// Currently only used if the type alias references opaque types. |
| 44 | /// Can always be normalized away. | 61 | /// Can always be normalized away. |
| 45 | Free, | 62 | Free { def_id: I::DefId }, |
| 46 | } | 63 | } |
| 47 | 64 | ||
| 48 | impl AliasTyKind { | 65 | impl<I: Interner> AliasTyKind<I> { |
| 66 | pub fn new_from_def_id(interner: I, def_id: I::DefId) -> Self { | ||
| 67 | interner.alias_ty_kind_from_def_id(def_id) | ||
| 68 | } | ||
| 69 | |||
| 49 | pub fn descr(self) -> &'static str { | 70 | pub fn descr(self) -> &'static str { |
| 50 | match self { | 71 | match self { |
| 51 | AliasTyKind::Projection => "associated type", | 72 | AliasTyKind::Projection { .. } => "associated type", |
| 52 | AliasTyKind::Inherent => "inherent associated type", | 73 | AliasTyKind::Inherent { .. } => "inherent associated type", |
| 53 | AliasTyKind::Opaque => "opaque type", | 74 | AliasTyKind::Opaque { .. } => "opaque type", |
| 54 | AliasTyKind::Free => "type alias", | 75 | AliasTyKind::Free { .. } => "type alias", |
| 55 | } | 76 | } |
| 56 | } | 77 | } |
| 78 | |||
| 79 | pub fn def_id(self) -> I::DefId { | ||
| 80 | let (AliasTyKind::Projection { def_id } | ||
| 81 | | AliasTyKind::Inherent { def_id } | ||
| 82 | | AliasTyKind::Opaque { def_id } | ||
| 83 | | AliasTyKind::Free { def_id }) = self; | ||
| 84 | |||
| 85 | def_id | ||
| 86 | } | ||
| 57 | } | 87 | } |
| 58 | 88 | ||
| 59 | /// Defines the kinds of types used by the type system. | 89 | /// Defines the kinds of types used by the type system. |
| ... | @@ -222,7 +252,7 @@ pub enum TyKind<I: Interner> { | ... | @@ -222,7 +252,7 @@ pub enum TyKind<I: Interner> { |
| 222 | /// | 252 | /// |
| 223 | /// All of these types are represented as pairs of def-id and args, and can | 253 | /// All of these types are represented as pairs of def-id and args, and can |
| 224 | /// be normalized, so they are grouped conceptually. | 254 | /// be normalized, so they are grouped conceptually. |
| 225 | Alias(AliasTyKind, AliasTy<I>), | 255 | Alias(AliasTy<I>), |
| 226 | 256 | ||
| 227 | /// A type parameter; for example, `T` in `fn f<T>(x: T) {}`. | 257 | /// A type parameter; for example, `T` in `fn f<T>(x: T) {}`. |
| 228 | Param(I::ParamTy), | 258 | Param(I::ParamTy), |
| ... | @@ -327,7 +357,7 @@ impl<I: Interner> TyKind<I> { | ... | @@ -327,7 +357,7 @@ impl<I: Interner> TyKind<I> { |
| 327 | 357 | ||
| 328 | ty::Error(_) | 358 | ty::Error(_) |
| 329 | | ty::Infer(_) | 359 | | ty::Infer(_) |
| 330 | | ty::Alias(_, _) | 360 | | ty::Alias(_) |
| 331 | | ty::Param(_) | 361 | | ty::Param(_) |
| 332 | | ty::Bound(_, _) | 362 | | ty::Bound(_, _) |
| 333 | | ty::Placeholder(_) => false, | 363 | | ty::Placeholder(_) => false, |
| ... | @@ -392,7 +422,7 @@ impl<I: Interner> fmt::Debug for TyKind<I> { | ... | @@ -392,7 +422,7 @@ impl<I: Interner> fmt::Debug for TyKind<I> { |
| 392 | } | 422 | } |
| 393 | write!(f, ")") | 423 | write!(f, ")") |
| 394 | } | 424 | } |
| 395 | Alias(i, a) => f.debug_tuple("Alias").field(i).field(&a).finish(), | 425 | Alias(a) => f.debug_tuple("Alias").field(&a).finish(), |
| 396 | Param(p) => write!(f, "{p:?}"), | 426 | Param(p) => write!(f, "{p:?}"), |
| 397 | Bound(d, b) => crate::debug_bound_var(f, *d, b), | 427 | Bound(d, b) => crate::debug_bound_var(f, *d, b), |
| 398 | Placeholder(p) => write!(f, "{p:?}"), | 428 | Placeholder(p) => write!(f, "{p:?}"), |
| ... | @@ -426,17 +456,9 @@ pub struct AliasTy<I: Interner> { | ... | @@ -426,17 +456,9 @@ pub struct AliasTy<I: Interner> { |
| 426 | /// while for TAIT it is used for the generic parameters of the alias. | 456 | /// while for TAIT it is used for the generic parameters of the alias. |
| 427 | pub args: I::GenericArgs, | 457 | pub args: I::GenericArgs, |
| 428 | 458 | ||
| 429 | /// The `DefId` of the `TraitItem` or `ImplItem` for the associated type `N` depending on whether | 459 | #[type_foldable(identity)] |
| 430 | /// this is a projection or an inherent projection or the `DefId` of the `OpaqueType` item if | 460 | #[type_visitable(ignore)] |
| 431 | /// this is an opaque. | 461 | pub kind: AliasTyKind<I>, |
| 432 | /// | ||
| 433 | /// During codegen, `interner.type_of(def_id)` can be used to get the type of the | ||
| 434 | /// underlying type if the type is an opaque. | ||
| 435 | /// | ||
| 436 | /// Note that if this is an associated type, this is not the `DefId` of the | ||
| 437 | /// `TraitRef` containing this associated type, which is in `interner.associated_item(def_id).container`, | ||
| 438 | /// aka. `interner.parent(def_id)`. | ||
| 439 | pub def_id: I::DefId, | ||
| 440 | 462 | ||
| 441 | /// This field exists to prevent the creation of `AliasTy` without using [`AliasTy::new_from_args`]. | 463 | /// This field exists to prevent the creation of `AliasTy` without using [`AliasTy::new_from_args`]. |
| 442 | #[derive_where(skip(Debug))] | 464 | #[derive_where(skip(Debug))] |
| ... | @@ -446,36 +468,33 @@ pub struct AliasTy<I: Interner> { | ... | @@ -446,36 +468,33 @@ pub struct AliasTy<I: Interner> { |
| 446 | impl<I: Interner> Eq for AliasTy<I> {} | 468 | impl<I: Interner> Eq for AliasTy<I> {} |
| 447 | 469 | ||
| 448 | impl<I: Interner> AliasTy<I> { | 470 | impl<I: Interner> AliasTy<I> { |
| 449 | pub fn new_from_args(interner: I, def_id: I::DefId, args: I::GenericArgs) -> AliasTy<I> { | 471 | pub fn new_from_args(interner: I, kind: AliasTyKind<I>, args: I::GenericArgs) -> AliasTy<I> { |
| 450 | interner.debug_assert_args_compatible(def_id, args); | 472 | interner.debug_assert_args_compatible(kind.def_id(), args); |
| 451 | AliasTy { def_id, args, _use_alias_ty_new_instead: () } | 473 | AliasTy { kind, args, _use_alias_ty_new_instead: () } |
| 452 | } | 474 | } |
| 453 | 475 | ||
| 454 | pub fn new( | 476 | pub fn new( |
| 455 | interner: I, | 477 | interner: I, |
| 456 | def_id: I::DefId, | 478 | kind: AliasTyKind<I>, |
| 457 | args: impl IntoIterator<Item: Into<I::GenericArg>>, | 479 | args: impl IntoIterator<Item: Into<I::GenericArg>>, |
| 458 | ) -> AliasTy<I> { | 480 | ) -> AliasTy<I> { |
| 459 | let args = interner.mk_args_from_iter(args.into_iter().map(Into::into)); | 481 | let args = interner.mk_args_from_iter(args.into_iter().map(Into::into)); |
| 460 | Self::new_from_args(interner, def_id, args) | 482 | Self::new_from_args(interner, kind, args) |
| 461 | } | ||
| 462 | |||
| 463 | pub fn kind(self, interner: I) -> AliasTyKind { | ||
| 464 | interner.alias_ty_kind(self) | ||
| 465 | } | 483 | } |
| 466 | 484 | ||
| 467 | /// Whether this alias type is an opaque. | 485 | /// Whether this alias type is an opaque. |
| 468 | pub fn is_opaque(self, interner: I) -> bool { | 486 | pub fn is_opaque(self) -> bool { |
| 469 | matches!(self.kind(interner), AliasTyKind::Opaque) | 487 | matches!(self.kind, AliasTyKind::Opaque { .. }) |
| 470 | } | 488 | } |
| 471 | 489 | ||
| 472 | pub fn to_ty(self, interner: I) -> I::Ty { | 490 | pub fn to_ty(self, interner: I) -> I::Ty { |
| 473 | Ty::new_alias(interner, self.kind(interner), self) | 491 | Ty::new_alias(interner, self) |
| 474 | } | 492 | } |
| 475 | } | 493 | } |
| 476 | 494 | ||
| 477 | /// The following methods work only with (trait) associated type projections. | 495 | /// The following methods work only with (trait) associated type projections. |
| 478 | impl<I: Interner> AliasTy<I> { | 496 | impl<I: Interner> AliasTy<I> { |
| 497 | #[track_caller] | ||
| 479 | pub fn self_ty(self) -> I::Ty { | 498 | pub fn self_ty(self) -> I::Ty { |
| 480 | self.args.type_at(0) | 499 | self.args.type_at(0) |
| 481 | } | 500 | } |
| ... | @@ -483,14 +502,15 @@ impl<I: Interner> AliasTy<I> { | ... | @@ -483,14 +502,15 @@ impl<I: Interner> AliasTy<I> { |
| 483 | pub fn with_replaced_self_ty(self, interner: I, self_ty: I::Ty) -> Self { | 502 | pub fn with_replaced_self_ty(self, interner: I, self_ty: I::Ty) -> Self { |
| 484 | AliasTy::new( | 503 | AliasTy::new( |
| 485 | interner, | 504 | interner, |
| 486 | self.def_id, | 505 | self.kind, |
| 487 | [self_ty.into()].into_iter().chain(self.args.iter().skip(1)), | 506 | [self_ty.into()].into_iter().chain(self.args.iter().skip(1)), |
| 488 | ) | 507 | ) |
| 489 | } | 508 | } |
| 490 | 509 | ||
| 491 | pub fn trait_def_id(self, interner: I) -> I::DefId { | 510 | pub fn trait_def_id(self, interner: I) -> I::DefId { |
| 492 | assert_eq!(self.kind(interner), AliasTyKind::Projection, "expected a projection"); | 511 | let AliasTyKind::Projection { def_id } = self.kind else { panic!("expected a projection") }; |
| 493 | interner.parent(self.def_id) | 512 | |
| 513 | interner.parent(def_id) | ||
| 494 | } | 514 | } |
| 495 | 515 | ||
| 496 | /// Extracts the underlying trait reference and own args from this projection. | 516 | /// Extracts the underlying trait reference and own args from this projection. |
| ... | @@ -499,8 +519,9 @@ impl<I: Interner> AliasTy<I> { | ... | @@ -499,8 +519,9 @@ impl<I: Interner> AliasTy<I> { |
| 499 | /// then this function would return a `T: StreamingIterator` trait reference and | 519 | /// then this function would return a `T: StreamingIterator` trait reference and |
| 500 | /// `['a]` as the own args. | 520 | /// `['a]` as the own args. |
| 501 | pub fn trait_ref_and_own_args(self, interner: I) -> (ty::TraitRef<I>, I::GenericArgsSlice) { | 521 | pub fn trait_ref_and_own_args(self, interner: I) -> (ty::TraitRef<I>, I::GenericArgsSlice) { |
| 502 | debug_assert_eq!(self.kind(interner), AliasTyKind::Projection); | 522 | let AliasTyKind::Projection { def_id } = self.kind else { panic!("expected a projection") }; |
| 503 | interner.trait_ref_and_own_args_for_alias(self.def_id, self.args) | 523 | |
| 524 | interner.trait_ref_and_own_args_for_alias(def_id, self.args) | ||
| 504 | } | 525 | } |
| 505 | 526 | ||
| 506 | /// Extracts the underlying trait reference from this projection. | 527 | /// Extracts the underlying trait reference from this projection. |
compiler/rustc_type_ir/src/walk.rs+2-2| ... | @@ -106,8 +106,8 @@ fn push_inner<I: Interner>(stack: &mut TypeWalkerStack<I>, parent: I::GenericArg | ... | @@ -106,8 +106,8 @@ fn push_inner<I: Interner>(stack: &mut TypeWalkerStack<I>, parent: I::GenericArg |
| 106 | stack.push(ty.into()); | 106 | stack.push(ty.into()); |
| 107 | stack.push(lt.into()); | 107 | stack.push(lt.into()); |
| 108 | } | 108 | } |
| 109 | ty::Alias(_, data) => { | 109 | ty::Alias(alias) => { |
| 110 | stack.extend(data.args.iter().rev()); | 110 | stack.extend(alias.args.iter().rev()); |
| 111 | } | 111 | } |
| 112 | ty::Dynamic(obj, lt) => { | 112 | ty::Dynamic(obj, lt) => { |
| 113 | stack.push(lt.into()); | 113 | stack.push(lt.into()); |
src/librustdoc/clean/mod.rs+6-6| ... | @@ -1699,7 +1699,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type | ... | @@ -1699,7 +1699,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type |
| 1699 | let self_type = clean_ty(qself, cx); | 1699 | let self_type = clean_ty(qself, cx); |
| 1700 | 1700 | ||
| 1701 | let (trait_, should_fully_qualify) = match ty.kind() { | 1701 | let (trait_, should_fully_qualify) = match ty.kind() { |
| 1702 | ty::Alias(ty::Projection, proj) => { | 1702 | ty::Alias(proj @ ty::AliasTy { kind: ty::Projection { .. }, .. }) => { |
| 1703 | let res = Res::Def(DefKind::Trait, proj.trait_ref(cx.tcx).def_id); | 1703 | let res = Res::Def(DefKind::Trait, proj.trait_ref(cx.tcx).def_id); |
| 1704 | let trait_ = clean_path(&hir::Path { span, res, segments: &[] }, cx); | 1704 | let trait_ = clean_path(&hir::Path { span, res, segments: &[] }, cx); |
| 1705 | register_res(cx, trait_.res); | 1705 | register_res(cx, trait_.res); |
| ... | @@ -1709,7 +1709,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type | ... | @@ -1709,7 +1709,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type |
| 1709 | 1709 | ||
| 1710 | (Some(trait_), should_fully_qualify) | 1710 | (Some(trait_), should_fully_qualify) |
| 1711 | } | 1711 | } |
| 1712 | ty::Alias(ty::Inherent, _) => (None, false), | 1712 | ty::Alias(ty::AliasTy { kind: ty::Inherent { .. }, .. }) => (None, false), |
| 1713 | // Rustdoc handles `ty::Error`s by turning them into `Type::Infer`s. | 1713 | // Rustdoc handles `ty::Error`s by turning them into `Type::Infer`s. |
| 1714 | ty::Error(_) => return Type::Infer, | 1714 | ty::Error(_) => return Type::Infer, |
| 1715 | _ => bug!("clean: expected associated type, found `{ty:?}`"), | 1715 | _ => bug!("clean: expected associated type, found `{ty:?}`"), |
| ... | @@ -2186,7 +2186,7 @@ pub(crate) fn clean_middle_ty<'tcx>( | ... | @@ -2186,7 +2186,7 @@ pub(crate) fn clean_middle_ty<'tcx>( |
| 2186 | Tuple(t.iter().map(|t| clean_middle_ty(bound_ty.rebind(t), cx, None, None)).collect()) | 2186 | Tuple(t.iter().map(|t| clean_middle_ty(bound_ty.rebind(t), cx, None, None)).collect()) |
| 2187 | } | 2187 | } |
| 2188 | 2188 | ||
| 2189 | ty::Alias(ty::Projection, alias_ty @ ty::AliasTy { def_id, args, .. }) => { | 2189 | ty::Alias(alias_ty @ ty::AliasTy { kind: ty::Projection { def_id }, args, .. }) => { |
| 2190 | if cx.tcx.is_impl_trait_in_trait(def_id) { | 2190 | if cx.tcx.is_impl_trait_in_trait(def_id) { |
| 2191 | clean_middle_opaque_bounds(cx, def_id, args) | 2191 | clean_middle_opaque_bounds(cx, def_id, args) |
| 2192 | } else { | 2192 | } else { |
| ... | @@ -2198,7 +2198,7 @@ pub(crate) fn clean_middle_ty<'tcx>( | ... | @@ -2198,7 +2198,7 @@ pub(crate) fn clean_middle_ty<'tcx>( |
| 2198 | } | 2198 | } |
| 2199 | } | 2199 | } |
| 2200 | 2200 | ||
| 2201 | ty::Alias(ty::Inherent, alias_ty @ ty::AliasTy { def_id, .. }) => { | 2201 | ty::Alias(alias_ty @ ty::AliasTy { kind: ty::Inherent { def_id }, .. }) => { |
| 2202 | let alias_ty = bound_ty.rebind(alias_ty); | 2202 | let alias_ty = bound_ty.rebind(alias_ty); |
| 2203 | let self_type = clean_middle_ty(alias_ty.map_bound(|ty| ty.self_ty()), cx, None, None); | 2203 | let self_type = clean_middle_ty(alias_ty.map_bound(|ty| ty.self_ty()), cx, None, None); |
| 2204 | 2204 | ||
| ... | @@ -2221,7 +2221,7 @@ pub(crate) fn clean_middle_ty<'tcx>( | ... | @@ -2221,7 +2221,7 @@ pub(crate) fn clean_middle_ty<'tcx>( |
| 2221 | })) | 2221 | })) |
| 2222 | } | 2222 | } |
| 2223 | 2223 | ||
| 2224 | ty::Alias(ty::Free, ty::AliasTy { def_id, args, .. }) => { | 2224 | ty::Alias(ty::AliasTy { kind: ty::Free { def_id }, args, .. }) => { |
| 2225 | if cx.tcx.features().lazy_type_alias() { | 2225 | if cx.tcx.features().lazy_type_alias() { |
| 2226 | // Free type alias `data` represents the `type X` in `type X = Y`. If we need `Y`, | 2226 | // Free type alias `data` represents the `type X` in `type X = Y`. If we need `Y`, |
| 2227 | // we need to use `type_of`. | 2227 | // we need to use `type_of`. |
| ... | @@ -2249,7 +2249,7 @@ pub(crate) fn clean_middle_ty<'tcx>( | ... | @@ -2249,7 +2249,7 @@ pub(crate) fn clean_middle_ty<'tcx>( |
| 2249 | ty::BoundTyKind::Anon => panic!("unexpected anonymous bound type variable"), | 2249 | ty::BoundTyKind::Anon => panic!("unexpected anonymous bound type variable"), |
| 2250 | }, | 2250 | }, |
| 2251 | 2251 | ||
| 2252 | ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => { | 2252 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { |
| 2253 | // If it's already in the same alias, don't get an infinite loop. | 2253 | // If it's already in the same alias, don't get an infinite loop. |
| 2254 | if cx.current_type_aliases.contains_key(&def_id) { | 2254 | if cx.current_type_aliases.contains_key(&def_id) { |
| 2255 | let path = | 2255 | let path = |
src/tools/clippy/clippy_lints/src/dereference.rs+16-4| ... | @@ -885,12 +885,21 @@ impl TyCoercionStability { | ... | @@ -885,12 +885,21 @@ impl TyCoercionStability { |
| 885 | continue; | 885 | continue; |
| 886 | }, | 886 | }, |
| 887 | ty::Param(_) if for_return => Self::Deref, | 887 | ty::Param(_) if for_return => Self::Deref, |
| 888 | ty::Alias(ty::Free | ty::Inherent, _) => unreachable!("should have been normalized away above"), | 888 | ty::Alias(ty::AliasTy { |
| 889 | ty::Alias(ty::Projection, _) if !for_return && ty.has_non_region_param() => Self::Reborrow, | 889 | kind: ty::Free { .. } | ty::Inherent { .. }, |
| 890 | .. | ||
| 891 | }) => unreachable!("should have been normalized away above"), | ||
| 892 | ty::Alias(ty::AliasTy { | ||
| 893 | kind: ty::Projection { .. }, | ||
| 894 | .. | ||
| 895 | }) if !for_return && ty.has_non_region_param() => Self::Reborrow, | ||
| 890 | ty::Infer(_) | 896 | ty::Infer(_) |
| 891 | | ty::Error(_) | 897 | | ty::Error(_) |
| 892 | | ty::Bound(..) | 898 | | ty::Bound(..) |
| 893 | | ty::Alias(ty::Opaque, ..) | 899 | | ty::Alias(ty::AliasTy { |
| 900 | kind: ty::Opaque { .. }, | ||
| 901 | .. | ||
| 902 | }) | ||
| 894 | | ty::Placeholder(_) | 903 | | ty::Placeholder(_) |
| 895 | | ty::Dynamic(..) | 904 | | ty::Dynamic(..) |
| 896 | | ty::Param(_) => Self::Reborrow, | 905 | | ty::Param(_) => Self::Reborrow, |
| ... | @@ -921,7 +930,10 @@ impl TyCoercionStability { | ... | @@ -921,7 +930,10 @@ impl TyCoercionStability { |
| 921 | | ty::CoroutineClosure(..) | 930 | | ty::CoroutineClosure(..) |
| 922 | | ty::Never | 931 | | ty::Never |
| 923 | | ty::Tuple(_) | 932 | | ty::Tuple(_) |
| 924 | | ty::Alias(ty::Projection, _) | 933 | | ty::Alias(ty::AliasTy { |
| 934 | kind: ty::Projection { .. }, | ||
| 935 | .. | ||
| 936 | }) | ||
| 925 | | ty::UnsafeBinder(_) => Self::Deref, | 937 | | ty::UnsafeBinder(_) => Self::Deref, |
| 926 | }; | 938 | }; |
| 927 | } | 939 | } |
src/tools/clippy/clippy_lints/src/from_over_into.rs+1-1| ... | @@ -78,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto { | ... | @@ -78,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto { |
| 78 | && span_is_local(item.span) | 78 | && span_is_local(item.span) |
| 79 | && let middle_trait_ref = cx.tcx.impl_trait_ref(item.owner_id).instantiate_identity() | 79 | && let middle_trait_ref = cx.tcx.impl_trait_ref(item.owner_id).instantiate_identity() |
| 80 | && cx.tcx.is_diagnostic_item(sym::Into, middle_trait_ref.def_id) | 80 | && cx.tcx.is_diagnostic_item(sym::Into, middle_trait_ref.def_id) |
| 81 | && !matches!(middle_trait_ref.args.type_at(1).kind(), ty::Alias(ty::Opaque, _)) | 81 | && !matches!(middle_trait_ref.args.type_at(1).kind(), ty::Alias(ty::AliasTy { kind: ty::Opaque{..} , .. })) |
| 82 | && self.msrv.meets(cx, msrvs::RE_REBALANCING_COHERENCE) | 82 | && self.msrv.meets(cx, msrvs::RE_REBALANCING_COHERENCE) |
| 83 | { | 83 | { |
| 84 | span_lint_and_then( | 84 | span_lint_and_then( |
src/tools/clippy/clippy_lints/src/future_not_send.rs+7-2| ... | @@ -75,7 +75,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { | ... | @@ -75,7 +75,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { |
| 75 | return; | 75 | return; |
| 76 | } | 76 | } |
| 77 | let ret_ty = return_ty(cx, cx.tcx.local_def_id_to_hir_id(fn_def_id).expect_owner()); | 77 | let ret_ty = return_ty(cx, cx.tcx.local_def_id_to_hir_id(fn_def_id).expect_owner()); |
| 78 | if let ty::Alias(ty::Opaque, AliasTy { def_id, args, .. }) = *ret_ty.kind() | 78 | if let ty::Alias(AliasTy { kind: ty::Opaque{def_id}, args, .. }) = *ret_ty.kind() |
| 79 | && let Some(future_trait) = cx.tcx.lang_items().future_trait() | 79 | && let Some(future_trait) = cx.tcx.lang_items().future_trait() |
| 80 | && let Some(send_trait) = cx.tcx.get_diagnostic_item(sym::Send) | 80 | && let Some(send_trait) = cx.tcx.get_diagnostic_item(sym::Send) |
| 81 | && let preds = cx.tcx.explicit_item_self_bounds(def_id) | 81 | && let preds = cx.tcx.explicit_item_self_bounds(def_id) |
| ... | @@ -148,7 +148,12 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for TyParamAtTopLevelVisitor { | ... | @@ -148,7 +148,12 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for TyParamAtTopLevelVisitor { |
| 148 | fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result { | 148 | fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result { |
| 149 | match ty.kind() { | 149 | match ty.kind() { |
| 150 | ty::Param(_) => ControlFlow::Break(true), | 150 | ty::Param(_) => ControlFlow::Break(true), |
| 151 | ty::Alias(ty::AliasTyKind::Projection, ty) => ty.visit_with(self), | 151 | ty::Alias( |
| 152 | ty @ AliasTy { | ||
| 153 | kind: ty::Projection { .. }, | ||
| 154 | .. | ||
| 155 | }, | ||
| 156 | ) => ty.visit_with(self), | ||
| 152 | _ => ControlFlow::Break(false), | 157 | _ => ControlFlow::Break(false), |
| 153 | } | 158 | } |
| 154 | } | 159 | } |
src/tools/clippy/clippy_lints/src/indexing_slicing.rs+1-1| ... | @@ -280,7 +280,7 @@ fn ty_has_applicable_get_function<'tcx>( | ... | @@ -280,7 +280,7 @@ fn ty_has_applicable_get_function<'tcx>( |
| 280 | && let generic_ty = option_generic_param.expect_ty().peel_refs() | 280 | && let generic_ty = option_generic_param.expect_ty().peel_refs() |
| 281 | // FIXME: ideally this would handle type params and projections properly, for now just assume it's the same type | 281 | // FIXME: ideally this would handle type params and projections properly, for now just assume it's the same type |
| 282 | && (cx.typeck_results().expr_ty(index_expr).peel_refs() == generic_ty.peel_refs() | 282 | && (cx.typeck_results().expr_ty(index_expr).peel_refs() == generic_ty.peel_refs() |
| 283 | || matches!(generic_ty.peel_refs().kind(), ty::Param(_) | ty::Alias(_, _))) | 283 | || matches!(generic_ty.peel_refs().kind(), ty::Param(_) | ty::Alias(_))) |
| 284 | { | 284 | { |
| 285 | true | 285 | true |
| 286 | } else { | 286 | } else { |
src/tools/clippy/clippy_lints/src/len_without_is_empty.rs+2-2| ... | @@ -137,8 +137,8 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, ident: Iden | ... | @@ -137,8 +137,8 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, ident: Iden |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | fn extract_future_output<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<&'tcx PathSegment<'tcx>> { | 139 | fn extract_future_output<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<&'tcx PathSegment<'tcx>> { |
| 140 | if let ty::Alias(_, alias_ty) = ty.kind() | 140 | if let ty::Alias(alias_ty) = ty.kind() |
| 141 | && let Some(Node::OpaqueTy(opaque)) = cx.tcx.hir_get_if_local(alias_ty.def_id) | 141 | && let Some(Node::OpaqueTy(opaque)) = cx.tcx.hir_get_if_local(alias_ty.kind.def_id()) |
| 142 | && let OpaqueTyOrigin::AsyncFn { .. } = opaque.origin | 142 | && let OpaqueTyOrigin::AsyncFn { .. } = opaque.origin |
| 143 | && let [GenericBound::Trait(trait_ref)] = &opaque.bounds | 143 | && let [GenericBound::Trait(trait_ref)] = &opaque.bounds |
| 144 | && let Some(segment) = trait_ref.trait_ref.path.segments.last() | 144 | && let Some(segment) = trait_ref.trait_ref.path.segments.last() |
src/tools/clippy/clippy_lints/src/len_zero.rs+4-1| ... | @@ -336,7 +336,10 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: Msrv) -> bool { | ... | @@ -336,7 +336,10 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: Msrv) -> bool { |
| 336 | .filter_by_name_unhygienic(sym::is_empty) | 336 | .filter_by_name_unhygienic(sym::is_empty) |
| 337 | .any(|item| is_is_empty_and_stable(cx, item, msrv)) | 337 | .any(|item| is_is_empty_and_stable(cx, item, msrv)) |
| 338 | }), | 338 | }), |
| 339 | ty::Alias(ty::Projection, proj) => has_is_empty_impl(cx, proj.def_id, msrv), | 339 | &ty::Alias(ty::AliasTy { |
| 340 | kind: ty::Projection { def_id }, | ||
| 341 | .. | ||
| 342 | }) => has_is_empty_impl(cx, def_id, msrv), | ||
| 340 | ty::Adt(id, _) => { | 343 | ty::Adt(id, _) => { |
| 341 | has_is_empty_impl(cx, id.did(), msrv) | 344 | has_is_empty_impl(cx, id.did(), msrv) |
| 342 | || (cx.tcx.recursion_limit().value_within_limit(depth) | 345 | || (cx.tcx.recursion_limit().value_within_limit(depth) |
src/tools/clippy/clippy_lints/src/methods/needless_collect.rs+1-1| ... | @@ -247,7 +247,7 @@ fn iterates_same_ty<'tcx>(cx: &LateContext<'tcx>, iter_ty: Ty<'tcx>, collect_ty: | ... | @@ -247,7 +247,7 @@ fn iterates_same_ty<'tcx>(cx: &LateContext<'tcx>, iter_ty: Ty<'tcx>, collect_ty: |
| 247 | && let Some(into_iter_item_proj) = make_projection(cx.tcx, into_iter_trait, sym::Item, [collect_ty]) | 247 | && let Some(into_iter_item_proj) = make_projection(cx.tcx, into_iter_trait, sym::Item, [collect_ty]) |
| 248 | && let Ok(into_iter_item_ty) = cx.tcx.try_normalize_erasing_regions( | 248 | && let Ok(into_iter_item_ty) = cx.tcx.try_normalize_erasing_regions( |
| 249 | cx.typing_env(), | 249 | cx.typing_env(), |
| 250 | Ty::new_projection_from_args(cx.tcx, into_iter_item_proj.def_id, into_iter_item_proj.args), | 250 | Ty::new_projection_from_args(cx.tcx, into_iter_item_proj.kind.def_id(), into_iter_item_proj.args), |
| 251 | ) | 251 | ) |
| 252 | { | 252 | { |
| 253 | iter_item_ty == into_iter_item_ty | 253 | iter_item_ty == into_iter_item_ty |
src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs+1-1| ... | @@ -207,7 +207,7 @@ fn fn_inputs_has_impl_trait_ty(cx: &LateContext<'_>, def_id: LocalDefId) -> bool | ... | @@ -207,7 +207,7 @@ fn fn_inputs_has_impl_trait_ty(cx: &LateContext<'_>, def_id: LocalDefId) -> bool |
| 207 | inputs.iter().any(|input| { | 207 | inputs.iter().any(|input| { |
| 208 | matches!( | 208 | matches!( |
| 209 | input.kind(), | 209 | input.kind(), |
| 210 | ty::Alias(ty::AliasTyKind::Free, alias_ty) if cx.tcx.type_of(alias_ty.def_id).skip_binder().is_impl_trait() | 210 | &ty::Alias(ty::AliasTy { kind: ty::Free{def_id} , ..}) if cx.tcx.type_of(def_id).skip_binder().is_impl_trait() |
| 211 | ) | 211 | ) |
| 212 | }) | 212 | }) |
| 213 | } | 213 | } |
src/tools/clippy/clippy_lints/src/needless_borrows_for_generic_args.rs+6-1| ... | @@ -331,7 +331,12 @@ fn is_mixed_projection_predicate<'tcx>( | ... | @@ -331,7 +331,12 @@ fn is_mixed_projection_predicate<'tcx>( |
| 331 | let mut projection_term = projection_predicate.projection_term; | 331 | let mut projection_term = projection_predicate.projection_term; |
| 332 | loop { | 332 | loop { |
| 333 | match *projection_term.self_ty().kind() { | 333 | match *projection_term.self_ty().kind() { |
| 334 | ty::Alias(ty::Projection, inner_projection_ty) => { | 334 | ty::Alias( |
| 335 | inner_projection_ty @ ty::AliasTy { | ||
| 336 | kind: ty::Projection { .. }, | ||
| 337 | .. | ||
| 338 | }, | ||
| 339 | ) => { | ||
| 335 | projection_term = inner_projection_ty.into(); | 340 | projection_term = inner_projection_ty.into(); |
| 336 | }, | 341 | }, |
| 337 | ty::Param(param_ty) => { | 342 | ty::Param(param_ty) => { |
src/tools/clippy/clippy_lints/src/non_copy_const.rs+8-3| ... | @@ -35,8 +35,8 @@ use rustc_lint::{LateContext, LateLintPass, LintContext}; | ... | @@ -35,8 +35,8 @@ use rustc_lint::{LateContext, LateLintPass, LintContext}; |
| 35 | use rustc_middle::mir::{ConstValue, UnevaluatedConst}; | 35 | use rustc_middle::mir::{ConstValue, UnevaluatedConst}; |
| 36 | use rustc_middle::ty::adjustment::{Adjust, Adjustment, DerefAdjustKind}; | 36 | use rustc_middle::ty::adjustment::{Adjust, Adjustment, DerefAdjustKind}; |
| 37 | use rustc_middle::ty::{ | 37 | use rustc_middle::ty::{ |
| 38 | self, AliasTyKind, EarlyBinder, GenericArgs, GenericArgsRef, Instance, Ty, TyCtxt, TypeFolder, TypeSuperFoldable, | 38 | self, EarlyBinder, GenericArgs, GenericArgsRef, Instance, Ty, TyCtxt, TypeFolder, TypeSuperFoldable, TypeckResults, |
| 39 | TypeckResults, TypingEnv, | 39 | TypingEnv, |
| 40 | }; | 40 | }; |
| 41 | use rustc_session::impl_lint_pass; | 41 | use rustc_session::impl_lint_pass; |
| 42 | use rustc_span::DUMMY_SP; | 42 | use rustc_span::DUMMY_SP; |
| ... | @@ -884,7 +884,12 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReplaceAssocFolder<'tcx> { | ... | @@ -884,7 +884,12 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReplaceAssocFolder<'tcx> { |
| 884 | } | 884 | } |
| 885 | 885 | ||
| 886 | fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { | 886 | fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { |
| 887 | if let ty::Alias(AliasTyKind::Projection, ty) = ty.kind() | 887 | if let ty::Alias( |
| 888 | ty @ ty::AliasTy { | ||
| 889 | kind: ty::Projection { .. }, | ||
| 890 | .. | ||
| 891 | }, | ||
| 892 | ) = ty.kind() | ||
| 888 | && ty.trait_def_id(self.tcx) == self.trait_id | 893 | && ty.trait_def_id(self.tcx) == self.trait_id |
| 889 | && ty.self_ty() == self.self_ty | 894 | && ty.self_ty() == self.self_ty |
| 890 | { | 895 | { |
src/tools/clippy/clippy_lints/src/transmute/missing_transmute_annotations.rs+4-1| ... | @@ -107,7 +107,10 @@ pub(super) fn check<'tcx>( | ... | @@ -107,7 +107,10 @@ pub(super) fn check<'tcx>( |
| 107 | fn ty_cannot_be_named(ty: Ty<'_>) -> bool { | 107 | fn ty_cannot_be_named(ty: Ty<'_>) -> bool { |
| 108 | matches!( | 108 | matches!( |
| 109 | ty.kind(), | 109 | ty.kind(), |
| 110 | ty::Alias(ty::AliasTyKind::Opaque | ty::AliasTyKind::Inherent, _) | 110 | ty::Alias(ty::AliasTy { |
| 111 | kind: ty::Opaque { .. } | ty::Inherent { .. }, | ||
| 112 | .. | ||
| 113 | }) | ||
| 111 | ) | 114 | ) |
| 112 | } | 115 | } |
| 113 | 116 |
src/tools/clippy/clippy_lints/src/unconditional_recursion.rs+6-3| ... | @@ -100,9 +100,12 @@ fn get_hir_ty_def_id<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: rustc_hir::Ty<'tcx>) -> Op | ... | @@ -100,9 +100,12 @@ fn get_hir_ty_def_id<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: rustc_hir::Ty<'tcx>) -> Op |
| 100 | let ty = lower_ty(tcx, &hir_ty); | 100 | let ty = lower_ty(tcx, &hir_ty); |
| 101 | 101 | ||
| 102 | match ty.kind() { | 102 | match ty.kind() { |
| 103 | ty::Alias(ty::Projection, proj) => { | 103 | ty::Alias( |
| 104 | Res::<HirId>::Def(DefKind::Trait, proj.trait_ref(tcx).def_id).opt_def_id() | 104 | proj @ ty::AliasTy { |
| 105 | }, | 105 | kind: ty::Projection { .. }, |
| 106 | .. | ||
| 107 | }, | ||
| 108 | ) => Res::<HirId>::Def(DefKind::Trait, proj.trait_ref(tcx).def_id).opt_def_id(), | ||
| 106 | _ => None, | 109 | _ => None, |
| 107 | } | 110 | } |
| 108 | }, | 111 | }, |
src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs+4-1| ... | @@ -82,7 +82,10 @@ fn check_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Span, msrv: Msrv) | ... | @@ -82,7 +82,10 @@ fn check_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Span, msrv: Msrv) |
| 82 | ty::Ref(_, _, hir::Mutability::Mut) if !msrv.meets(cx, msrvs::CONST_MUT_REFS) => { | 82 | ty::Ref(_, _, hir::Mutability::Mut) if !msrv.meets(cx, msrvs::CONST_MUT_REFS) => { |
| 83 | return Err((span, "mutable references in const fn are unstable".into())); | 83 | return Err((span, "mutable references in const fn are unstable".into())); |
| 84 | }, | 84 | }, |
| 85 | ty::Alias(ty::Opaque, ..) => return Err((span, "`impl Trait` in const fn is unstable".into())), | 85 | ty::Alias(ty::AliasTy { |
| 86 | kind: ty::Opaque { .. }, | ||
| 87 | .. | ||
| 88 | }) => return Err((span, "`impl Trait` in const fn is unstable".into())), | ||
| 86 | ty::FnPtr(..) => { | 89 | ty::FnPtr(..) => { |
| 87 | return Err((span, "function pointers in const fn are unstable".into())); | 90 | return Err((span, "function pointers in const fn are unstable".into())); |
| 88 | }, | 91 | }, |
src/tools/clippy/clippy_utils/src/ty/mod.rs+34-9| ... | @@ -101,7 +101,11 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<' | ... | @@ -101,7 +101,11 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<' |
| 101 | return true; | 101 | return true; |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | if let ty::Alias(ty::Opaque, AliasTy { def_id, .. }) = *inner_ty.kind() { | 104 | if let ty::Alias(AliasTy { |
| 105 | kind: ty::Opaque { def_id }, | ||
| 106 | .. | ||
| 107 | }) = *inner_ty.kind() | ||
| 108 | { | ||
| 105 | if !seen.insert(def_id) { | 109 | if !seen.insert(def_id) { |
| 106 | return false; | 110 | return false; |
| 107 | } | 111 | } |
| ... | @@ -324,7 +328,10 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { | ... | @@ -324,7 +328,10 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { |
| 324 | is_must_use_ty(cx, *ty) | 328 | is_must_use_ty(cx, *ty) |
| 325 | }, | 329 | }, |
| 326 | ty::Tuple(args) => args.iter().any(|ty| is_must_use_ty(cx, ty)), | 330 | ty::Tuple(args) => args.iter().any(|ty| is_must_use_ty(cx, ty)), |
| 327 | ty::Alias(ty::Opaque, AliasTy { def_id, .. }) => { | 331 | ty::Alias(AliasTy { |
| 332 | kind: ty::Opaque { def_id }, | ||
| 333 | .. | ||
| 334 | }) => { | ||
| 328 | for (predicate, _) in cx.tcx.explicit_item_self_bounds(*def_id).skip_binder() { | 335 | for (predicate, _) in cx.tcx.explicit_item_self_bounds(*def_id).skip_binder() { |
| 329 | if let ty::ClauseKind::Trait(trait_predicate) = predicate.kind().skip_binder() | 336 | if let ty::ClauseKind::Trait(trait_predicate) = predicate.kind().skip_binder() |
| 330 | && find_attr!(cx.tcx, trait_predicate.trait_ref.def_id, MustUse { .. }) | 337 | && find_attr!(cx.tcx, trait_predicate.trait_ref.def_id, MustUse { .. }) |
| ... | @@ -617,7 +624,11 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<ExprFnSig<'t | ... | @@ -617,7 +624,11 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<ExprFnSig<'t |
| 617 | Some(ExprFnSig::Closure(decl, subs.as_closure().sig())) | 624 | Some(ExprFnSig::Closure(decl, subs.as_closure().sig())) |
| 618 | }, | 625 | }, |
| 619 | ty::FnDef(id, subs) => Some(ExprFnSig::Sig(cx.tcx.fn_sig(id).instantiate(cx.tcx, subs), Some(id))), | 626 | ty::FnDef(id, subs) => Some(ExprFnSig::Sig(cx.tcx.fn_sig(id).instantiate(cx.tcx, subs), Some(id))), |
| 620 | ty::Alias(ty::Opaque, AliasTy { def_id, args, .. }) => sig_from_bounds( | 627 | ty::Alias(AliasTy { |
| 628 | kind: ty::Opaque { def_id }, | ||
| 629 | args, | ||
| 630 | .. | ||
| 631 | }) => sig_from_bounds( | ||
| 621 | cx, | 632 | cx, |
| 622 | ty, | 633 | ty, |
| 623 | cx.tcx.item_self_bounds(def_id).iter_instantiated(cx.tcx, args), | 634 | cx.tcx.item_self_bounds(def_id).iter_instantiated(cx.tcx, args), |
| ... | @@ -641,7 +652,12 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<ExprFnSig<'t | ... | @@ -641,7 +652,12 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<ExprFnSig<'t |
| 641 | _ => None, | 652 | _ => None, |
| 642 | } | 653 | } |
| 643 | }, | 654 | }, |
| 644 | ty::Alias(ty::Projection, proj) => match cx.tcx.try_normalize_erasing_regions(cx.typing_env(), ty) { | 655 | ty::Alias( |
| 656 | proj @ AliasTy { | ||
| 657 | kind: ty::Projection { .. }, | ||
| 658 | .. | ||
| 659 | }, | ||
| 660 | ) => match cx.tcx.try_normalize_erasing_regions(cx.typing_env(), ty) { | ||
| 645 | Ok(normalized_ty) if normalized_ty != ty => ty_sig(cx, normalized_ty), | 661 | Ok(normalized_ty) if normalized_ty != ty => ty_sig(cx, normalized_ty), |
| 646 | _ => sig_for_projection(cx, proj).or_else(|| sig_from_bounds(cx, ty, cx.param_env.caller_bounds(), None)), | 662 | _ => sig_for_projection(cx, proj).or_else(|| sig_from_bounds(cx, ty, cx.param_env.caller_bounds(), None)), |
| 647 | }, | 663 | }, |
| ... | @@ -699,7 +715,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: AliasTy<'tcx>) -> Option | ... | @@ -699,7 +715,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: AliasTy<'tcx>) -> Option |
| 699 | 715 | ||
| 700 | for (pred, _) in cx | 716 | for (pred, _) in cx |
| 701 | .tcx | 717 | .tcx |
| 702 | .explicit_item_bounds(ty.def_id) | 718 | .explicit_item_bounds(ty.kind.def_id()) |
| 703 | .iter_instantiated_copied(cx.tcx, ty.args) | 719 | .iter_instantiated_copied(cx.tcx, ty.args) |
| 704 | { | 720 | { |
| 705 | match pred.kind().skip_binder() { | 721 | match pred.kind().skip_binder() { |
| ... | @@ -1007,7 +1023,11 @@ pub fn make_projection<'tcx>( | ... | @@ -1007,7 +1023,11 @@ pub fn make_projection<'tcx>( |
| 1007 | #[cfg(debug_assertions)] | 1023 | #[cfg(debug_assertions)] |
| 1008 | assert_generic_args_match(tcx, assoc_item.def_id, args); | 1024 | assert_generic_args_match(tcx, assoc_item.def_id, args); |
| 1009 | 1025 | ||
| 1010 | Some(AliasTy::new_from_args(tcx, assoc_item.def_id, args)) | 1026 | Some(AliasTy::new_from_args( |
| 1027 | tcx, | ||
| 1028 | ty::AliasTyKind::new_from_def_id(tcx, assoc_item.def_id), | ||
| 1029 | args, | ||
| 1030 | )) | ||
| 1011 | } | 1031 | } |
| 1012 | helper( | 1032 | helper( |
| 1013 | tcx, | 1033 | tcx, |
| ... | @@ -1046,7 +1066,9 @@ pub fn make_normalized_projection<'tcx>( | ... | @@ -1046,7 +1066,9 @@ pub fn make_normalized_projection<'tcx>( |
| 1046 | ); | 1066 | ); |
| 1047 | return None; | 1067 | return None; |
| 1048 | } | 1068 | } |
| 1049 | match tcx.try_normalize_erasing_regions(typing_env, Ty::new_projection_from_args(tcx, ty.def_id, ty.args)) { | 1069 | match tcx |
| 1070 | .try_normalize_erasing_regions(typing_env, Ty::new_projection_from_args(tcx, ty.kind.def_id(), ty.args)) | ||
| 1071 | { | ||
| 1050 | Ok(ty) => Some(ty), | 1072 | Ok(ty) => Some(ty), |
| 1051 | Err(e) => { | 1073 | Err(e) => { |
| 1052 | debug_assert!(false, "failed to normalize type `{ty}`: {e:#?}"); | 1074 | debug_assert!(false, "failed to normalize type `{ty}`: {e:#?}"); |
| ... | @@ -1148,7 +1170,10 @@ impl<'tcx> InteriorMut<'tcx> { | ... | @@ -1148,7 +1170,10 @@ impl<'tcx> InteriorMut<'tcx> { |
| 1148 | .find_map(|f| self.interior_mut_ty_chain_inner(cx, f.ty(cx.tcx, args), depth)) | 1170 | .find_map(|f| self.interior_mut_ty_chain_inner(cx, f.ty(cx.tcx, args), depth)) |
| 1149 | } | 1171 | } |
| 1150 | }, | 1172 | }, |
| 1151 | ty::Alias(ty::Projection, _) => match cx.tcx.try_normalize_erasing_regions(cx.typing_env(), ty) { | 1173 | ty::Alias(AliasTy { |
| 1174 | kind: ty::Projection { .. }, | ||
| 1175 | .. | ||
| 1176 | }) => match cx.tcx.try_normalize_erasing_regions(cx.typing_env(), ty) { | ||
| 1152 | Ok(normalized_ty) if ty != normalized_ty => self.interior_mut_ty_chain_inner(cx, normalized_ty, depth), | 1177 | Ok(normalized_ty) if ty != normalized_ty => self.interior_mut_ty_chain_inner(cx, normalized_ty, depth), |
| 1153 | _ => None, | 1178 | _ => None, |
| 1154 | }, | 1179 | }, |
| ... | @@ -1196,7 +1221,7 @@ pub fn make_normalized_projection_with_regions<'tcx>( | ... | @@ -1196,7 +1221,7 @@ pub fn make_normalized_projection_with_regions<'tcx>( |
| 1196 | let (infcx, param_env) = tcx.infer_ctxt().build_with_typing_env(typing_env); | 1221 | let (infcx, param_env) = tcx.infer_ctxt().build_with_typing_env(typing_env); |
| 1197 | match infcx | 1222 | match infcx |
| 1198 | .at(&cause, param_env) | 1223 | .at(&cause, param_env) |
| 1199 | .query_normalize(Ty::new_projection_from_args(tcx, ty.def_id, ty.args)) | 1224 | .query_normalize(Ty::new_projection_from_args(tcx, ty.kind.def_id(), ty.args)) |
| 1200 | { | 1225 | { |
| 1201 | Ok(ty) => Some(ty.value), | 1226 | Ok(ty) => Some(ty.value), |
| 1202 | Err(e) => { | 1227 | Err(e) => { |
tests/ui/attributes/dump-preds.stderr+1-1| ... | @@ -33,7 +33,7 @@ error: rustc_dump_item_bounds | ... | @@ -33,7 +33,7 @@ error: rustc_dump_item_bounds |
| 33 | LL | type Assoc<P: Eq>: std::ops::Deref<Target = ()> | 33 | LL | type Assoc<P: Eq>: std::ops::Deref<Target = ()> |
| 34 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 34 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 35 | | | 35 | | |
| 36 | = note: Binder { value: ProjectionPredicate(AliasTerm { args: [Alias(Projection, AliasTy { args: [Self/#0, T/#1, P/#2], def_id: DefId(..), .. })], def_id: DefId(..), .. }, Term::Ty(())), bound_vars: [] } | 36 | = note: Binder { value: ProjectionPredicate(AliasTerm { args: [Alias(AliasTy { args: [Self/#0, T/#1, P/#2], kind: Projection { def_id: DefId(..) }, .. })], def_id: DefId(..), .. }, Term::Ty(())), bound_vars: [] } |
| 37 | = note: Binder { value: TraitPredicate(<<Self as Trait<T>>::Assoc<P> as std::ops::Deref>, polarity:Positive), bound_vars: [] } | 37 | = note: Binder { value: TraitPredicate(<<Self as Trait<T>>::Assoc<P> as std::ops::Deref>, polarity:Positive), bound_vars: [] } |
| 38 | = note: Binder { value: TraitPredicate(<<Self as Trait<T>>::Assoc<P> as std::marker::Sized>, polarity:Positive), bound_vars: [] } | 38 | = note: Binder { value: TraitPredicate(<<Self as Trait<T>>::Assoc<P> as std::marker::Sized>, polarity:Positive), bound_vars: [] } |
| 39 | 39 |