diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2016-06-15 22:59:20 +0100 |
|---|---|---|
| committer | Manish Goregaokar <manishsmail@gmail.com> | 2016-06-16 01:39:43 +0100 |
| commit | d84993b054faf9ac73239f73f5edad949f7d5341 (patch) | |
| tree | 7f7890a25e2341c78826907cee6d32d47b211820 | |
| parent | bb4a79b087158f396b984bdf552d2c90890b12a3 (diff) | |
| parent | f59afbc2143894932529a29057de25a4425ed65e (diff) | |
| download | rust-d84993b054faf9ac73239f73f5edad949f7d5341.tar.gz rust-d84993b054faf9ac73239f73f5edad949f7d5341.zip | |
Rollup merge of #34207 - petrochenkov:nohyg, r=jseyfried
Remove last traces of identifier hygiene from HIR https://github.com/rust-lang/rust/pull/34095/commits/e783a0a5e39d5ae2fa147508197d09a51530fae8 removed the [last](https://github.com/rust-lang/rust/pull/33654#discussion_r63415218) [use](https://github.com/rust-lang/rust/pull/33654#discussion_r63416284) of hygiene at post-resolve compilation stages, so we can avoid renaming during lowering to HIR and just keep original names. r? @nrc
| -rw-r--r-- | src/librustc/hir/lowering.rs | 35 | ||||
| -rw-r--r-- | src/librustc/hir/mod.rs | 4 | ||||
| -rw-r--r-- | src/librustc/middle/resolve_lifetime.rs | 3 | ||||
| -rw-r--r-- | src/librustc_const_eval/check_match.rs | 3 | ||||
| -rw-r--r-- | src/librustc_lint/builtin.rs | 2 | ||||
| -rw-r--r-- | src/librustc_trans/debuginfo/create_scope_map.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/ast.rs | 4 |
7 files changed, 13 insertions, 42 deletions
diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 69cf5baa26f..393045bf93e 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -51,10 +51,9 @@ use std::collections::BTreeMap; use std::iter; use syntax::ast::*; use syntax::attr::{ThinAttributes, ThinAttributesExt}; -use syntax::ext::mtwt; use syntax::ptr::P; use syntax::codemap::{respan, Spanned, Span}; -use syntax::parse::token::{self, keywords}; +use syntax::parse::token; use syntax::std_inject; use syntax::visit::{self, Visitor}; @@ -184,16 +183,8 @@ impl<'a> LoweringContext<'a> { result } - fn lower_ident(&mut self, ident: Ident) -> Name { - if ident.name != keywords::Invalid.name() { - mtwt::resolve(ident) - } else { - ident.name - } - } - fn lower_opt_sp_ident(&mut self, o_id: Option<Spanned<Ident>>) -> Option<Spanned<Name>> { - o_id.map(|sp_ident| respan(sp_ident.span, self.lower_ident(sp_ident.node))) + o_id.map(|sp_ident| respan(sp_ident.span, sp_ident.node.name)) } fn lower_attrs(&mut self, attrs: &Vec<Attribute>) -> hir::HirVec<Attribute> { @@ -338,18 +329,14 @@ impl<'a> LoweringContext<'a> { } } - fn lower_path_full(&mut self, p: &Path, rename: bool) -> hir::Path { + fn lower_path(&mut self, p: &Path) -> hir::Path { hir::Path { global: p.global, segments: p.segments .iter() .map(|&PathSegment { identifier, ref parameters }| { hir::PathSegment { - name: if rename { - self.lower_ident(identifier) - } else { - identifier.name - }, + name: identifier.name, parameters: self.lower_path_parameters(parameters), } }) @@ -358,10 +345,6 @@ impl<'a> LoweringContext<'a> { } } - fn lower_path(&mut self, p: &Path) -> hir::Path { - self.lower_path_full(p, false) - } - fn lower_path_parameters(&mut self, path_parameters: &PathParameters) -> hir::PathParameters { match *path_parameters { PathParameters::AngleBracketed(ref data) => @@ -870,8 +853,7 @@ impl<'a> LoweringContext<'a> { // `None` can occur in body-less function signatures None | Some(Def::Local(..)) => { hir::PatKind::Binding(this.lower_binding_mode(binding_mode), - respan(pth1.span, - this.lower_ident(pth1.node)), + respan(pth1.span, pth1.node.name), sub.as_ref().map(|x| this.lower_pat(x))) } _ => hir::PatKind::Path(hir::Path::from_name(pth1.span, pth1.node.name)) @@ -1238,12 +1220,7 @@ impl<'a> LoweringContext<'a> { position: position, } }); - // Only local variables are renamed - let rename = match self.resolver.get_resolution(e.id).map(|d| d.base_def) { - Some(Def::Local(..)) | Some(Def::Upvar(..)) => true, - _ => false, - }; - hir::ExprPath(hir_qself, self.lower_path_full(path, rename)) + hir::ExprPath(hir_qself, self.lower_path(path)) } ExprKind::Break(opt_ident) => hir::ExprBreak(self.lower_opt_sp_ident(opt_ident)), ExprKind::Again(opt_ident) => hir::ExprAgain(self.lower_opt_sp_ident(opt_ident)), diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index c36c88c7990..8faa1cc1174 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -1138,7 +1138,7 @@ pub type ExplicitSelf = Spanned<SelfKind>; impl Arg { pub fn to_self(&self) -> Option<ExplicitSelf> { if let PatKind::Binding(BindByValue(mutbl), name, _) = self.pat.node { - if name.node.unhygienize() == keywords::SelfValue.name() { + if name.node == keywords::SelfValue.name() { return match self.ty.node { TyInfer => Some(respan(self.pat.span, SelfKind::Value(mutbl))), TyRptr(lt, MutTy{ref ty, mutbl}) if ty.node == TyInfer => { @@ -1154,7 +1154,7 @@ impl Arg { pub fn is_self(&self) -> bool { if let PatKind::Binding(_, name, _) = self.pat.node { - name.node.unhygienize() == keywords::SelfValue.name() + name.node == keywords::SelfValue.name() } else { false } diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index dcc84fb0439..78d9f5c9b7c 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -456,8 +456,7 @@ fn extract_labels(ctxt: &mut LifetimeContext, b: &hir::Block) { fn expression_label(ex: &hir::Expr) -> Option<(ast::Name, Span)> { match ex.node { hir::ExprWhile(_, _, Some(label)) | - hir::ExprLoop(_, Some(label)) => Some((label.node.unhygienize(), - label.span)), + hir::ExprLoop(_, Some(label)) => Some((label.node, label.span)), _ => None, } } diff --git a/src/librustc_const_eval/check_match.rs b/src/librustc_const_eval/check_match.rs index f183736b9ed..dbca15ffd34 100644 --- a/src/librustc_const_eval/check_match.rs +++ b/src/librustc_const_eval/check_match.rs @@ -247,8 +247,7 @@ fn check_for_bindings_named_the_same_as_variants(cx: &MatchCheckCtxt, pat: &Pat) if let ty::TyEnum(edef, _) = pat_ty.sty { if let Def::Local(..) = cx.tcx.expect_def(p.id) { if edef.variants.iter().any(|variant| - variant.name == name.node.unhygienize() - && variant.kind() == VariantKind::Unit + variant.name == name.node && variant.kind() == VariantKind::Unit ) { let ty_path = cx.tcx.item_path_str(edef.did); let mut err = struct_span_warn!(cx.tcx.sess, p.span, E0170, diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 2bd2997566e..3ceca9218bd 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -163,7 +163,7 @@ impl LateLintPass for NonShorthandFieldPatterns { continue; } if let PatKind::Binding(_, ident, None) = fieldpat.node.pat.node { - if ident.node.unhygienize() == fieldpat.node.name { + if ident.node == fieldpat.node.name { cx.span_lint(NON_SHORTHAND_FIELD_PATTERNS, fieldpat.span, &format!("the `{}:` in this pattern is redundant and can \ be removed", ident.node)) diff --git a/src/librustc_trans/debuginfo/create_scope_map.rs b/src/librustc_trans/debuginfo/create_scope_map.rs index f1d9e2c5a57..33bdccbf067 100644 --- a/src/librustc_trans/debuginfo/create_scope_map.rs +++ b/src/librustc_trans/debuginfo/create_scope_map.rs @@ -51,7 +51,7 @@ pub fn create_scope_map(cx: &CrateContext, for arg in args { pat_util::pat_bindings(&arg.pat, |_, node_id, _, path1| { scope_stack.push(ScopeStackEntry { scope_metadata: fn_metadata, - name: Some(path1.node.unhygienize()) }); + name: Some(path1.node) }); scope_map.insert(node_id, fn_metadata); }) } @@ -260,7 +260,7 @@ fn walk_pattern(cx: &CrateContext, // N.B.: this comparison must be UNhygienic... because // gdb knows nothing about the context, so any two // variables with the same name will cause the problem. - let name = path1.node.unhygienize(); + let name = path1.node; let need_new_scope = scope_stack .iter() .any(|entry| entry.name == Some(name)); diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 40c98206c16..8537fcc221c 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -60,10 +60,6 @@ impl Name { pub fn as_str(self) -> token::InternedString { token::InternedString::new_from_name(self) } - - pub fn unhygienize(self) -> Name { - token::intern(&self.as_str()) - } } impl fmt::Debug for Name { |
