Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit eb789de

Browse files
committedDec 4, 2015
Do MTWT resolution during lowering to HIR
1 parent 68c15be commit eb789de

File tree

17 files changed

+156
-86
lines changed

17 files changed

+156
-86
lines changed
 

‎src/librustc/middle/check_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ fn check_for_bindings_named_the_same_as_variants(cx: &MatchCheckCtxt, pat: &Pat)
247247
let def = cx.tcx.def_map.borrow().get(&p.id).map(|d| d.full_def());
248248
if let Some(DefLocal(..)) = def {
249249
if edef.variants.iter().any(|variant|
250-
variant.name == ident.node.name
250+
variant.name == ident.node.unhygienic_name
251251
&& variant.kind() == VariantKind::Unit
252252
) {
253253
span_warn!(cx.tcx.sess, p.span, E0170,

‎src/librustc/middle/liveness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1596,7 +1596,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
15961596
self.ir.tcx.sess.add_lint(lint::builtin::UNUSED_VARIABLES, id, sp,
15971597
format!("variable `{}` is assigned to, but never used",
15981598
name));
1599-
} else {
1599+
} else if name != "self" {
16001600
self.ir.tcx.sess.add_lint(lint::builtin::UNUSED_VARIABLES, id, sp,
16011601
format!("unused variable: `{}`", name));
16021602
}

‎src/librustc/middle/pat_util.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use middle::ty;
1414
use util::nodemap::FnvHashMap;
1515

1616
use syntax::ast;
17-
use syntax::ext::mtwt;
1817
use rustc_front::hir;
1918
use rustc_front::util::walk_pat;
2019
use syntax::codemap::{respan, Span, Spanned, DUMMY_SP};
@@ -27,8 +26,8 @@ pub type PatIdMap = FnvHashMap<ast::Name, ast::NodeId>;
2726
// use the NodeId of their namesake in the first pattern.
2827
pub fn pat_id_map(dm: &RefCell<DefMap>, pat: &hir::Pat) -> PatIdMap {
2928
let mut map = FnvHashMap();
30-
pat_bindings_hygienic(dm, pat, |_bm, p_id, _s, path1| {
31-
map.insert(mtwt::resolve(path1.node), p_id);
29+
pat_bindings(dm, pat, |_bm, p_id, _s, path1| {
30+
map.insert(path1.node, p_id);
3231
});
3332
map
3433
}
@@ -124,9 +123,8 @@ pub fn pat_bindings<I>(dm: &RefCell<DefMap>, pat: &hir::Pat, mut it: I) where
124123
true
125124
});
126125
}
127-
128-
pub fn pat_bindings_hygienic<I>(dm: &RefCell<DefMap>, pat: &hir::Pat, mut it: I) where
129-
I: FnMut(hir::BindingMode, ast::NodeId, Span, &Spanned<ast::Ident>),
126+
pub fn pat_bindings_ident<I>(dm: &RefCell<DefMap>, pat: &hir::Pat, mut it: I) where
127+
I: FnMut(hir::BindingMode, ast::NodeId, Span, &Spanned<hir::Ident>),
130128
{
131129
walk_pat(pat, |p| {
132130
match p.node {
@@ -214,7 +212,7 @@ pub fn def_to_path(tcx: &ty::ctxt, id: DefId) -> hir::Path {
214212
tcx.with_path(id, |path| hir::Path {
215213
global: false,
216214
segments: path.last().map(|elem| hir::PathSegment {
217-
identifier: ast::Ident::with_empty_ctxt(elem.name()),
215+
identifier: hir::Ident::from_name(elem.name()),
218216
parameters: hir::PathParameters::none(),
219217
}).into_iter().collect(),
220218
span: DUMMY_SP,

‎src/librustc/middle/resolve_lifetime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ fn extract_labels<'v, 'a>(ctxt: &mut LifetimeContext<'a>, b: &'v hir::Block) {
426426
fn expression_label(ex: &hir::Expr) -> Option<ast::Name> {
427427
match ex.node {
428428
hir::ExprWhile(_, _, Some(label)) |
429-
hir::ExprLoop(_, Some(label)) => Some(label.name),
429+
hir::ExprLoop(_, Some(label)) => Some(label.unhygienic_name),
430430
_ => None,
431431
}
432432
}

‎src/librustc_driver/driver.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ pub fn compile_input(sess: Session,
112112
let mut hir_forest = time(sess.time_passes(),
113113
"lowering ast -> hir",
114114
|| hir_map::Forest::new(lower_crate(&lcx, &expanded_crate)));
115+
116+
// Discard MTWT tables that aren't required past lowering to HIR.
117+
if !sess.opts.debugging_opts.keep_mtwt_tables &&
118+
!sess.opts.debugging_opts.save_analysis {
119+
syntax::ext::mtwt::clear_tables();
120+
}
121+
115122
let arenas = ty::CtxtArenas::new();
116123
let ast_map = make_map(&sess, &mut hir_forest);
117124

@@ -704,12 +711,6 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
704711
"resolution",
705712
|| resolve::resolve_crate(sess, &ast_map, make_glob_map));
706713

707-
// Discard MTWT tables that aren't required past resolution.
708-
// FIXME: get rid of uses of MTWT tables in typeck, mir and trans and clear them
709-
if !sess.opts.debugging_opts.keep_mtwt_tables {
710-
// syntax::ext::mtwt::clear_tables();
711-
}
712-
713714
let named_region_map = time(time_passes,
714715
"lifetime resolution",
715716
|| middle::resolve_lifetime::krate(sess, krate, &def_map.borrow()));

‎src/librustc_front/fold.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//! and returns a piece of the same type.
1313
1414
use hir::*;
15-
use syntax::ast::{Ident, Name, NodeId, DUMMY_NODE_ID, Attribute, Attribute_, MetaItem};
15+
use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, Attribute, Attribute_, MetaItem};
1616
use syntax::ast::{MetaWord, MetaList, MetaNameValue};
1717
use syntax::attr::ThinAttributesExt;
1818
use hir;

‎src/librustc_front/hir.rs

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use intravisit::Visitor;
3939
use std::collections::BTreeMap;
4040
use syntax::codemap::{self, Span, Spanned, DUMMY_SP, ExpnId};
4141
use syntax::abi::Abi;
42-
use syntax::ast::{Name, Ident, NodeId, DUMMY_NODE_ID, TokenTree, AsmDialect};
42+
use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, TokenTree, AsmDialect};
4343
use syntax::ast::{Attribute, Lit, StrStyle, FloatTy, IntTy, UintTy, CrateConfig};
4444
use syntax::attr::ThinAttributes;
4545
use syntax::owned_slice::OwnedSlice;
@@ -50,7 +50,59 @@ use print::pprust;
5050
use util;
5151

5252
use std::fmt;
53-
use serialize::{Encodable, Encoder, Decoder};
53+
use std::hash::{Hash, Hasher};
54+
use serialize::{Encodable, Decodable, Encoder, Decoder};
55+
56+
/// Identifier in HIR
57+
#[derive(Clone, Copy, Eq)]
58+
pub struct Ident {
59+
/// Hygienic name (renamed), should be used by default
60+
pub name: Name,
61+
/// Unhygienic name (original, not renamed), needed in few places in name resolution
62+
pub unhygienic_name: Name,
63+
}
64+
65+
impl Ident {
66+
pub fn from_name(name: Name) -> Ident {
67+
Ident { name: name, unhygienic_name: name }
68+
}
69+
}
70+
71+
impl PartialEq for Ident {
72+
fn eq(&self, other: &Ident) -> bool {
73+
self.name == other.name
74+
}
75+
}
76+
77+
impl Hash for Ident {
78+
fn hash<H: Hasher>(&self, state: &mut H) {
79+
self.name.hash(state)
80+
}
81+
}
82+
83+
impl fmt::Debug for Ident {
84+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
85+
fmt::Debug::fmt(&self.name, f)
86+
}
87+
}
88+
89+
impl fmt::Display for Ident {
90+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
91+
fmt::Display::fmt(&self.name, f)
92+
}
93+
}
94+
95+
impl Encodable for Ident {
96+
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
97+
self.name.encode(s)
98+
}
99+
}
100+
101+
impl Decodable for Ident {
102+
fn decode<D: Decoder>(d: &mut D) -> Result<Ident, D::Error> {
103+
Ok(Ident::from_name(try!(Name::decode(d))))
104+
}
105+
}
54106

55107
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
56108
pub struct Lifetime {

‎src/librustc_front/intravisit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
//! property.
2727
2828
use syntax::abi::Abi;
29-
use syntax::ast::{Ident, NodeId, CRATE_NODE_ID, Name, Attribute};
29+
use syntax::ast::{NodeId, CRATE_NODE_ID, Name, Attribute};
3030
use syntax::codemap::Span;
3131
use hir::*;
3232

‎src/librustc_front/lowering.rs

Lines changed: 57 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@ use std::collections::BTreeMap;
6767
use std::collections::HashMap;
6868
use syntax::ast::*;
6969
use syntax::attr::{ThinAttributes, ThinAttributesExt};
70+
use syntax::ext::mtwt;
7071
use syntax::ptr::P;
7172
use syntax::codemap::{respan, Spanned, Span};
7273
use syntax::owned_slice::OwnedSlice;
73-
use syntax::parse::token::{self, str_to_ident};
74+
use syntax::parse::token;
7475
use syntax::std_inject;
7576
use syntax::visit::{self, Visitor};
7677

@@ -86,7 +87,7 @@ pub struct LoweringContext<'a> {
8687
// incrementing.
8788
cached_id: Cell<u32>,
8889
// Keep track of gensym'ed idents.
89-
gensym_cache: RefCell<HashMap<(NodeId, &'static str), Ident>>,
90+
gensym_cache: RefCell<HashMap<(NodeId, &'static str), hir::Ident>>,
9091
// A copy of cached_id, but is also set to an id while it is being cached.
9192
gensym_key: Cell<u32>,
9293
}
@@ -123,23 +124,30 @@ impl<'a, 'hir> LoweringContext<'a> {
123124
cached
124125
}
125126

126-
fn str_to_ident(&self, s: &'static str) -> Ident {
127+
fn str_to_ident(&self, s: &'static str) -> hir::Ident {
127128
let cached_id = self.gensym_key.get();
128129
if cached_id == 0 {
129-
return token::gensym_ident(s);
130+
return hir::Ident::from_name(token::gensym(s));
130131
}
131132

132133
let cached = self.gensym_cache.borrow().contains_key(&(cached_id, s));
133134
if cached {
134135
self.gensym_cache.borrow()[&(cached_id, s)]
135136
} else {
136-
let result = token::gensym_ident(s);
137+
let result = hir::Ident::from_name(token::gensym(s));
137138
self.gensym_cache.borrow_mut().insert((cached_id, s), result);
138139
result
139140
}
140141
}
141142
}
142143

144+
pub fn lower_ident(_lctx: &LoweringContext, ident: Ident) -> hir::Ident {
145+
hir::Ident {
146+
name: mtwt::resolve(ident),
147+
unhygienic_name: ident.name,
148+
}
149+
}
150+
143151
pub fn lower_view_path(lctx: &LoweringContext, view_path: &ViewPath) -> P<hir::ViewPath> {
144152
P(Spanned {
145153
node: match view_path.node {
@@ -276,14 +284,22 @@ pub fn lower_variant(lctx: &LoweringContext, v: &Variant) -> P<hir::Variant> {
276284
})
277285
}
278286

279-
pub fn lower_path(lctx: &LoweringContext, p: &Path) -> hir::Path {
287+
// Path segments are usually unhygienic, hygienic path segments can occur only in
288+
// identifier-like paths originating from `ExprPath`.
289+
// Make life simpler for rustc_resolve by renaming only such segments.
290+
pub fn lower_path_full(lctx: &LoweringContext, p: &Path, maybe_hygienic: bool) -> hir::Path {
291+
let maybe_hygienic = maybe_hygienic && !p.global && p.segments.len() == 1;
280292
hir::Path {
281293
global: p.global,
282294
segments: p.segments
283295
.iter()
284296
.map(|&PathSegment { identifier, ref parameters }| {
285297
hir::PathSegment {
286-
identifier: identifier,
298+
identifier: if maybe_hygienic {
299+
lower_ident(lctx, identifier)
300+
} else {
301+
hir::Ident::from_name(identifier.name)
302+
},
287303
parameters: lower_path_parameters(lctx, parameters),
288304
}
289305
})
@@ -292,6 +308,10 @@ pub fn lower_path(lctx: &LoweringContext, p: &Path) -> hir::Path {
292308
}
293309
}
294310

311+
pub fn lower_path(lctx: &LoweringContext, p: &Path) -> hir::Path {
312+
lower_path_full(lctx, p, false)
313+
}
314+
295315
pub fn lower_path_parameters(lctx: &LoweringContext,
296316
path_parameters: &PathParameters)
297317
-> hir::PathParameters {
@@ -844,7 +864,7 @@ pub fn lower_pat(lctx: &LoweringContext, p: &Pat) -> P<hir::Pat> {
844864
PatWild => hir::PatWild,
845865
PatIdent(ref binding_mode, pth1, ref sub) => {
846866
hir::PatIdent(lower_binding_mode(lctx, binding_mode),
847-
pth1,
867+
respan(pth1.span, lower_ident(lctx, pth1.node)),
848868
sub.as_ref().map(|x| lower_pat(lctx, x)))
849869
}
850870
PatLit(ref e) => hir::PatLit(lower_expr(lctx, e)),
@@ -1138,10 +1158,12 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P<hir::Expr> {
11381158
hir::ExprIf(lower_expr(lctx, cond), lower_block(lctx, blk), else_opt)
11391159
}
11401160
ExprWhile(ref cond, ref body, opt_ident) => {
1141-
hir::ExprWhile(lower_expr(lctx, cond), lower_block(lctx, body), opt_ident)
1161+
hir::ExprWhile(lower_expr(lctx, cond), lower_block(lctx, body),
1162+
opt_ident.map(|ident| lower_ident(lctx, ident)))
11421163
}
11431164
ExprLoop(ref body, opt_ident) => {
1144-
hir::ExprLoop(lower_block(lctx, body), opt_ident)
1165+
hir::ExprLoop(lower_block(lctx, body),
1166+
opt_ident.map(|ident| lower_ident(lctx, ident)))
11451167
}
11461168
ExprMatch(ref expr, ref arms) => {
11471169
hir::ExprMatch(lower_expr(lctx, expr),
@@ -1176,16 +1198,20 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P<hir::Expr> {
11761198
e2.as_ref().map(|x| lower_expr(lctx, x)))
11771199
}
11781200
ExprPath(ref qself, ref path) => {
1179-
let qself = qself.as_ref().map(|&QSelf { ref ty, position }| {
1201+
let hir_qself = qself.as_ref().map(|&QSelf { ref ty, position }| {
11801202
hir::QSelf {
11811203
ty: lower_ty(lctx, ty),
11821204
position: position,
11831205
}
11841206
});
1185-
hir::ExprPath(qself, lower_path(lctx, path))
1207+
hir::ExprPath(hir_qself, lower_path_full(lctx, path, qself.is_none()))
11861208
}
1187-
ExprBreak(opt_ident) => hir::ExprBreak(opt_ident),
1188-
ExprAgain(opt_ident) => hir::ExprAgain(opt_ident),
1209+
ExprBreak(opt_ident) => hir::ExprBreak(opt_ident.map(|sp_ident| {
1210+
respan(sp_ident.span, lower_ident(lctx, sp_ident.node))
1211+
})),
1212+
ExprAgain(opt_ident) => hir::ExprAgain(opt_ident.map(|sp_ident| {
1213+
respan(sp_ident.span, lower_ident(lctx, sp_ident.node))
1214+
})),
11891215
ExprRet(ref e) => hir::ExprRet(e.as_ref().map(|x| lower_expr(lctx, x))),
11901216
ExprInlineAsm(InlineAsm {
11911217
ref inputs,
@@ -1356,8 +1382,10 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P<hir::Expr> {
13561382

13571383
// `[opt_ident]: loop { ... }`
13581384
let loop_block = block_expr(lctx, match_expr);
1385+
let loop_expr = hir::ExprLoop(loop_block,
1386+
opt_ident.map(|ident| lower_ident(lctx, ident)));
13591387
// add attributes to the outer returned expr node
1360-
expr(lctx, e.span, hir::ExprLoop(loop_block, opt_ident), e.attrs.clone())
1388+
expr(lctx, e.span, loop_expr, e.attrs.clone())
13611389
});
13621390
}
13631391

@@ -1434,10 +1462,9 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P<hir::Expr> {
14341462

14351463
// `[opt_ident]: loop { ... }`
14361464
let loop_block = block_expr(lctx, match_expr);
1437-
let loop_expr = expr(lctx,
1438-
e.span,
1439-
hir::ExprLoop(loop_block, opt_ident),
1440-
None);
1465+
let loop_expr = hir::ExprLoop(loop_block,
1466+
opt_ident.map(|ident| lower_ident(lctx, ident)));
1467+
let loop_expr = expr(lctx, e.span, loop_expr, None);
14411468

14421469
// `mut iter => { ... }`
14431470
let iter_arm = {
@@ -1593,7 +1620,7 @@ fn expr_call(lctx: &LoweringContext,
15931620
expr(lctx, span, hir::ExprCall(e, args), attrs)
15941621
}
15951622

1596-
fn expr_ident(lctx: &LoweringContext, span: Span, id: Ident,
1623+
fn expr_ident(lctx: &LoweringContext, span: Span, id: hir::Ident,
15971624
attrs: ThinAttributes) -> P<hir::Expr> {
15981625
expr_path(lctx, path_ident(span, id), attrs)
15991626
}
@@ -1641,7 +1668,7 @@ fn expr(lctx: &LoweringContext, span: Span, node: hir::Expr_,
16411668
fn stmt_let(lctx: &LoweringContext,
16421669
sp: Span,
16431670
mutbl: bool,
1644-
ident: Ident,
1671+
ident: hir::Ident,
16451672
ex: P<hir::Expr>,
16461673
attrs: ThinAttributes)
16471674
-> P<hir::Stmt> {
@@ -1701,13 +1728,13 @@ fn pat_enum(lctx: &LoweringContext,
17011728
pat(lctx, span, pt)
17021729
}
17031730

1704-
fn pat_ident(lctx: &LoweringContext, span: Span, ident: Ident) -> P<hir::Pat> {
1731+
fn pat_ident(lctx: &LoweringContext, span: Span, ident: hir::Ident) -> P<hir::Pat> {
17051732
pat_ident_binding_mode(lctx, span, ident, hir::BindByValue(hir::MutImmutable))
17061733
}
17071734

17081735
fn pat_ident_binding_mode(lctx: &LoweringContext,
17091736
span: Span,
1710-
ident: Ident,
1737+
ident: hir::Ident,
17111738
bm: hir::BindingMode)
17121739
-> P<hir::Pat> {
17131740
let pat_ident = hir::PatIdent(bm,
@@ -1731,21 +1758,21 @@ fn pat(lctx: &LoweringContext, span: Span, pat: hir::Pat_) -> P<hir::Pat> {
17311758
})
17321759
}
17331760

1734-
fn path_ident(span: Span, id: Ident) -> hir::Path {
1761+
fn path_ident(span: Span, id: hir::Ident) -> hir::Path {
17351762
path(span, vec![id])
17361763
}
17371764

1738-
fn path(span: Span, strs: Vec<Ident>) -> hir::Path {
1765+
fn path(span: Span, strs: Vec<hir::Ident>) -> hir::Path {
17391766
path_all(span, false, strs, Vec::new(), Vec::new(), Vec::new())
17401767
}
17411768

1742-
fn path_global(span: Span, strs: Vec<Ident>) -> hir::Path {
1769+
fn path_global(span: Span, strs: Vec<hir::Ident>) -> hir::Path {
17431770
path_all(span, true, strs, Vec::new(), Vec::new(), Vec::new())
17441771
}
17451772

17461773
fn path_all(sp: Span,
17471774
global: bool,
1748-
mut idents: Vec<Ident>,
1775+
mut idents: Vec<hir::Ident>,
17491776
lifetimes: Vec<hir::Lifetime>,
17501777
types: Vec<P<hir::Ty>>,
17511778
bindings: Vec<P<hir::TypeBinding>>)
@@ -1774,12 +1801,12 @@ fn path_all(sp: Span,
17741801
}
17751802
}
17761803

1777-
fn std_path(lctx: &LoweringContext, components: &[&str]) -> Vec<Ident> {
1804+
fn std_path(lctx: &LoweringContext, components: &[&str]) -> Vec<hir::Ident> {
17781805
let mut v = Vec::new();
17791806
if let Some(s) = lctx.crate_root {
1780-
v.push(str_to_ident(s));
1807+
v.push(hir::Ident::from_name(token::intern(s)));
17811808
}
1782-
v.extend(components.iter().map(|s| str_to_ident(s)));
1809+
v.extend(components.iter().map(|s| hir::Ident::from_name(token::intern(s))));
17831810
return v;
17841811
}
17851812

‎src/librustc_front/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use hir;
1212
use hir::*;
1313
use intravisit::{self, Visitor, FnKind};
1414
use syntax::ast_util;
15-
use syntax::ast::{Ident, Name, NodeId, DUMMY_NODE_ID};
15+
use syntax::ast::{Name, NodeId, DUMMY_NODE_ID};
1616
use syntax::codemap::Span;
1717
use syntax::ptr::P;
1818
use syntax::owned_slice::OwnedSlice;

‎src/librustc_lint/builtin.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,7 @@ impl LateLintPass for NonShorthandFieldPatterns {
170170
});
171171
for fieldpat in field_pats {
172172
if let hir::PatIdent(_, ident, None) = fieldpat.node.pat.node {
173-
if ident.node.name == fieldpat.node.name {
174-
// FIXME: should this comparison really be done on the name?
175-
// doing it on the ident will fail during compilation of libcore
173+
if ident.node.unhygienic_name == fieldpat.node.name {
176174
cx.span_lint(NON_SHORTHAND_FIELD_PATTERNS, fieldpat.span,
177175
&format!("the `{}:` in this pattern is redundant and can \
178176
be removed", ident.node))

‎src/librustc_mir/hair/cx/expr.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use rustc::middle::ty::{self, VariantDef, Ty};
2121
use rustc::mir::repr::*;
2222
use rustc_front::hir;
2323
use rustc_front::util as hir_util;
24-
use syntax::ext::mtwt;
2524
use syntax::parse::token;
2625
use syntax::ptr::P;
2726

@@ -500,8 +499,8 @@ fn convert_arm<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>, arm: &'tcx hir::Arm) -> Arm<
500499
None
501500
} else {
502501
map = FnvHashMap();
503-
pat_util::pat_bindings_hygienic(&cx.tcx.def_map, &arm.pats[0], |_, p_id, _, path| {
504-
map.insert(mtwt::resolve(path.node), p_id);
502+
pat_util::pat_bindings(&cx.tcx.def_map, &arm.pats[0], |_, p_id, _, path| {
503+
map.insert(path.node, p_id);
505504
});
506505
Some(&map)
507506
};

‎src/librustc_mir/hair/cx/pattern.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use rustc::middle::ty::{self, Ty};
1919
use rustc::mir::repr::*;
2020
use rustc_front::hir;
2121
use syntax::ast;
22-
use syntax::ext::mtwt;
2322
use syntax::ptr::P;
2423

2524
/// When there are multiple patterns in a single arm, each one has its
@@ -162,7 +161,7 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, 'tcx> {
162161
{
163162
let id = match self.binding_map {
164163
None => pat.id,
165-
Some(ref map) => map[&mtwt::resolve(ident.node)],
164+
Some(ref map) => map[&ident.node.name],
166165
};
167166
let var_ty = self.cx.tcx.node_id_to_type(pat.id);
168167
let region = match var_ty.sty {

‎src/librustc_resolve/lib.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use rustc::lint;
5757
use rustc::middle::cstore::{CrateStore, DefLike, DlDef};
5858
use rustc::middle::def::*;
5959
use rustc::middle::def_id::DefId;
60-
use rustc::middle::pat_util::pat_bindings_hygienic;
60+
use rustc::middle::pat_util::pat_bindings;
6161
use rustc::middle::privacy::*;
6262
use rustc::middle::subst::{ParamSpace, FnSpace, TypeSpace};
6363
use rustc::middle::ty::{Freevar, FreevarMap, TraitMap, GlobMap};
@@ -67,7 +67,6 @@ use syntax::ast;
6767
use syntax::ast::{CRATE_NODE_ID, Ident, Name, NodeId, CrateNum, TyIs, TyI8, TyI16, TyI32, TyI64};
6868
use syntax::ast::{TyUs, TyU8, TyU16, TyU32, TyU64, TyF64, TyF32};
6969
use syntax::attr::AttrMetaMethods;
70-
use syntax::ext::mtwt;
7170
use syntax::parse::token::{self, special_names, special_idents};
7271
use syntax::ptr::P;
7372
use syntax::codemap::{self, Span, Pos};
@@ -2315,8 +2314,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
23152314
// user and one 'x' came from the macro.
23162315
fn binding_mode_map(&mut self, pat: &Pat) -> BindingMap {
23172316
let mut result = HashMap::new();
2318-
pat_bindings_hygienic(&self.def_map, pat, |binding_mode, _id, sp, path1| {
2319-
let name = mtwt::resolve(path1.node);
2317+
pat_bindings(&self.def_map, pat, |binding_mode, _id, sp, path1| {
2318+
let name = path1.node;
23202319
result.insert(name,
23212320
BindingInfo {
23222321
span: sp,
@@ -2520,9 +2519,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
25202519
let const_ok = mode == RefutableMode && at_rhs.is_none();
25212520

25222521
let ident = path1.node;
2523-
let renamed = mtwt::resolve(ident);
2522+
let renamed = ident.name;
25242523

2525-
match self.resolve_bare_identifier_pattern(ident.name, pattern.span) {
2524+
match self.resolve_bare_identifier_pattern(ident.unhygienic_name,
2525+
pattern.span) {
25262526
FoundStructOrEnumVariant(def, lp) if const_ok => {
25272527
debug!("(resolving pattern) resolving `{}` to struct or enum variant",
25282528
renamed);
@@ -2911,15 +2911,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
29112911

29122912
// Resolve a single identifier
29132913
fn resolve_identifier(&mut self,
2914-
identifier: Ident,
2914+
identifier: hir::Ident,
29152915
namespace: Namespace,
29162916
check_ribs: bool)
29172917
-> Option<LocalDef> {
29182918
// First, check to see whether the name is a primitive type.
29192919
if namespace == TypeNS {
29202920
if let Some(&prim_ty) = self.primitive_type_table
29212921
.primitive_types
2922-
.get(&identifier.name) {
2922+
.get(&identifier.unhygienic_name) {
29232923
return Some(LocalDef::from_def(DefPrimTy(prim_ty)));
29242924
}
29252925
}
@@ -2930,7 +2930,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
29302930
}
29312931
}
29322932

2933-
self.resolve_item_by_name_in_lexical_scope(identifier.name, namespace)
2933+
self.resolve_item_by_name_in_lexical_scope(identifier.unhygienic_name, namespace)
29342934
.map(LocalDef::from_def)
29352935
}
29362936

@@ -3144,13 +3144,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
31443144
}
31453145

31463146
fn resolve_identifier_in_local_ribs(&mut self,
3147-
ident: Ident,
3147+
ident: hir::Ident,
31483148
namespace: Namespace)
31493149
-> Option<LocalDef> {
31503150
// Check the local set of ribs.
31513151
let (name, ribs) = match namespace {
3152-
ValueNS => (mtwt::resolve(ident), &self.value_ribs),
3153-
TypeNS => (ident.name, &self.type_ribs),
3152+
ValueNS => (ident.name, &self.value_ribs),
3153+
TypeNS => (ident.unhygienic_name, &self.type_ribs),
31543154
};
31553155

31563156
for (i, rib) in ribs.iter().enumerate().rev() {
@@ -3551,17 +3551,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
35513551

35523552
{
35533553
let rib = this.label_ribs.last_mut().unwrap();
3554-
let renamed = mtwt::resolve(label);
3555-
rib.bindings.insert(renamed, def_like);
3554+
rib.bindings.insert(label.name, def_like);
35563555
}
35573556

35583557
intravisit::walk_expr(this, expr);
35593558
})
35603559
}
35613560

35623561
ExprBreak(Some(label)) | ExprAgain(Some(label)) => {
3563-
let renamed = mtwt::resolve(label.node);
3564-
match self.search_label(renamed) {
3562+
match self.search_label(label.node.name) {
35653563
None => {
35663564
resolve_error(self,
35673565
label.span,

‎src/librustc_trans/trans/_match.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ use std::fmt;
228228
use std::rc::Rc;
229229
use rustc_front::hir;
230230
use syntax::ast::{self, DUMMY_NODE_ID, NodeId};
231-
use syntax::ext::mtwt;
232231
use syntax::codemap::Span;
233232
use rustc_front::fold::Folder;
234233
use syntax::ptr::P;
@@ -478,7 +477,7 @@ fn expand_nested_bindings<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
478477
loop {
479478
pat = match pat.node {
480479
hir::PatIdent(_, ref path, Some(ref inner)) => {
481-
bound_ptrs.push((mtwt::resolve(path.node), val.val));
480+
bound_ptrs.push((path.node.name, val.val));
482481
&**inner
483482
},
484483
_ => break
@@ -519,15 +518,15 @@ fn enter_match<'a, 'b, 'p, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
519518
match this.node {
520519
hir::PatIdent(_, ref path, None) => {
521520
if pat_is_binding(&dm.borrow(), &*this) {
522-
bound_ptrs.push((mtwt::resolve(path.node), val.val));
521+
bound_ptrs.push((path.node.name, val.val));
523522
}
524523
}
525524
hir::PatVec(ref before, Some(ref slice), ref after) => {
526525
if let hir::PatIdent(_, ref path, None) = slice.node {
527526
let subslice_val = bind_subslice_pat(
528527
bcx, this.id, val,
529528
before.len(), after.len());
530-
bound_ptrs.push((mtwt::resolve(path.node), subslice_val));
529+
bound_ptrs.push((path.node.name, subslice_val));
531530
}
532531
}
533532
_ => {}
@@ -1527,8 +1526,8 @@ fn create_bindings_map<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, pat: &hir::Pat,
15271526
let tcx = bcx.tcx();
15281527
let reassigned = is_discr_reassigned(bcx, discr, body);
15291528
let mut bindings_map = FnvHashMap();
1530-
pat_bindings_hygienic(&tcx.def_map, &*pat, |bm, p_id, span, path1| {
1531-
let name = mtwt::resolve(path1.node);
1529+
pat_bindings(&tcx.def_map, &*pat, |bm, p_id, span, path1| {
1530+
let name = path1.node;
15321531
let variable_ty = node_id_type(bcx, p_id);
15331532
let llvariable_ty = type_of::type_of(ccx, variable_ty);
15341533
let tcx = bcx.tcx();

‎src/librustc_trans/trans/debuginfo/create_scope_map.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ pub fn create_scope_map(cx: &CrateContext,
4747
// Push argument identifiers onto the stack so arguments integrate nicely
4848
// with variable shadowing.
4949
for arg in args {
50-
pat_util::pat_bindings(def_map, &*arg.pat, |_, node_id, _, path1| {
50+
pat_util::pat_bindings_ident(def_map, &*arg.pat, |_, node_id, _, path1| {
5151
scope_stack.push(ScopeStackEntry { scope_metadata: fn_metadata,
52-
name: Some(path1.node) });
52+
name: Some(path1.node.unhygienic_name) });
5353
scope_map.insert(node_id, fn_metadata);
5454
})
5555
}
@@ -169,7 +169,7 @@ fn walk_pattern(cx: &CrateContext,
169169
// scope stack and maybe introduce an artificial scope
170170
if pat_util::pat_is_binding(&def_map.borrow(), &*pat) {
171171

172-
let name = path1.node.name;
172+
let name = path1.node.unhygienic_name;
173173

174174
// LLVM does not properly generate 'DW_AT_start_scope' fields
175175
// for variable DIEs. For this reason we have to introduce

‎src/librustc_typeck/check/_match.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use session::Session;
2626
use std::cmp;
2727
use std::collections::hash_map::Entry::{Occupied, Vacant};
2828
use syntax::ast;
29-
use syntax::ext::mtwt;
3029
use syntax::codemap::{Span, Spanned};
3130
use syntax::ptr::P;
3231

@@ -187,7 +186,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
187186

188187
// if there are multiple arms, make sure they all agree on
189188
// what the type of the binding `x` ought to be
190-
let canon_id = *pcx.map.get(&mtwt::resolve(path.node)).unwrap();
189+
let canon_id = *pcx.map.get(&path.node.name).unwrap();
191190
if canon_id != pat.id {
192191
let ct = fcx.local_ty(pat.span, canon_id);
193192
demand::eqtype(fcx, pat.span, ct, typ);

0 commit comments

Comments
 (0)
Please sign in to comment.