diff options
| author | bors <bors@rust-lang.org> | 2023-02-17 04:45:15 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-02-17 04:45:15 +0000 |
| commit | 9556b56dbdbd4238f0051e7230004b0aa488fa14 (patch) | |
| tree | 239e87d32d56548dd262905ead28de9f0500fa8c /compiler/rustc_ty_utils/src | |
| parent | ea218392a4ce119c4dfcd8fb94a7fee77f76f2c5 (diff) | |
| parent | f6c3469aa2f445c0eb4a7598175cba969ef4b948 (diff) | |
| download | rust-9556b56dbdbd4238f0051e7230004b0aa488fa14.tar.gz rust-9556b56dbdbd4238f0051e7230004b0aa488fa14.zip | |
Auto merge of #107753 - kylematsuda:type-of, r=BoxyUwU
Switch to `EarlyBinder` for `type_of` query Part of the work to finish #105779 and implement https://github.com/rust-lang/types-team/issues/78. Several queries `X` have a `bound_X` variant that wraps the output in `EarlyBinder`. This adds `EarlyBinder` to the return type of the `type_of` query and removes `bound_type_of`. r? `@lcnr`
Diffstat (limited to 'compiler/rustc_ty_utils/src')
| -rw-r--r-- | compiler/rustc_ty_utils/src/implied_bounds.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_ty_utils/src/instance.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_ty_utils/src/layout.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_ty_utils/src/needs_drop.rs | 16 | ||||
| -rw-r--r-- | compiler/rustc_ty_utils/src/representability.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_ty_utils/src/ty.rs | 8 |
6 files changed, 24 insertions, 16 deletions
diff --git a/compiler/rustc_ty_utils/src/implied_bounds.rs b/compiler/rustc_ty_utils/src/implied_bounds.rs index 2fe9d135fa5..eb307e66e34 100644 --- a/compiler/rustc_ty_utils/src/implied_bounds.rs +++ b/compiler/rustc_ty_utils/src/implied_bounds.rs @@ -28,7 +28,7 @@ fn assumed_wf_types(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List<Ty<'_>> { tcx.intern_type_list(&types) } // Only the impl self type - None => tcx.intern_type_list(&[tcx.type_of(def_id)]), + None => tcx.intern_type_list(&[tcx.type_of(def_id).subst_identity()]), } } DefKind::AssocConst | DefKind::AssocTy => tcx.assumed_wf_types(tcx.parent(def_id)), diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index 8d46ba320fc..de7230b0cfa 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -53,7 +53,8 @@ fn inner_resolve_instance<'tcx>( ) } else { let ty = tcx.type_of(def.def_id_for_type_of()); - let item_type = tcx.subst_and_normalize_erasing_regions(substs, param_env, ty); + let item_type = + tcx.subst_and_normalize_erasing_regions(substs, param_env, ty.skip_binder()); let def = match *item_type.kind() { ty::FnDef(def_id, ..) if tcx.is_intrinsic(def_id) => { diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index 2df4a5eab21..b860fb6c918 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -453,9 +453,10 @@ fn layout_of_uncached<'tcx>( let param_env = tcx.param_env(def.did()); def.is_struct() && match def.variants().iter().next().and_then(|x| x.fields.last()) { - Some(last_field) => { - tcx.type_of(last_field.did).is_sized(tcx, param_env) - } + Some(last_field) => tcx + .type_of(last_field.did) + .subst_identity() + .is_sized(tcx, param_env), None => false, } }, diff --git a/compiler/rustc_ty_utils/src/needs_drop.rs b/compiler/rustc_ty_utils/src/needs_drop.rs index cd1475391a4..c177d60bb59 100644 --- a/compiler/rustc_ty_utils/src/needs_drop.rs +++ b/compiler/rustc_ty_utils/src/needs_drop.rs @@ -242,7 +242,7 @@ fn drop_tys_helper<'tcx>( Ok(Vec::new()) } else { let field_tys = adt_def.all_fields().map(|field| { - let r = tcx.bound_type_of(field.did).subst(tcx, substs); + let r = tcx.type_of(field.did).subst(tcx, substs); debug!("drop_tys_helper: Subst into {:?} with {:?} gettng {:?}", field, substs, r); r }); @@ -295,9 +295,15 @@ fn adt_drop_tys<'tcx>( let adt_has_dtor = |adt_def: ty::AdtDef<'tcx>| adt_def.destructor(tcx).map(|_| DtorType::Significant); // `tcx.type_of(def_id)` identical to `tcx.make_adt(def, identity_substs)` - drop_tys_helper(tcx, tcx.type_of(def_id), tcx.param_env(def_id), adt_has_dtor, false) - .collect::<Result<Vec<_>, _>>() - .map(|components| tcx.intern_type_list(&components)) + drop_tys_helper( + tcx, + tcx.type_of(def_id).subst_identity(), + tcx.param_env(def_id), + adt_has_dtor, + false, + ) + .collect::<Result<Vec<_>, _>>() + .map(|components| tcx.intern_type_list(&components)) } // If `def_id` refers to a generic ADT, the queries above and below act as if they had been handed // a `tcx.make_ty(def, identity_substs)` and as such it is legal to substitute the generic parameters @@ -308,7 +314,7 @@ fn adt_significant_drop_tys( ) -> Result<&ty::List<Ty<'_>>, AlwaysRequiresDrop> { drop_tys_helper( tcx, - tcx.type_of(def_id), // identical to `tcx.make_adt(def, identity_substs)` + tcx.type_of(def_id).subst_identity(), // identical to `tcx.make_adt(def, identity_substs)` tcx.param_env(def_id), adt_consider_insignificant_dtor(tcx), true, diff --git a/compiler/rustc_ty_utils/src/representability.rs b/compiler/rustc_ty_utils/src/representability.rs index 7f48fb80417..591017eecd2 100644 --- a/compiler/rustc_ty_utils/src/representability.rs +++ b/compiler/rustc_ty_utils/src/representability.rs @@ -31,7 +31,7 @@ fn representability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Representability { } Representability::Representable } - DefKind::Field => representability_ty(tcx, tcx.type_of(def_id)), + DefKind::Field => representability_ty(tcx, tcx.type_of(def_id).subst_identity()), def_kind => bug!("unexpected {def_kind:?}"), } } @@ -91,7 +91,7 @@ fn params_in_repr(tcx: TyCtxt<'_>, def_id: DefId) -> BitSet<u32> { let mut params_in_repr = BitSet::new_empty(generics.params.len()); for variant in adt_def.variants() { for field in variant.fields.iter() { - params_in_repr_ty(tcx, tcx.type_of(field.did), &mut params_in_repr); + params_in_repr_ty(tcx, tcx.type_of(field.did).subst_identity(), &mut params_in_repr); } } params_in_repr diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index fc3d9fb067d..2c50b766d21 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -105,7 +105,7 @@ fn adt_sized_constraint(tcx: TyCtxt<'_>, def_id: DefId) -> &[Ty<'_>] { def.variants() .iter() .flat_map(|v| v.fields.last()) - .flat_map(|f| sized_constraint_for_ty(tcx, def, tcx.type_of(f.did))), + .flat_map(|f| sized_constraint_for_ty(tcx, def, tcx.type_of(f.did).subst_identity())), ); debug!("adt_sized_constraint: {:?} => {:?}", def, result); @@ -301,7 +301,7 @@ fn well_formed_types_in_env(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List<Predica // In an inherent impl, we assume that the receiver type and all its // constituents are well-formed. NodeKind::InherentImpl => { - let self_ty = tcx.type_of(def_id); + let self_ty = tcx.type_of(def_id).subst_identity(); inputs.extend(self_ty.walk()); } @@ -436,7 +436,7 @@ fn unsizing_params_for_adt<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> BitSet<u32 }; let mut unsizing_params = BitSet::new_empty(num_params); - for arg in tcx.bound_type_of(tail_field.did).subst_identity().walk() { + for arg in tcx.type_of(tail_field.did).subst_identity().walk() { if let Some(i) = maybe_unsizing_param_idx(arg) { unsizing_params.insert(i); } @@ -445,7 +445,7 @@ fn unsizing_params_for_adt<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> BitSet<u32 // Ensure none of the other fields mention the parameters used // in unsizing. for field in prefix_fields { - for arg in tcx.bound_type_of(field.did).subst_identity().walk() { + for arg in tcx.type_of(field.did).subst_identity().walk() { if let Some(i) = maybe_unsizing_param_idx(arg) { unsizing_params.remove(i); } |
