about summary refs log tree commit diff
path: root/src/libsyntax_ext
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-03-17 23:22:57 +0000
committerbors <bors@rust-lang.org>2018-03-17 23:22:57 +0000
commitca6a98426192f838cc90a18709f92d425b86029e (patch)
treeaad9717ff8dca9636794c782148b0729b46090e0 /src/libsyntax_ext
parentadf2135adc4a65a78ba053f04c29d7fe0468eb87 (diff)
parented5ea5c705ccea7d2eef1558530e87d2dbb88be7 (diff)
downloadrust-ca6a98426192f838cc90a18709f92d425b86029e.tar.gz
rust-ca6a98426192f838cc90a18709f92d425b86029e.zip
Auto merge of #48842 - petrochenkov:under, r=nikomatsakis
syntax: Make `_` a reserved identifier

Why:
- Lexically `_` is an identifier.
- Internally it makes implementation of `use Trait as _;` (https://github.com/rust-lang/rust/issues/48216) and some other things cleaner.
- We prevent the externally observable effect of `_` being accepted by macros expecting `ident` by treating `_` specially in the `ident` matcher:
```rust
macro_rules! m {
    ($i: ident) => { let $i = 10; }
}

m!(_); // Still an error
```
Diffstat (limited to 'src/libsyntax_ext')
-rw-r--r--src/libsyntax_ext/env.rs6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/libsyntax_ext/env.rs b/src/libsyntax_ext/env.rs
index fcad065be52..ba6d25f7a60 100644
--- a/src/libsyntax_ext/env.rs
+++ b/src/libsyntax_ext/env.rs
@@ -17,7 +17,7 @@ use syntax::ast::{self, Ident};
 use syntax::ext::base::*;
 use syntax::ext::base;
 use syntax::ext::build::AstBuilder;
-use syntax::symbol::Symbol;
+use syntax::symbol::{keywords, Symbol};
 use syntax_pos::Span;
 use syntax::tokenstream;
 
@@ -35,14 +35,14 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt,
     let sp = sp.with_ctxt(sp.ctxt().apply_mark(cx.current_expansion.mark));
     let e = match env::var(&*var.as_str()) {
         Err(..) => {
+            let lt = cx.lifetime(sp, keywords::StaticLifetime.ident());
             cx.expr_path(cx.path_all(sp,
                                      true,
                                      cx.std_path(&["option", "Option", "None"]),
                                      Vec::new(),
                                      vec![cx.ty_rptr(sp,
                                                      cx.ty_ident(sp, Ident::from_str("str")),
-                                                     Some(cx.lifetime(sp,
-                                                                      Ident::from_str("'static"))),
+                                                     Some(lt),
                                                      ast::Mutability::Immutable)],
                                      Vec::new()))
         }