Skip to content

Commit d84993b

Browse files
committed
Rollup merge of rust-lang#34207 - petrochenkov:nohyg, r=jseyfried
Remove last traces of identifier hygiene from HIR rust-lang@e783a0a removed the [last](rust-lang#33654 (comment)) [use](rust-lang#33654 (comment)) of hygiene at post-resolve compilation stages, so we can avoid renaming during lowering to HIR and just keep original names. r? @nrc
2 parents bb4a79b + f59afbc commit d84993b

File tree

7 files changed

+13
-42
lines changed

7 files changed

+13
-42
lines changed

src/librustc/hir/lowering.rs

+6-29
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ use std::collections::BTreeMap;
5151
use std::iter;
5252
use syntax::ast::*;
5353
use syntax::attr::{ThinAttributes, ThinAttributesExt};
54-
use syntax::ext::mtwt;
5554
use syntax::ptr::P;
5655
use syntax::codemap::{respan, Spanned, Span};
57-
use syntax::parse::token::{self, keywords};
56+
use syntax::parse::token;
5857
use syntax::std_inject;
5958
use syntax::visit::{self, Visitor};
6059

@@ -184,16 +183,8 @@ impl<'a> LoweringContext<'a> {
184183
result
185184
}
186185

187-
fn lower_ident(&mut self, ident: Ident) -> Name {
188-
if ident.name != keywords::Invalid.name() {
189-
mtwt::resolve(ident)
190-
} else {
191-
ident.name
192-
}
193-
}
194-
195186
fn lower_opt_sp_ident(&mut self, o_id: Option<Spanned<Ident>>) -> Option<Spanned<Name>> {
196-
o_id.map(|sp_ident| respan(sp_ident.span, self.lower_ident(sp_ident.node)))
187+
o_id.map(|sp_ident| respan(sp_ident.span, sp_ident.node.name))
197188
}
198189

199190
fn lower_attrs(&mut self, attrs: &Vec<Attribute>) -> hir::HirVec<Attribute> {
@@ -338,18 +329,14 @@ impl<'a> LoweringContext<'a> {
338329
}
339330
}
340331

341-
fn lower_path_full(&mut self, p: &Path, rename: bool) -> hir::Path {
332+
fn lower_path(&mut self, p: &Path) -> hir::Path {
342333
hir::Path {
343334
global: p.global,
344335
segments: p.segments
345336
.iter()
346337
.map(|&PathSegment { identifier, ref parameters }| {
347338
hir::PathSegment {
348-
name: if rename {
349-
self.lower_ident(identifier)
350-
} else {
351-
identifier.name
352-
},
339+
name: identifier.name,
353340
parameters: self.lower_path_parameters(parameters),
354341
}
355342
})
@@ -358,10 +345,6 @@ impl<'a> LoweringContext<'a> {
358345
}
359346
}
360347

361-
fn lower_path(&mut self, p: &Path) -> hir::Path {
362-
self.lower_path_full(p, false)
363-
}
364-
365348
fn lower_path_parameters(&mut self, path_parameters: &PathParameters) -> hir::PathParameters {
366349
match *path_parameters {
367350
PathParameters::AngleBracketed(ref data) =>
@@ -870,8 +853,7 @@ impl<'a> LoweringContext<'a> {
870853
// `None` can occur in body-less function signatures
871854
None | Some(Def::Local(..)) => {
872855
hir::PatKind::Binding(this.lower_binding_mode(binding_mode),
873-
respan(pth1.span,
874-
this.lower_ident(pth1.node)),
856+
respan(pth1.span, pth1.node.name),
875857
sub.as_ref().map(|x| this.lower_pat(x)))
876858
}
877859
_ => hir::PatKind::Path(hir::Path::from_name(pth1.span, pth1.node.name))
@@ -1238,12 +1220,7 @@ impl<'a> LoweringContext<'a> {
12381220
position: position,
12391221
}
12401222
});
1241-
// Only local variables are renamed
1242-
let rename = match self.resolver.get_resolution(e.id).map(|d| d.base_def) {
1243-
Some(Def::Local(..)) | Some(Def::Upvar(..)) => true,
1244-
_ => false,
1245-
};
1246-
hir::ExprPath(hir_qself, self.lower_path_full(path, rename))
1223+
hir::ExprPath(hir_qself, self.lower_path(path))
12471224
}
12481225
ExprKind::Break(opt_ident) => hir::ExprBreak(self.lower_opt_sp_ident(opt_ident)),
12491226
ExprKind::Again(opt_ident) => hir::ExprAgain(self.lower_opt_sp_ident(opt_ident)),

src/librustc/hir/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ pub type ExplicitSelf = Spanned<SelfKind>;
11381138
impl Arg {
11391139
pub fn to_self(&self) -> Option<ExplicitSelf> {
11401140
if let PatKind::Binding(BindByValue(mutbl), name, _) = self.pat.node {
1141-
if name.node.unhygienize() == keywords::SelfValue.name() {
1141+
if name.node == keywords::SelfValue.name() {
11421142
return match self.ty.node {
11431143
TyInfer => Some(respan(self.pat.span, SelfKind::Value(mutbl))),
11441144
TyRptr(lt, MutTy{ref ty, mutbl}) if ty.node == TyInfer => {
@@ -1154,7 +1154,7 @@ impl Arg {
11541154

11551155
pub fn is_self(&self) -> bool {
11561156
if let PatKind::Binding(_, name, _) = self.pat.node {
1157-
name.node.unhygienize() == keywords::SelfValue.name()
1157+
name.node == keywords::SelfValue.name()
11581158
} else {
11591159
false
11601160
}

src/librustc/middle/resolve_lifetime.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,7 @@ fn extract_labels(ctxt: &mut LifetimeContext, b: &hir::Block) {
456456
fn expression_label(ex: &hir::Expr) -> Option<(ast::Name, Span)> {
457457
match ex.node {
458458
hir::ExprWhile(_, _, Some(label)) |
459-
hir::ExprLoop(_, Some(label)) => Some((label.node.unhygienize(),
460-
label.span)),
459+
hir::ExprLoop(_, Some(label)) => Some((label.node, label.span)),
461460
_ => None,
462461
}
463462
}

src/librustc_const_eval/check_match.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,7 @@ fn check_for_bindings_named_the_same_as_variants(cx: &MatchCheckCtxt, pat: &Pat)
247247
if let ty::TyEnum(edef, _) = pat_ty.sty {
248248
if let Def::Local(..) = cx.tcx.expect_def(p.id) {
249249
if edef.variants.iter().any(|variant|
250-
variant.name == name.node.unhygienize()
251-
&& variant.kind() == VariantKind::Unit
250+
variant.name == name.node && variant.kind() == VariantKind::Unit
252251
) {
253252
let ty_path = cx.tcx.item_path_str(edef.did);
254253
let mut err = struct_span_warn!(cx.tcx.sess, p.span, E0170,

src/librustc_lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl LateLintPass for NonShorthandFieldPatterns {
163163
continue;
164164
}
165165
if let PatKind::Binding(_, ident, None) = fieldpat.node.pat.node {
166-
if ident.node.unhygienize() == fieldpat.node.name {
166+
if ident.node == fieldpat.node.name {
167167
cx.span_lint(NON_SHORTHAND_FIELD_PATTERNS, fieldpat.span,
168168
&format!("the `{}:` in this pattern is redundant and can \
169169
be removed", ident.node))

src/librustc_trans/debuginfo/create_scope_map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub fn create_scope_map(cx: &CrateContext,
5151
for arg in args {
5252
pat_util::pat_bindings(&arg.pat, |_, node_id, _, path1| {
5353
scope_stack.push(ScopeStackEntry { scope_metadata: fn_metadata,
54-
name: Some(path1.node.unhygienize()) });
54+
name: Some(path1.node) });
5555
scope_map.insert(node_id, fn_metadata);
5656
})
5757
}
@@ -260,7 +260,7 @@ fn walk_pattern(cx: &CrateContext,
260260
// N.B.: this comparison must be UNhygienic... because
261261
// gdb knows nothing about the context, so any two
262262
// variables with the same name will cause the problem.
263-
let name = path1.node.unhygienize();
263+
let name = path1.node;
264264
let need_new_scope = scope_stack
265265
.iter()
266266
.any(|entry| entry.name == Some(name));

src/libsyntax/ast.rs

-4
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ impl Name {
6060
pub fn as_str(self) -> token::InternedString {
6161
token::InternedString::new_from_name(self)
6262
}
63-
64-
pub fn unhygienize(self) -> Name {
65-
token::intern(&self.as_str())
66-
}
6763
}
6864

6965
impl fmt::Debug for Name {

0 commit comments

Comments
 (0)