1
Fork 0

Auto merge of #132580 - compiler-errors:globs, r=Noratrieb

Remove unnecessary pub enum glob-imports from `rustc_middle::ty`

We used to have an idiom in the compiler where we'd prefix or suffix all the variants of an enum, for example `BoundRegionKind`, with something like `Br`, and then *glob-import* that enum variant directly.

`@noratrieb` brought this up, and I think that it's easier to read when we just use the normal style `EnumName::Variant`.

This PR is a bit large, but it's just naming.

The only somewhat opinionated change that this PR does is rename `BorrowKind::Imm` to `BorrowKind::Immutable` and same for the other variants. I think these enums are used sparingly enough that the extra length is fine.

r? `@noratrieb` or reassign
This commit is contained in:
bors 2024-11-05 08:30:56 +00:00
commit 096277e989
121 changed files with 535 additions and 515 deletions

View file

@ -1189,8 +1189,8 @@ fn compare_self_type<'tcx>(
let self_string = |method: ty::AssocItem| {
let untransformed_self_ty = match method.container {
ty::ImplContainer => impl_trait_ref.self_ty(),
ty::TraitContainer => tcx.types.self_param,
ty::AssocItemContainer::Impl => impl_trait_ref.self_ty(),
ty::AssocItemContainer::Trait => tcx.types.self_param,
};
let self_arg_ty = tcx.fn_sig(method.def_id).instantiate_identity().input(0);
let param_env = ty::ParamEnv::reveal_all();
@ -2224,10 +2224,8 @@ fn param_env_with_gat_bounds<'tcx>(
for impl_ty in impl_tys_to_install {
let trait_ty = match impl_ty.container {
ty::AssocItemContainer::TraitContainer => impl_ty,
ty::AssocItemContainer::ImplContainer => {
tcx.associated_item(impl_ty.trait_item_def_id.unwrap())
}
ty::AssocItemContainer::Trait => impl_ty,
ty::AssocItemContainer::Impl => tcx.associated_item(impl_ty.trait_item_def_id.unwrap()),
};
let mut bound_vars: smallvec::SmallVec<[ty::BoundVariableKind; 8]> =
@ -2246,7 +2244,7 @@ fn param_env_with_gat_bounds<'tcx>(
.into()
}
GenericParamDefKind::Lifetime => {
let kind = ty::BoundRegionKind::BrNamed(param.def_id, param.name);
let kind = ty::BoundRegionKind::Named(param.def_id, param.name);
let bound_var = ty::BoundVariableKind::Region(kind);
bound_vars.push(bound_var);
ty::Region::new_bound(tcx, ty::INNERMOST, ty::BoundRegion {

View file

@ -178,19 +178,19 @@ pub fn check_intrinsic_type(
let name_str = intrinsic_name.as_str();
let bound_vars = tcx.mk_bound_variable_kinds(&[
ty::BoundVariableKind::Region(ty::BrAnon),
ty::BoundVariableKind::Region(ty::BrAnon),
ty::BoundVariableKind::Region(ty::BrEnv),
ty::BoundVariableKind::Region(ty::BoundRegionKind::Anon),
ty::BoundVariableKind::Region(ty::BoundRegionKind::Anon),
ty::BoundVariableKind::Region(ty::BoundRegionKind::ClosureEnv),
]);
let mk_va_list_ty = |mutbl| {
tcx.lang_items().va_list().map(|did| {
let region = ty::Region::new_bound(tcx, ty::INNERMOST, ty::BoundRegion {
var: ty::BoundVar::ZERO,
kind: ty::BrAnon,
kind: ty::BoundRegionKind::Anon,
});
let env_region = ty::Region::new_bound(tcx, ty::INNERMOST, ty::BoundRegion {
var: ty::BoundVar::from_u32(2),
kind: ty::BrEnv,
kind: ty::BoundRegionKind::ClosureEnv,
});
let va_list_ty = tcx.type_of(did).instantiate(tcx, &[region.into()]);
(Ty::new_ref(tcx, env_region, va_list_ty, mutbl), va_list_ty)
@ -509,7 +509,8 @@ pub fn check_intrinsic_type(
);
let discriminant_def_id = assoc_items[0];
let br = ty::BoundRegion { var: ty::BoundVar::ZERO, kind: ty::BrAnon };
let br =
ty::BoundRegion { var: ty::BoundVar::ZERO, kind: ty::BoundRegionKind::Anon };
(
1,
0,
@ -573,10 +574,14 @@ pub fn check_intrinsic_type(
}
sym::raw_eq => {
let br = ty::BoundRegion { var: ty::BoundVar::ZERO, kind: ty::BrAnon };
let br =
ty::BoundRegion { var: ty::BoundVar::ZERO, kind: ty::BoundRegionKind::Anon };
let param_ty_lhs =
Ty::new_imm_ref(tcx, ty::Region::new_bound(tcx, ty::INNERMOST, br), param(0));
let br = ty::BoundRegion { var: ty::BoundVar::from_u32(1), kind: ty::BrAnon };
let br = ty::BoundRegion {
var: ty::BoundVar::from_u32(1),
kind: ty::BoundRegionKind::Anon,
};
let param_ty_rhs =
Ty::new_imm_ref(tcx, ty::Region::new_bound(tcx, ty::INNERMOST, br), param(0));
(1, 0, vec![param_ty_lhs, param_ty_rhs], tcx.types.bool)

View file

@ -1048,8 +1048,10 @@ fn check_associated_item(
.coherent_trait(tcx.parent(item.trait_item_def_id.unwrap_or(item_id.into())))?;
let self_ty = match item.container {
ty::TraitContainer => tcx.types.self_param,
ty::ImplContainer => tcx.type_of(item.container_id(tcx)).instantiate_identity(),
ty::AssocItemContainer::Trait => tcx.types.self_param,
ty::AssocItemContainer::Impl => {
tcx.type_of(item.container_id(tcx)).instantiate_identity()
}
};
match item.kind {
@ -1072,7 +1074,7 @@ fn check_associated_item(
check_method_receiver(wfcx, hir_sig, item, self_ty)
}
ty::AssocKind::Type => {
if let ty::AssocItemContainer::TraitContainer = item.container {
if let ty::AssocItemContainer::Trait = item.container {
check_associated_type_bounds(wfcx, item, span)
}
if item.defaultness(tcx).has_value() {

View file

@ -634,7 +634,7 @@ fn get_new_lifetime_name<'tcx>(
.collect_referenced_late_bound_regions(poly_trait_ref)
.into_iter()
.filter_map(|lt| {
if let ty::BoundRegionKind::BrNamed(_, name) = lt {
if let ty::BoundRegionKind::Named(_, name) = lt {
Some(name.as_str().to_string())
} else {
None

View file

@ -322,7 +322,7 @@ fn late_arg_as_bound_arg<'tcx>(
let name = tcx.item_name(def_id);
match param.kind {
GenericParamKind::Lifetime { .. } => {
ty::BoundVariableKind::Region(ty::BrNamed(def_id, name))
ty::BoundVariableKind::Region(ty::BoundRegionKind::Named(def_id, name))
}
GenericParamKind::Type { .. } => {
ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(def_id, name))
@ -337,7 +337,7 @@ fn late_arg_as_bound_arg<'tcx>(
fn generic_param_def_as_bound_arg(param: &ty::GenericParamDef) -> ty::BoundVariableKind {
match param.kind {
ty::GenericParamDefKind::Lifetime => {
ty::BoundVariableKind::Region(ty::BoundRegionKind::BrNamed(param.def_id, param.name))
ty::BoundVariableKind::Region(ty::BoundRegionKind::Named(param.def_id, param.name))
}
ty::GenericParamDefKind::Type { .. } => {
ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(param.def_id, param.name))

View file

@ -644,7 +644,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
ty::GenericParamDefKind::Lifetime => {
ty::Region::new_bound(tcx, ty::INNERMOST, ty::BoundRegion {
var: ty::BoundVar::from_usize(num_bound_vars),
kind: ty::BoundRegionKind::BrNamed(param.def_id, param.name),
kind: ty::BoundRegionKind::Named(param.def_id, param.name),
})
.into()
}
@ -830,8 +830,8 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GenericParamAndBoundVarCollector<'_, 't
}
ty::ReBound(db, br) if db >= self.depth => {
self.vars.insert(match br.kind {
ty::BrNamed(def_id, name) => (def_id, name),
ty::BrAnon | ty::BrEnv => {
ty::BoundRegionKind::Named(def_id, name) => (def_id, name),
ty::BoundRegionKind::Anon | ty::BoundRegionKind::ClosureEnv => {
let guar = self
.cx
.dcx()

View file

@ -314,7 +314,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
let name = lifetime_name(def_id);
let br = ty::BoundRegion {
var: ty::BoundVar::from_u32(index),
kind: ty::BrNamed(def_id.to_def_id(), name),
kind: ty::BoundRegionKind::Named(def_id.to_def_id(), name),
};
ty::Region::new_bound(tcx, debruijn, br)
}
@ -332,7 +332,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
ty::Region::new_late_param(
tcx,
scope.to_def_id(),
ty::BrNamed(id.to_def_id(), name),
ty::BoundRegionKind::Named(id.to_def_id(), name),
)
// (*) -- not late-bound, won't change
@ -2449,15 +2449,17 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
) {
for br in referenced_regions.difference(&constrained_regions) {
let br_name = match *br {
ty::BrNamed(_, kw::UnderscoreLifetime) | ty::BrAnon | ty::BrEnv => {
"an anonymous lifetime".to_string()
}
ty::BrNamed(_, name) => format!("lifetime `{name}`"),
ty::BoundRegionKind::Named(_, kw::UnderscoreLifetime)
| ty::BoundRegionKind::Anon
| ty::BoundRegionKind::ClosureEnv => "an anonymous lifetime".to_string(),
ty::BoundRegionKind::Named(_, name) => format!("lifetime `{name}`"),
};
let mut err = generate_err(&br_name);
if let ty::BrNamed(_, kw::UnderscoreLifetime) | ty::BrAnon = *br {
if let ty::BoundRegionKind::Named(_, kw::UnderscoreLifetime)
| ty::BoundRegionKind::Anon = *br
{
// The only way for an anonymous lifetime to wind up
// in the return type but **also** be unconstrained is
// if it only appears in "associated types" in the