Skip to content

Commit 1ae1a19

Browse files
committed
Refactor checking if a Lifetime is static
Simply move the test for `keywords::StaticLifetime` into the `Lifetime` impl, to match how elision is checked.
1 parent 8c4f2c6 commit 1ae1a19

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/librustc/hir/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ impl Lifetime {
100100
pub fn is_elided(&self) -> bool {
101101
self.name == keywords::Invalid.name()
102102
}
103+
104+
pub fn is_static(&self) -> bool {
105+
self.name == keywords::StaticLifetime.name()
106+
}
103107
}
104108

105109
/// A lifetime definition, eg `'a: 'b+'c+'d`

src/librustc/middle/resolve_lifetime.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
434434
self.resolve_elided_lifetimes(slice::ref_slice(lifetime_ref));
435435
return;
436436
}
437-
if lifetime_ref.name == keywords::StaticLifetime.name() {
437+
if lifetime_ref.is_static() {
438438
self.insert_lifetime(lifetime_ref, Region::Static);
439439
return;
440440
}
@@ -1434,7 +1434,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
14341434
let lifetime_i = &lifetimes[i];
14351435

14361436
for lifetime in lifetimes {
1437-
if lifetime.lifetime.name == keywords::StaticLifetime.name() {
1437+
if lifetime.lifetime.is_static() {
14381438
let lifetime = lifetime.lifetime;
14391439
let mut err = struct_span_err!(self.sess, lifetime.span, E0262,
14401440
"invalid lifetime parameter name: `{}`", lifetime.name);

0 commit comments

Comments
 (0)