Skip to content

Commit 096277e

Browse files
committed
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
2 parents 27e38f8 + d458f85 commit 096277e

File tree

121 files changed

+535
-515
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+535
-515
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
817817
) {
818818
match captured_place.info.capture_kind {
819819
ty::UpvarCapture::ByRef(
820-
ty::BorrowKind::MutBorrow | ty::BorrowKind::UniqueImmBorrow,
820+
ty::BorrowKind::Mutable | ty::BorrowKind::UniqueImmutable,
821821
) => {
822822
capture_reason = format!("mutable borrow of `{upvar}`");
823823
}

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
189189
/// Returns `true` if a closure is inferred to be an `FnMut` closure.
190190
fn is_closure_fn_mut(&self, fr: RegionVid) -> bool {
191191
if let Some(ty::ReLateParam(late_param)) = self.to_error_region(fr).as_deref()
192-
&& let ty::BoundRegionKind::BrEnv = late_param.bound_region
192+
&& let ty::BoundRegionKind::ClosureEnv = late_param.bound_region
193193
&& let DefiningTy::Closure(_, args) = self.regioncx.universal_regions().defining_ty
194194
{
195195
return args.as_closure().kind() == ty::ClosureKind::FnMut;

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
301301
}
302302

303303
ty::ReLateParam(late_param) => match late_param.bound_region {
304-
ty::BoundRegionKind::BrNamed(region_def_id, name) => {
304+
ty::BoundRegionKind::Named(region_def_id, name) => {
305305
// Get the span to point to, even if we don't use the name.
306306
let span = tcx.hir().span_if_local(region_def_id).unwrap_or(DUMMY_SP);
307307
debug!(
@@ -332,7 +332,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
332332
}
333333
}
334334

335-
ty::BoundRegionKind::BrEnv => {
335+
ty::BoundRegionKind::ClosureEnv => {
336336
let def_ty = self.regioncx.universal_regions().defining_ty;
337337

338338
let closure_kind = match def_ty {
@@ -369,7 +369,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
369369
})
370370
}
371371

372-
ty::BoundRegionKind::BrAnon => None,
372+
ty::BoundRegionKind::Anon => None,
373373
},
374374

375375
ty::ReBound(..)

compiler/rustc_borrowck/src/type_check/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1332,9 +1332,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
13321332

13331333
let region_ctxt_fn = || {
13341334
let reg_info = match br.kind {
1335-
ty::BoundRegionKind::BrAnon => sym::anon,
1336-
ty::BoundRegionKind::BrNamed(_, name) => name,
1337-
ty::BoundRegionKind::BrEnv => sym::env,
1335+
ty::BoundRegionKind::Anon => sym::anon,
1336+
ty::BoundRegionKind::Named(_, name) => name,
1337+
ty::BoundRegionKind::ClosureEnv => sym::env,
13381338
};
13391339

13401340
RegionCtxt::LateBound(reg_info)

compiler/rustc_borrowck/src/type_check/relate_tys.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,9 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
264264
self.type_checker.constraints.placeholder_region(self.type_checker.infcx, placeholder);
265265

266266
let reg_info = match placeholder.bound.kind {
267-
ty::BoundRegionKind::BrAnon => sym::anon,
268-
ty::BoundRegionKind::BrNamed(_, name) => name,
269-
ty::BoundRegionKind::BrEnv => sym::env,
267+
ty::BoundRegionKind::Anon => sym::anon,
268+
ty::BoundRegionKind::Named(_, name) => name,
269+
ty::BoundRegionKind::ClosureEnv => sym::env,
270270
};
271271

272272
if cfg!(debug_assertions) {

compiler/rustc_borrowck/src/universal_regions.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -696,14 +696,13 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
696696
let closure_sig = args.as_closure().sig();
697697
let inputs_and_output = closure_sig.inputs_and_output();
698698
let bound_vars = tcx.mk_bound_variable_kinds_from_iter(
699-
inputs_and_output
700-
.bound_vars()
701-
.iter()
702-
.chain(iter::once(ty::BoundVariableKind::Region(ty::BrEnv))),
699+
inputs_and_output.bound_vars().iter().chain(iter::once(
700+
ty::BoundVariableKind::Region(ty::BoundRegionKind::ClosureEnv),
701+
)),
703702
);
704703
let br = ty::BoundRegion {
705704
var: ty::BoundVar::from_usize(bound_vars.len() - 1),
706-
kind: ty::BrEnv,
705+
kind: ty::BoundRegionKind::ClosureEnv,
707706
};
708707
let env_region = ty::Region::new_bound(tcx, ty::INNERMOST, br);
709708
let closure_ty = tcx.closure_env_ty(
@@ -751,15 +750,13 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
751750
DefiningTy::CoroutineClosure(def_id, args) => {
752751
assert_eq!(self.mir_def.to_def_id(), def_id);
753752
let closure_sig = args.as_coroutine_closure().coroutine_closure_sig();
754-
let bound_vars = tcx.mk_bound_variable_kinds_from_iter(
755-
closure_sig
756-
.bound_vars()
757-
.iter()
758-
.chain(iter::once(ty::BoundVariableKind::Region(ty::BrEnv))),
759-
);
753+
let bound_vars =
754+
tcx.mk_bound_variable_kinds_from_iter(closure_sig.bound_vars().iter().chain(
755+
iter::once(ty::BoundVariableKind::Region(ty::BoundRegionKind::ClosureEnv)),
756+
));
760757
let br = ty::BoundRegion {
761758
var: ty::BoundVar::from_usize(bound_vars.len() - 1),
762-
kind: ty::BrEnv,
759+
kind: ty::BoundRegionKind::ClosureEnv,
763760
};
764761
let env_region = ty::Region::new_bound(tcx, ty::INNERMOST, br);
765762
let closure_kind = args.as_coroutine_closure().kind();

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ pub fn check_tied_features(
710710
/// applied to the method prototype.
711711
fn should_inherit_track_caller(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
712712
if let Some(impl_item) = tcx.opt_associated_item(def_id)
713-
&& let ty::AssocItemContainer::ImplContainer = impl_item.container
713+
&& let ty::AssocItemContainer::Impl = impl_item.container
714714
&& let Some(trait_item) = impl_item.trait_item_def_id
715715
{
716716
return tcx.codegen_fn_attrs(trait_item).flags.intersects(CodegenFnAttrFlags::TRACK_CALLER);

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1189,8 +1189,8 @@ fn compare_self_type<'tcx>(
11891189

11901190
let self_string = |method: ty::AssocItem| {
11911191
let untransformed_self_ty = match method.container {
1192-
ty::ImplContainer => impl_trait_ref.self_ty(),
1193-
ty::TraitContainer => tcx.types.self_param,
1192+
ty::AssocItemContainer::Impl => impl_trait_ref.self_ty(),
1193+
ty::AssocItemContainer::Trait => tcx.types.self_param,
11941194
};
11951195
let self_arg_ty = tcx.fn_sig(method.def_id).instantiate_identity().input(0);
11961196
let param_env = ty::ParamEnv::reveal_all();
@@ -2224,10 +2224,8 @@ fn param_env_with_gat_bounds<'tcx>(
22242224

22252225
for impl_ty in impl_tys_to_install {
22262226
let trait_ty = match impl_ty.container {
2227-
ty::AssocItemContainer::TraitContainer => impl_ty,
2228-
ty::AssocItemContainer::ImplContainer => {
2229-
tcx.associated_item(impl_ty.trait_item_def_id.unwrap())
2230-
}
2227+
ty::AssocItemContainer::Trait => impl_ty,
2228+
ty::AssocItemContainer::Impl => tcx.associated_item(impl_ty.trait_item_def_id.unwrap()),
22312229
};
22322230

22332231
let mut bound_vars: smallvec::SmallVec<[ty::BoundVariableKind; 8]> =
@@ -2246,7 +2244,7 @@ fn param_env_with_gat_bounds<'tcx>(
22462244
.into()
22472245
}
22482246
GenericParamDefKind::Lifetime => {
2249-
let kind = ty::BoundRegionKind::BrNamed(param.def_id, param.name);
2247+
let kind = ty::BoundRegionKind::Named(param.def_id, param.name);
22502248
let bound_var = ty::BoundVariableKind::Region(kind);
22512249
bound_vars.push(bound_var);
22522250
ty::Region::new_bound(tcx, ty::INNERMOST, ty::BoundRegion {

compiler/rustc_hir_analysis/src/check/intrinsic.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,19 @@ pub fn check_intrinsic_type(
178178
let name_str = intrinsic_name.as_str();
179179

180180
let bound_vars = tcx.mk_bound_variable_kinds(&[
181-
ty::BoundVariableKind::Region(ty::BrAnon),
182-
ty::BoundVariableKind::Region(ty::BrAnon),
183-
ty::BoundVariableKind::Region(ty::BrEnv),
181+
ty::BoundVariableKind::Region(ty::BoundRegionKind::Anon),
182+
ty::BoundVariableKind::Region(ty::BoundRegionKind::Anon),
183+
ty::BoundVariableKind::Region(ty::BoundRegionKind::ClosureEnv),
184184
]);
185185
let mk_va_list_ty = |mutbl| {
186186
tcx.lang_items().va_list().map(|did| {
187187
let region = ty::Region::new_bound(tcx, ty::INNERMOST, ty::BoundRegion {
188188
var: ty::BoundVar::ZERO,
189-
kind: ty::BrAnon,
189+
kind: ty::BoundRegionKind::Anon,
190190
});
191191
let env_region = ty::Region::new_bound(tcx, ty::INNERMOST, ty::BoundRegion {
192192
var: ty::BoundVar::from_u32(2),
193-
kind: ty::BrEnv,
193+
kind: ty::BoundRegionKind::ClosureEnv,
194194
});
195195
let va_list_ty = tcx.type_of(did).instantiate(tcx, &[region.into()]);
196196
(Ty::new_ref(tcx, env_region, va_list_ty, mutbl), va_list_ty)
@@ -509,7 +509,8 @@ pub fn check_intrinsic_type(
509509
);
510510
let discriminant_def_id = assoc_items[0];
511511

512-
let br = ty::BoundRegion { var: ty::BoundVar::ZERO, kind: ty::BrAnon };
512+
let br =
513+
ty::BoundRegion { var: ty::BoundVar::ZERO, kind: ty::BoundRegionKind::Anon };
513514
(
514515
1,
515516
0,
@@ -573,10 +574,14 @@ pub fn check_intrinsic_type(
573574
}
574575

575576
sym::raw_eq => {
576-
let br = ty::BoundRegion { var: ty::BoundVar::ZERO, kind: ty::BrAnon };
577+
let br =
578+
ty::BoundRegion { var: ty::BoundVar::ZERO, kind: ty::BoundRegionKind::Anon };
577579
let param_ty_lhs =
578580
Ty::new_imm_ref(tcx, ty::Region::new_bound(tcx, ty::INNERMOST, br), param(0));
579-
let br = ty::BoundRegion { var: ty::BoundVar::from_u32(1), kind: ty::BrAnon };
581+
let br = ty::BoundRegion {
582+
var: ty::BoundVar::from_u32(1),
583+
kind: ty::BoundRegionKind::Anon,
584+
};
580585
let param_ty_rhs =
581586
Ty::new_imm_ref(tcx, ty::Region::new_bound(tcx, ty::INNERMOST, br), param(0));
582587
(1, 0, vec![param_ty_lhs, param_ty_rhs], tcx.types.bool)

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1048,8 +1048,10 @@ fn check_associated_item(
10481048
.coherent_trait(tcx.parent(item.trait_item_def_id.unwrap_or(item_id.into())))?;
10491049

10501050
let self_ty = match item.container {
1051-
ty::TraitContainer => tcx.types.self_param,
1052-
ty::ImplContainer => tcx.type_of(item.container_id(tcx)).instantiate_identity(),
1051+
ty::AssocItemContainer::Trait => tcx.types.self_param,
1052+
ty::AssocItemContainer::Impl => {
1053+
tcx.type_of(item.container_id(tcx)).instantiate_identity()
1054+
}
10531055
};
10541056

10551057
match item.kind {
@@ -1072,7 +1074,7 @@ fn check_associated_item(
10721074
check_method_receiver(wfcx, hir_sig, item, self_ty)
10731075
}
10741076
ty::AssocKind::Type => {
1075-
if let ty::AssocItemContainer::TraitContainer = item.container {
1077+
if let ty::AssocItemContainer::Trait = item.container {
10761078
check_associated_type_bounds(wfcx, item, span)
10771079
}
10781080
if item.defaultness(tcx).has_value() {

compiler/rustc_hir_analysis/src/collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ fn get_new_lifetime_name<'tcx>(
634634
.collect_referenced_late_bound_regions(poly_trait_ref)
635635
.into_iter()
636636
.filter_map(|lt| {
637-
if let ty::BoundRegionKind::BrNamed(_, name) = lt {
637+
if let ty::BoundRegionKind::Named(_, name) = lt {
638638
Some(name.as_str().to_string())
639639
} else {
640640
None

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ fn late_arg_as_bound_arg<'tcx>(
322322
let name = tcx.item_name(def_id);
323323
match param.kind {
324324
GenericParamKind::Lifetime { .. } => {
325-
ty::BoundVariableKind::Region(ty::BrNamed(def_id, name))
325+
ty::BoundVariableKind::Region(ty::BoundRegionKind::Named(def_id, name))
326326
}
327327
GenericParamKind::Type { .. } => {
328328
ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(def_id, name))
@@ -337,7 +337,7 @@ fn late_arg_as_bound_arg<'tcx>(
337337
fn generic_param_def_as_bound_arg(param: &ty::GenericParamDef) -> ty::BoundVariableKind {
338338
match param.kind {
339339
ty::GenericParamDefKind::Lifetime => {
340-
ty::BoundVariableKind::Region(ty::BoundRegionKind::BrNamed(param.def_id, param.name))
340+
ty::BoundVariableKind::Region(ty::BoundRegionKind::Named(param.def_id, param.name))
341341
}
342342
ty::GenericParamDefKind::Type { .. } => {
343343
ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(param.def_id, param.name))

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
644644
ty::GenericParamDefKind::Lifetime => {
645645
ty::Region::new_bound(tcx, ty::INNERMOST, ty::BoundRegion {
646646
var: ty::BoundVar::from_usize(num_bound_vars),
647-
kind: ty::BoundRegionKind::BrNamed(param.def_id, param.name),
647+
kind: ty::BoundRegionKind::Named(param.def_id, param.name),
648648
})
649649
.into()
650650
}
@@ -830,8 +830,8 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GenericParamAndBoundVarCollector<'_, 't
830830
}
831831
ty::ReBound(db, br) if db >= self.depth => {
832832
self.vars.insert(match br.kind {
833-
ty::BrNamed(def_id, name) => (def_id, name),
834-
ty::BrAnon | ty::BrEnv => {
833+
ty::BoundRegionKind::Named(def_id, name) => (def_id, name),
834+
ty::BoundRegionKind::Anon | ty::BoundRegionKind::ClosureEnv => {
835835
let guar = self
836836
.cx
837837
.dcx()

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
314314
let name = lifetime_name(def_id);
315315
let br = ty::BoundRegion {
316316
var: ty::BoundVar::from_u32(index),
317-
kind: ty::BrNamed(def_id.to_def_id(), name),
317+
kind: ty::BoundRegionKind::Named(def_id.to_def_id(), name),
318318
};
319319
ty::Region::new_bound(tcx, debruijn, br)
320320
}
@@ -332,7 +332,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
332332
ty::Region::new_late_param(
333333
tcx,
334334
scope.to_def_id(),
335-
ty::BrNamed(id.to_def_id(), name),
335+
ty::BoundRegionKind::Named(id.to_def_id(), name),
336336
)
337337

338338
// (*) -- not late-bound, won't change
@@ -2449,15 +2449,17 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
24492449
) {
24502450
for br in referenced_regions.difference(&constrained_regions) {
24512451
let br_name = match *br {
2452-
ty::BrNamed(_, kw::UnderscoreLifetime) | ty::BrAnon | ty::BrEnv => {
2453-
"an anonymous lifetime".to_string()
2454-
}
2455-
ty::BrNamed(_, name) => format!("lifetime `{name}`"),
2452+
ty::BoundRegionKind::Named(_, kw::UnderscoreLifetime)
2453+
| ty::BoundRegionKind::Anon
2454+
| ty::BoundRegionKind::ClosureEnv => "an anonymous lifetime".to_string(),
2455+
ty::BoundRegionKind::Named(_, name) => format!("lifetime `{name}`"),
24562456
};
24572457

24582458
let mut err = generate_err(&br_name);
24592459

2460-
if let ty::BrNamed(_, kw::UnderscoreLifetime) | ty::BrAnon = *br {
2460+
if let ty::BoundRegionKind::Named(_, kw::UnderscoreLifetime)
2461+
| ty::BoundRegionKind::Anon = *br
2462+
{
24612463
// The only way for an anonymous lifetime to wind up
24622464
// in the return type but **also** be unconstrained is
24632465
// if it only appears in "associated types" in the

compiler/rustc_hir_typeck/src/check.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -194,21 +194,21 @@ fn check_panic_info_fn(tcx: TyCtxt<'_>, fn_id: LocalDefId, fn_sig: ty::FnSig<'_>
194194
let panic_info_ty = tcx.type_of(panic_info_did).instantiate(tcx, &[ty::GenericArg::from(
195195
ty::Region::new_bound(tcx, ty::INNERMOST, ty::BoundRegion {
196196
var: ty::BoundVar::from_u32(1),
197-
kind: ty::BrAnon,
197+
kind: ty::BoundRegionKind::Anon,
198198
}),
199199
)]);
200200
let panic_info_ref_ty = Ty::new_imm_ref(
201201
tcx,
202202
ty::Region::new_bound(tcx, ty::INNERMOST, ty::BoundRegion {
203203
var: ty::BoundVar::ZERO,
204-
kind: ty::BrAnon,
204+
kind: ty::BoundRegionKind::Anon,
205205
}),
206206
panic_info_ty,
207207
);
208208

209209
let bounds = tcx.mk_bound_variable_kinds(&[
210-
ty::BoundVariableKind::Region(ty::BrAnon),
211-
ty::BoundVariableKind::Region(ty::BrAnon),
210+
ty::BoundVariableKind::Region(ty::BoundRegionKind::Anon),
211+
ty::BoundVariableKind::Region(ty::BoundRegionKind::Anon),
212212
]);
213213
let expected_sig = ty::Binder::bind_with_vars(
214214
tcx.mk_fn_sig([panic_info_ref_ty], tcx.types.never, false, fn_sig.safety, ExternAbi::Rust),

0 commit comments

Comments
 (0)