Skip to content

Commit 10debec

Browse files
authored
Rollup merge of #138926 - nnethercote:less-kw-Empty-rustc_middle, r=lcnr
Remove `kw::Empty` uses from `rustc_middle`. There are several places in `rustc_middle` that check for an empty lifetime name. These checks appear to be totally unnecessary, because empty lifetime names aren't produced here. (Empty lifetime names *are* possible in `hir::Lifetime`. Perhaps there was some confusion between it and the `rustc_middle` types?) This commit removes the `kw::Empty` checks. r? `@lcnr`
2 parents 3a8621d + 5a6ed74 commit 10debec

File tree

5 files changed

+11
-20
lines changed

5 files changed

+11
-20
lines changed

compiler/rustc_middle/src/ty/generics.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ impl GenericParamDef {
7373

7474
pub fn is_anonymous_lifetime(&self) -> bool {
7575
match self.kind {
76-
GenericParamDefKind::Lifetime => {
77-
self.name == kw::UnderscoreLifetime || self.name == kw::Empty
78-
}
76+
GenericParamDefKind::Lifetime => self.name == kw::UnderscoreLifetime,
7977
_ => false,
8078
}
8179
}

compiler/rustc_middle/src/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ impl EarlyParamRegion {
457457
/// Does this early bound region have a name? Early bound regions normally
458458
/// always have names except when using anonymous lifetimes (`'_`).
459459
pub fn has_name(&self) -> bool {
460-
self.name != kw::UnderscoreLifetime && self.name != kw::Empty
460+
self.name != kw::UnderscoreLifetime
461461
}
462462
}
463463

compiler/rustc_middle/src/ty/print/pretty.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -2591,11 +2591,9 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
25912591
// to fit that into a short string. Hence the recommendation to use
25922592
// `explain_region()` or `note_and_explain_region()`.
25932593
match *region {
2594-
ty::ReEarlyParam(ref data) => {
2595-
if data.name != kw::Empty {
2596-
p!(write("{}", data.name));
2597-
return Ok(());
2598-
}
2594+
ty::ReEarlyParam(data) => {
2595+
p!(write("{}", data.name));
2596+
return Ok(());
25992597
}
26002598
ty::ReLateParam(ty::LateParamRegion { kind, .. }) => {
26012599
if let Some(name) = kind.get_name() {
@@ -2834,7 +2832,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
28342832

28352833
(name, ty::BoundRegionKind::Named(CRATE_DEF_ID.to_def_id(), name))
28362834
}
2837-
ty::BoundRegionKind::Named(def_id, kw::UnderscoreLifetime | kw::Empty) => {
2835+
ty::BoundRegionKind::Named(def_id, kw::UnderscoreLifetime) => {
28382836
let name = next_name(self);
28392837

28402838
if let Some(lt_idx) = lifetime_idx {

compiler/rustc_middle/src/ty/region.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,7 @@ impl LateParamRegionKind {
400400

401401
pub fn is_named(&self) -> bool {
402402
match *self {
403-
LateParamRegionKind::Named(_, name) => {
404-
name != kw::UnderscoreLifetime && name != kw::Empty
405-
}
403+
LateParamRegionKind::Named(_, name) => name != kw::UnderscoreLifetime,
406404
_ => false,
407405
}
408406
}
@@ -475,7 +473,7 @@ impl core::fmt::Debug for BoundRegion {
475473
impl BoundRegionKind {
476474
pub fn is_named(&self) -> bool {
477475
match *self {
478-
BoundRegionKind::Named(_, name) => name != kw::UnderscoreLifetime && name != kw::Empty,
476+
BoundRegionKind::Named(_, name) => name != kw::UnderscoreLifetime,
479477
_ => false,
480478
}
481479
}

src/librustdoc/clean/mod.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1943,14 +1943,11 @@ fn clean_trait_object_lifetime_bound<'tcx>(
19431943
// latter contrary to `clean_middle_region`.
19441944
match *region {
19451945
ty::ReStatic => Some(Lifetime::statik()),
1946-
ty::ReEarlyParam(region) if region.name != kw::Empty => Some(Lifetime(region.name)),
1947-
ty::ReBound(_, ty::BoundRegion { kind: ty::BoundRegionKind::Named(_, name), .. })
1948-
if name != kw::Empty =>
1949-
{
1946+
ty::ReEarlyParam(region) => Some(Lifetime(region.name)),
1947+
ty::ReBound(_, ty::BoundRegion { kind: ty::BoundRegionKind::Named(_, name), .. }) => {
19501948
Some(Lifetime(name))
19511949
}
1952-
ty::ReEarlyParam(_)
1953-
| ty::ReBound(..)
1950+
ty::ReBound(..)
19541951
| ty::ReLateParam(_)
19551952
| ty::ReVar(_)
19561953
| ty::RePlaceholder(_)

0 commit comments

Comments
 (0)