change usages of type_of to bound_type_of
This commit is contained in:
parent
9a7cc6c32f
commit
d822b97a27
136 changed files with 385 additions and 262 deletions
|
@ -93,7 +93,7 @@ fn check_union(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
|||
|
||||
/// Check that the fields of the `union` do not need dropping.
|
||||
fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> bool {
|
||||
let item_type = tcx.type_of(item_def_id);
|
||||
let item_type = tcx.bound_type_of(item_def_id).subst_identity();
|
||||
if let ty::Adt(def, substs) = item_type.kind() {
|
||||
assert!(def.is_union());
|
||||
|
||||
|
@ -170,7 +170,7 @@ fn check_static_inhabited(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
|||
// would be enough to check this for `extern` statics, as statics with an initializer will
|
||||
// have UB during initialization if they are uninhabited, but there also seems to be no good
|
||||
// reason to allow any statics to be uninhabited.
|
||||
let ty = tcx.type_of(def_id);
|
||||
let ty = tcx.bound_type_of(def_id).subst_identity();
|
||||
let span = tcx.def_span(def_id);
|
||||
let layout = match tcx.layout_of(ParamEnv::reveal_all().and(ty)) {
|
||||
Ok(l) => l,
|
||||
|
@ -227,7 +227,7 @@ fn check_opaque(tcx: TyCtxt<'_>, id: hir::ItemId) {
|
|||
if !tcx.features().impl_trait_projections {
|
||||
check_opaque_for_inheriting_lifetimes(tcx, item.owner_id.def_id, span);
|
||||
}
|
||||
if tcx.type_of(item.owner_id.def_id).references_error() {
|
||||
if tcx.bound_type_of(item.owner_id.def_id).subst_identity().references_error() {
|
||||
return;
|
||||
}
|
||||
if check_opaque_for_cycles(tcx, item.owner_id.def_id, substs, span, &origin).is_err() {
|
||||
|
@ -492,7 +492,7 @@ fn is_enum_of_nonnullable_ptr<'tcx>(
|
|||
|
||||
fn check_static_linkage(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
||||
if tcx.codegen_fn_attrs(def_id).import_linkage.is_some() {
|
||||
if match tcx.type_of(def_id).kind() {
|
||||
if match tcx.bound_type_of(def_id).subst_identity().kind() {
|
||||
ty::RawPtr(_) => false,
|
||||
ty::Adt(adt_def, substs) => !is_enum_of_nonnullable_ptr(tcx, *adt_def, *substs),
|
||||
_ => true,
|
||||
|
@ -578,7 +578,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
|
|||
}
|
||||
}
|
||||
DefKind::TyAlias => {
|
||||
let pty_ty = tcx.type_of(id.owner_id);
|
||||
let pty_ty = tcx.bound_type_of(id.owner_id).subst_identity();
|
||||
let generics = tcx.generics_of(id.owner_id);
|
||||
check_type_params_are_used(tcx, &generics, pty_ty);
|
||||
}
|
||||
|
@ -854,7 +854,7 @@ fn check_impl_items_against_trait<'tcx>(
|
|||
}
|
||||
|
||||
pub fn check_simd(tcx: TyCtxt<'_>, sp: Span, def_id: LocalDefId) {
|
||||
let t = tcx.type_of(def_id);
|
||||
let t = tcx.bound_type_of(def_id).subst_identity();
|
||||
if let ty::Adt(def, substs) = t.kind()
|
||||
&& def.is_struct()
|
||||
{
|
||||
|
@ -974,7 +974,7 @@ pub(super) fn check_packed(tcx: TyCtxt<'_>, sp: Span, def: ty::AdtDef<'_>) {
|
|||
&if first {
|
||||
format!(
|
||||
"`{}` contains a field of type `{}`",
|
||||
tcx.type_of(def.did()),
|
||||
tcx.bound_type_of(def.did()).subst_identity(),
|
||||
ident
|
||||
)
|
||||
} else {
|
||||
|
@ -996,7 +996,7 @@ pub(super) fn check_packed_inner(
|
|||
def_id: DefId,
|
||||
stack: &mut Vec<DefId>,
|
||||
) -> Option<Vec<(DefId, Span)>> {
|
||||
if let ty::Adt(def, substs) = tcx.type_of(def_id).kind() {
|
||||
if let ty::Adt(def, substs) = tcx.bound_type_of(def_id).subst_identity().kind() {
|
||||
if def.is_struct() || def.is_union() {
|
||||
if def.repr().align.is_some() {
|
||||
return Some(vec![(def.did(), DUMMY_SP)]);
|
||||
|
|
|
@ -1580,7 +1580,8 @@ fn compare_generic_param_kinds<'tcx>(
|
|||
use GenericParamDefKind::*;
|
||||
if match (¶m_impl.kind, ¶m_trait.kind) {
|
||||
(Const { .. }, Const { .. })
|
||||
if tcx.type_of(param_impl.def_id) != tcx.type_of(param_trait.def_id) =>
|
||||
if tcx.bound_type_of(param_impl.def_id)
|
||||
!= tcx.bound_type_of(param_trait.def_id) =>
|
||||
{
|
||||
true
|
||||
}
|
||||
|
@ -1605,7 +1606,11 @@ fn compare_generic_param_kinds<'tcx>(
|
|||
|
||||
let make_param_message = |prefix: &str, param: &ty::GenericParamDef| match param.kind {
|
||||
Const { .. } => {
|
||||
format!("{} const parameter of type `{}`", prefix, tcx.type_of(param.def_id))
|
||||
format!(
|
||||
"{} const parameter of type `{}`",
|
||||
prefix,
|
||||
tcx.bound_type_of(param.def_id).subst_identity()
|
||||
)
|
||||
}
|
||||
Type { .. } => format!("{} type parameter", prefix),
|
||||
Lifetime { .. } => unreachable!(),
|
||||
|
@ -1654,7 +1659,7 @@ pub(super) fn compare_impl_const_raw(
|
|||
// Create a parameter environment that represents the implementation's
|
||||
// method.
|
||||
// Compute placeholder form of impl and trait const tys.
|
||||
let impl_ty = tcx.type_of(impl_const_item_def.to_def_id());
|
||||
let impl_ty = tcx.bound_type_of(impl_const_item_def.to_def_id()).subst_identity();
|
||||
let trait_ty = tcx.bound_type_of(trait_const_item_def).subst(tcx, trait_to_impl_substs);
|
||||
let mut cause = ObligationCause::new(
|
||||
impl_c_span,
|
||||
|
@ -1927,7 +1932,7 @@ pub(super) fn check_type_bounds<'tcx>(
|
|||
bound_vars.push(bound_var);
|
||||
tcx.mk_const(
|
||||
ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from_usize(bound_vars.len() - 1)),
|
||||
tcx.type_of(param.def_id),
|
||||
tcx.bound_type_of(param.def_id).subst_identity(),
|
||||
)
|
||||
.into()
|
||||
}
|
||||
|
@ -1937,7 +1942,7 @@ pub(super) fn check_type_bounds<'tcx>(
|
|||
let container_id = impl_ty.container_id(tcx);
|
||||
|
||||
let rebased_substs = impl_ty_substs.rebase_onto(tcx, container_id, impl_trait_ref.substs);
|
||||
let impl_ty_value = tcx.type_of(impl_ty.def_id);
|
||||
let impl_ty_value = tcx.bound_type_of(impl_ty.def_id).subst_identity();
|
||||
|
||||
let param_env = tcx.param_env(impl_ty.def_id);
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ use rustc_middle::ty::{self, Predicate, Ty, TyCtxt};
|
|||
/// cannot do `struct S<T>; impl<T:Clone> Drop for S<T> { ... }`).
|
||||
///
|
||||
pub fn check_drop_impl(tcx: TyCtxt<'_>, drop_impl_did: DefId) -> Result<(), ErrorGuaranteed> {
|
||||
let dtor_self_type = tcx.type_of(drop_impl_did);
|
||||
let dtor_self_type = tcx.bound_type_of(drop_impl_did).subst_identity();
|
||||
let dtor_predicates = tcx.predicates_of(drop_impl_did);
|
||||
match dtor_self_type.kind() {
|
||||
ty::Adt(adt_def, self_to_impl_substs) => {
|
||||
|
|
|
@ -450,7 +450,7 @@ fn suggestion_signature(assoc: &ty::AssocItem, tcx: TyCtxt<'_>) -> String {
|
|||
}
|
||||
ty::AssocKind::Type => format!("type {} = Type;", assoc.name),
|
||||
ty::AssocKind::Const => {
|
||||
let ty = tcx.type_of(assoc.def_id);
|
||||
let ty = tcx.bound_type_of(assoc.def_id).subst_identity();
|
||||
let val = ty_kind_suggestion(ty).unwrap_or("value");
|
||||
format!("const {}: {} = {};", assoc.name, ty, val)
|
||||
}
|
||||
|
|
|
@ -874,7 +874,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
|
|||
|
||||
// Const parameters are well formed if their type is structural match.
|
||||
hir::GenericParamKind::Const { ty: hir_ty, default: _ } => {
|
||||
let ty = tcx.type_of(param.def_id);
|
||||
let ty = tcx.bound_type_of(param.def_id).subst_identity();
|
||||
|
||||
if tcx.features().adt_const_params {
|
||||
if let Some(non_structural_match_ty) =
|
||||
|
@ -1011,12 +1011,12 @@ fn check_associated_item(
|
|||
|
||||
let self_ty = match item.container {
|
||||
ty::TraitContainer => tcx.types.self_param,
|
||||
ty::ImplContainer => tcx.type_of(item.container_id(tcx)),
|
||||
ty::ImplContainer => tcx.bound_type_of(item.container_id(tcx)).subst_identity(),
|
||||
};
|
||||
|
||||
match item.kind {
|
||||
ty::AssocKind::Const => {
|
||||
let ty = tcx.type_of(item.def_id);
|
||||
let ty = tcx.bound_type_of(item.def_id).subst_identity();
|
||||
let ty = wfcx.normalize(span, Some(WellFormedLoc::Ty(item_id)), ty);
|
||||
wfcx.register_wf_obligation(span, loc, ty.into());
|
||||
}
|
||||
|
@ -1037,7 +1037,7 @@ fn check_associated_item(
|
|||
check_associated_type_bounds(wfcx, item, span)
|
||||
}
|
||||
if item.defaultness(tcx).has_value() {
|
||||
let ty = tcx.type_of(item.def_id);
|
||||
let ty = tcx.bound_type_of(item.def_id).subst_identity();
|
||||
let ty = wfcx.normalize(span, Some(WellFormedLoc::Ty(item_id)), ty);
|
||||
wfcx.register_wf_obligation(span, loc, ty.into());
|
||||
}
|
||||
|
@ -1070,7 +1070,11 @@ fn check_type_defn<'tcx>(tcx: TyCtxt<'tcx>, item: &hir::Item<'tcx>, all_sized: b
|
|||
let field_id = field.did.expect_local();
|
||||
let hir::FieldDef { ty: hir_ty, .. } =
|
||||
tcx.hir().get_by_def_id(field_id).expect_field();
|
||||
let ty = wfcx.normalize(hir_ty.span, None, tcx.type_of(field.did));
|
||||
let ty = wfcx.normalize(
|
||||
hir_ty.span,
|
||||
None,
|
||||
tcx.bound_type_of(field.did).subst_identity(),
|
||||
);
|
||||
wfcx.register_wf_obligation(
|
||||
hir_ty.span,
|
||||
Some(WellFormedLoc::Ty(field_id)),
|
||||
|
@ -1082,7 +1086,7 @@ fn check_type_defn<'tcx>(tcx: TyCtxt<'tcx>, item: &hir::Item<'tcx>, all_sized: b
|
|||
// intermediate types must be sized.
|
||||
let needs_drop_copy = || {
|
||||
packed && {
|
||||
let ty = tcx.type_of(variant.fields.last().unwrap().did);
|
||||
let ty = tcx.bound_type_of(variant.fields.last().unwrap().did).subst_identity();
|
||||
let ty = tcx.erase_regions(ty);
|
||||
if ty.needs_infer() {
|
||||
tcx.sess
|
||||
|
@ -1104,7 +1108,11 @@ fn check_type_defn<'tcx>(tcx: TyCtxt<'tcx>, item: &hir::Item<'tcx>, all_sized: b
|
|||
let field_id = field.did.expect_local();
|
||||
let hir::FieldDef { ty: hir_ty, .. } =
|
||||
tcx.hir().get_by_def_id(field_id).expect_field();
|
||||
let ty = wfcx.normalize(hir_ty.span, None, tcx.type_of(field.did));
|
||||
let ty = wfcx.normalize(
|
||||
hir_ty.span,
|
||||
None,
|
||||
tcx.bound_type_of(field.did).subst_identity(),
|
||||
);
|
||||
wfcx.register_bound(
|
||||
traits::ObligationCause::new(
|
||||
hir_ty.span,
|
||||
|
@ -1215,7 +1223,7 @@ fn check_item_type(tcx: TyCtxt<'_>, item_id: LocalDefId, ty_span: Span, allow_fo
|
|||
debug!("check_item_type: {:?}", item_id);
|
||||
|
||||
enter_wf_checking_ctxt(tcx, ty_span, item_id, |wfcx| {
|
||||
let ty = tcx.type_of(item_id);
|
||||
let ty = tcx.bound_type_of(item_id).subst_identity();
|
||||
let item_ty = wfcx.normalize(ty_span, Some(WellFormedLoc::Ty(item_id)), ty);
|
||||
|
||||
let mut forbid_unsized = true;
|
||||
|
@ -1300,7 +1308,7 @@ fn check_impl<'tcx>(
|
|||
wfcx.register_obligations(obligations);
|
||||
}
|
||||
None => {
|
||||
let self_ty = tcx.type_of(item.owner_id);
|
||||
let self_ty = tcx.bound_type_of(item.owner_id).subst_identity();
|
||||
let self_ty = wfcx.normalize(
|
||||
item.span,
|
||||
Some(WellFormedLoc::Ty(item.hir_id().expect_owner().def_id)),
|
||||
|
@ -1345,7 +1353,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
|
|||
match param.kind {
|
||||
GenericParamDefKind::Type { .. } => {
|
||||
if is_our_default(param) {
|
||||
let ty = tcx.type_of(param.def_id);
|
||||
let ty = tcx.bound_type_of(param.def_id).subst_identity();
|
||||
// Ignore dependent defaults -- that is, where the default of one type
|
||||
// parameter includes another (e.g., `<T, U = T>`). In those cases, we can't
|
||||
// be sure if it will error or not as user might always specify the other.
|
||||
|
@ -1397,7 +1405,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
|
|||
GenericParamDefKind::Type { .. } => {
|
||||
// If the param has a default, ...
|
||||
if is_our_default(param) {
|
||||
let default_ty = tcx.type_of(param.def_id);
|
||||
let default_ty = tcx.bound_type_of(param.def_id).subst_identity();
|
||||
// ... and it's not a dependent default, ...
|
||||
if !default_ty.needs_subst() {
|
||||
// ... then substitute it with the default.
|
||||
|
@ -1813,7 +1821,7 @@ fn check_variances_for_type_defn<'tcx>(
|
|||
item: &hir::Item<'tcx>,
|
||||
hir_generics: &hir::Generics<'_>,
|
||||
) {
|
||||
let ty = tcx.type_of(item.owner_id);
|
||||
let ty = tcx.bound_type_of(item.owner_id).subst_identity();
|
||||
if tcx.has_error_field(ty) {
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue