diff options
| author | Adam Ransom <v0id.gmr@gmail.com> | 2017-03-21 21:35:57 +0900 |
|---|---|---|
| committer | Adam Ransom <v0id.gmr@gmail.com> | 2017-03-22 19:27:35 +0900 |
| commit | 1ae1a19ba6156479969f493c8e05871539e69b52 (patch) | |
| tree | cf5bde48c7ef89fee39f74034f34e0a289ed8b7f | |
| parent | 8c4f2c64c6759a82f143e23964a46a65c67509c9 (diff) | |
| download | rust-1ae1a19ba6156479969f493c8e05871539e69b52.tar.gz rust-1ae1a19ba6156479969f493c8e05871539e69b52.zip | |
Refactor checking if a `Lifetime` is static
Simply move the test for `keywords::StaticLifetime` into the `Lifetime` impl, to match how elision is checked.
| -rw-r--r-- | src/librustc/hir/mod.rs | 4 | ||||
| -rw-r--r-- | src/librustc/middle/resolve_lifetime.rs | 4 |
2 files changed, 6 insertions, 2 deletions
diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index edcfcffaa03..8239fd7d13c 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -100,6 +100,10 @@ impl Lifetime { pub fn is_elided(&self) -> bool { self.name == keywords::Invalid.name() } + + pub fn is_static(&self) -> bool { + self.name == keywords::StaticLifetime.name() + } } /// A lifetime definition, eg `'a: 'b+'c+'d` diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 37749816eb1..10ee760a6a6 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -434,7 +434,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { self.resolve_elided_lifetimes(slice::ref_slice(lifetime_ref)); return; } - if lifetime_ref.name == keywords::StaticLifetime.name() { + if lifetime_ref.is_static() { self.insert_lifetime(lifetime_ref, Region::Static); return; } @@ -1434,7 +1434,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { let lifetime_i = &lifetimes[i]; for lifetime in lifetimes { - if lifetime.lifetime.name == keywords::StaticLifetime.name() { + if lifetime.lifetime.is_static() { let lifetime = lifetime.lifetime; let mut err = struct_span_err!(self.sess, lifetime.span, E0262, "invalid lifetime parameter name: `{}`", lifetime.name); |
