mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
ty::Alias review comments
This commit is contained in:
@@ -54,7 +54,6 @@
|
||||
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
|
||||
use rustc_errors::{Applicability, Diag, DiagStyledString, IntoDiagArg, StringPart, pluralize};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::{CRATE_DEF_ID, DefId};
|
||||
use rustc_hir::intravisit::Visitor;
|
||||
use rustc_hir::lang_items::LangItem;
|
||||
@@ -182,11 +181,7 @@ pub fn report_mismatched_consts(
|
||||
|
||||
pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
|
||||
let (def_id, args) = match *ty.kind() {
|
||||
ty::Alias(ty::AliasTy { kind, args, .. })
|
||||
if self.tcx.def_kind(kind.def_id()) == DefKind::OpaqueTy =>
|
||||
{
|
||||
(kind.def_id(), args)
|
||||
}
|
||||
ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => (def_id, args),
|
||||
ty::Alias(ty::AliasTy { kind, args, .. })
|
||||
if self.tcx.is_impl_trait_in_trait(kind.def_id()) =>
|
||||
{
|
||||
|
||||
@@ -196,6 +196,7 @@ fn canonical_param_env_cache_get_or_insert<R>(
|
||||
type VariancesOf: Copy + Debug + SliceLike<Item = ty::Variance>;
|
||||
fn variances_of(self, def_id: Self::DefId) -> Self::VariancesOf;
|
||||
|
||||
// FIXME: remove `def_id` param after `AliasTermKind` contains `def_id` within
|
||||
fn opt_alias_variances(
|
||||
self,
|
||||
kind: impl Into<ty::AliasTermKind>,
|
||||
|
||||
@@ -644,52 +644,26 @@ pub fn kind(self, interner: I) -> AliasTermKind {
|
||||
}
|
||||
|
||||
pub fn to_term(self, interner: I) -> I::Term {
|
||||
match self.kind(interner) {
|
||||
AliasTermKind::ProjectionTy => Ty::new_alias(
|
||||
interner,
|
||||
ty::AliasTy {
|
||||
kind: ty::AliasTyKind::Projection { def_id: self.def_id },
|
||||
args: self.args,
|
||||
_use_alias_ty_new_instead: (),
|
||||
},
|
||||
)
|
||||
.into(),
|
||||
AliasTermKind::InherentTy => Ty::new_alias(
|
||||
interner,
|
||||
ty::AliasTy {
|
||||
kind: ty::AliasTyKind::Inherent { def_id: self.def_id },
|
||||
args: self.args,
|
||||
_use_alias_ty_new_instead: (),
|
||||
},
|
||||
)
|
||||
.into(),
|
||||
AliasTermKind::OpaqueTy => Ty::new_alias(
|
||||
interner,
|
||||
ty::AliasTy {
|
||||
kind: ty::AliasTyKind::Opaque { def_id: self.def_id },
|
||||
args: self.args,
|
||||
_use_alias_ty_new_instead: (),
|
||||
},
|
||||
)
|
||||
.into(),
|
||||
AliasTermKind::FreeTy => Ty::new_alias(
|
||||
interner,
|
||||
ty::AliasTy {
|
||||
kind: ty::AliasTyKind::Free { def_id: self.def_id },
|
||||
args: self.args,
|
||||
_use_alias_ty_new_instead: (),
|
||||
},
|
||||
)
|
||||
.into(),
|
||||
let alias_ty_kind = match self.kind(interner) {
|
||||
AliasTermKind::FreeConst
|
||||
| AliasTermKind::InherentConst
|
||||
| AliasTermKind::UnevaluatedConst
|
||||
| AliasTermKind::ProjectionConst => I::Const::new_unevaluated(
|
||||
interner,
|
||||
ty::UnevaluatedConst::new(self.def_id.try_into().unwrap(), self.args),
|
||||
)
|
||||
.into(),
|
||||
}
|
||||
| AliasTermKind::ProjectionConst => {
|
||||
return I::Const::new_unevaluated(
|
||||
interner,
|
||||
ty::UnevaluatedConst::new(self.def_id.try_into().unwrap(), self.args),
|
||||
)
|
||||
.into();
|
||||
}
|
||||
|
||||
AliasTermKind::ProjectionTy => ty::Projection { def_id: self.def_id },
|
||||
AliasTermKind::InherentTy => ty::Inherent { def_id: self.def_id },
|
||||
AliasTermKind::OpaqueTy => ty::Opaque { def_id: self.def_id },
|
||||
AliasTermKind::FreeTy => ty::Free { def_id: self.def_id },
|
||||
};
|
||||
|
||||
Ty::new_alias(interner, ty::AliasTy::new_from_args(interner, alias_ty_kind, self.args))
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -504,8 +504,6 @@ pub fn structurally_relate_tys<I: Interner, R: TypeRelation<I>>(
|
||||
// Alias tend to mostly already be handled downstream due to normalization.
|
||||
(ty::Alias(a), ty::Alias(b)) => {
|
||||
let alias_ty = relation.relate(a, b)?;
|
||||
assert_eq!(a.kind, b.kind);
|
||||
assert_eq!(a.kind, alias_ty.kind);
|
||||
Ok(Ty::new_alias(cx, alias_ty))
|
||||
}
|
||||
|
||||
|
||||
@@ -31,25 +31,30 @@ pub enum AliasTyKind<I: Interner> {
|
||||
/// A projection `<Type as Trait>::AssocType`.
|
||||
///
|
||||
/// Can get normalized away if monomorphic enough.
|
||||
Projection {
|
||||
/// The `DefId` of the `TraitItem` or `ImplItem` for the associated type `N` depending on whether
|
||||
/// this is a projection or an inherent projection or the `DefId` of the `OpaqueType` item if
|
||||
/// this is an opaque.
|
||||
///
|
||||
/// During codegen, `interner.type_of(def_id)` can be used to get the type of the
|
||||
/// underlying type if the type is an opaque.
|
||||
///
|
||||
/// Note that if this is an associated type, this is not the `DefId` of the
|
||||
/// `TraitRef` containing this associated type, which is in `interner.associated_item(def_id).container`,
|
||||
/// aka. `interner.parent(def_id)`.
|
||||
def_id: I::DefId,
|
||||
},
|
||||
///
|
||||
/// The `def_id` is the `DefId` of the `TraitItem` for the associated type.
|
||||
///
|
||||
/// Note that the `def_id` is not the `DefId` of the `TraitRef` containing this
|
||||
/// associated type, which is in `interner.associated_item(def_id).container`,
|
||||
/// aka. `interner.parent(def_id)`.
|
||||
Projection { def_id: I::DefId },
|
||||
|
||||
/// An associated type in an inherent `impl`
|
||||
///
|
||||
/// The `def_id` is the `DefId` of the `ImplItem` for the associated type.
|
||||
Inherent { def_id: I::DefId },
|
||||
|
||||
/// An opaque type (usually from `impl Trait` in type aliases or function return types)
|
||||
///
|
||||
/// Can only be normalized away in PostAnalysis mode or its defining scope.
|
||||
/// `def_id` is the `DefId` of the `OpaqueType` item.
|
||||
///
|
||||
///
|
||||
/// Can only be normalized away in `PostAnalysis` mode or its defining scope.
|
||||
///
|
||||
/// During codegen, `interner.type_of(def_id)` can be used to get the type of the
|
||||
/// underlying type if the type is an opaque.
|
||||
Opaque { def_id: I::DefId },
|
||||
|
||||
/// A type alias that actually checks its trait bounds.
|
||||
///
|
||||
/// Currently only used if the type alias references opaque types.
|
||||
|
||||
Reference in New Issue
Block a user