Skip to content

Commit cc30948

Browse files
committed
Auto merge of #29748 - petrochenkov:issue29746, r=nrc
Closes #29746
2 parents b8eaa16 + fba1926 commit cc30948

File tree

7 files changed

+65
-14
lines changed

7 files changed

+65
-14
lines changed

src/librustc/middle/pat_util.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use middle::ty;
1414
use util::nodemap::FnvHashMap;
1515

1616
use syntax::ast;
17+
use syntax::ext::mtwt;
1718
use rustc_front::hir;
1819
use rustc_front::util::walk_pat;
1920
use syntax::codemap::{respan, Span, Spanned, DUMMY_SP};
@@ -26,8 +27,8 @@ pub type PatIdMap = FnvHashMap<ast::Name, ast::NodeId>;
2627
// use the NodeId of their namesake in the first pattern.
2728
pub fn pat_id_map(dm: &RefCell<DefMap>, pat: &hir::Pat) -> PatIdMap {
2829
let mut map = FnvHashMap();
29-
pat_bindings(dm, pat, |_bm, p_id, _s, path1| {
30-
map.insert(path1.node, p_id);
30+
pat_bindings_hygienic(dm, pat, |_bm, p_id, _s, path1| {
31+
map.insert(mtwt::resolve(path1.node), p_id);
3132
});
3233
map
3334
}

src/librustc_driver/driver.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -678,8 +678,9 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
678678
|| resolve::resolve_crate(sess, &ast_map, make_glob_map));
679679

680680
// Discard MTWT tables that aren't required past resolution.
681+
// FIXME: get rid of uses of MTWT tables in typeck, mir and trans and clear them
681682
if !sess.opts.debugging_opts.keep_mtwt_tables {
682-
syntax::ext::mtwt::clear_tables();
683+
// syntax::ext::mtwt::clear_tables();
683684
}
684685

685686
let named_region_map = time(time_passes,

src/librustc_mir/hair/cx/expr.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use rustc::middle::pat_util;
2222
use rustc::middle::ty::{self, VariantDef, Ty};
2323
use rustc_front::hir;
2424
use rustc_front::util as hir_util;
25+
use syntax::ext::mtwt;
2526
use syntax::parse::token;
2627
use syntax::ptr::P;
2728

@@ -490,8 +491,8 @@ fn convert_arm<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>, arm: &'tcx hir::Arm) -> Arm<
490491
None
491492
} else {
492493
map = FnvHashMap();
493-
pat_util::pat_bindings(&cx.tcx.def_map, &arm.pats[0], |_, p_id, _, path| {
494-
map.insert(path.node, p_id);
494+
pat_util::pat_bindings_hygienic(&cx.tcx.def_map, &arm.pats[0], |_, p_id, _, path| {
495+
map.insert(mtwt::resolve(path.node), p_id);
495496
});
496497
Some(&map)
497498
};

src/librustc_mir/hair/cx/pattern.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use rustc::middle::subst::Substs;
1919
use rustc::middle::ty::{self, Ty};
2020
use rustc_front::hir;
2121
use syntax::ast;
22+
use syntax::ext::mtwt;
2223
use syntax::ptr::P;
2324

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

src/librustc_trans/trans/_match.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ 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;
231232
use syntax::codemap::Span;
232233
use rustc_front::fold::Folder;
233234
use syntax::ptr::P;
@@ -477,7 +478,7 @@ fn expand_nested_bindings<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
477478
loop {
478479
pat = match pat.node {
479480
hir::PatIdent(_, ref path, Some(ref inner)) => {
480-
bound_ptrs.push((path.node.name, val.val));
481+
bound_ptrs.push((mtwt::resolve(path.node), val.val));
481482
&**inner
482483
},
483484
_ => break
@@ -518,15 +519,15 @@ fn enter_match<'a, 'b, 'p, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
518519
match this.node {
519520
hir::PatIdent(_, ref path, None) => {
520521
if pat_is_binding(&dm.borrow(), &*this) {
521-
bound_ptrs.push((path.node.name, val.val));
522+
bound_ptrs.push((mtwt::resolve(path.node), val.val));
522523
}
523524
}
524525
hir::PatVec(ref before, Some(ref slice), ref after) => {
525526
if let hir::PatIdent(_, ref path, None) = slice.node {
526527
let subslice_val = bind_subslice_pat(
527528
bcx, this.id, val,
528529
before.len(), after.len());
529-
bound_ptrs.push((path.node.name, subslice_val));
530+
bound_ptrs.push((mtwt::resolve(path.node), subslice_val));
530531
}
531532
}
532533
_ => {}
@@ -1127,8 +1128,8 @@ fn compile_submatch<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
11271128
}
11281129
None => {
11291130
let data = &m[0].data;
1130-
for &(ref ident, ref value_ptr) in &m[0].bound_ptrs {
1131-
let binfo = *data.bindings_map.get(ident).unwrap();
1131+
for &(ref name, ref value_ptr) in &m[0].bound_ptrs {
1132+
let binfo = *data.bindings_map.get(name).unwrap();
11321133
call_lifetime_start(bcx, binfo.llmatch);
11331134
if binfo.trmode == TrByRef && type_is_fat_ptr(bcx.tcx(), binfo.ty) {
11341135
expr::copy_fat_ptr(bcx, *value_ptr, binfo.llmatch);
@@ -1526,8 +1527,8 @@ fn create_bindings_map<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, pat: &hir::Pat,
15261527
let tcx = bcx.tcx();
15271528
let reassigned = is_discr_reassigned(bcx, discr, body);
15281529
let mut bindings_map = FnvHashMap();
1529-
pat_bindings(&tcx.def_map, &*pat, |bm, p_id, span, path1| {
1530-
let name = path1.node;
1530+
pat_bindings_hygienic(&tcx.def_map, &*pat, |bm, p_id, span, path1| {
1531+
let name = mtwt::resolve(path1.node);
15311532
let variable_ty = node_id_type(bcx, p_id);
15321533
let llvariable_ty = type_of::type_of(ccx, variable_ty);
15331534
let tcx = bcx.tcx();

src/librustc_typeck/check/_match.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use util::nodemap::FnvHashMap;
2525
use std::cmp;
2626
use std::collections::hash_map::Entry::{Occupied, Vacant};
2727
use syntax::ast;
28+
use syntax::ext::mtwt;
2829
use syntax::codemap::{Span, Spanned};
2930
use syntax::ptr::P;
3031

@@ -179,7 +180,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
179180

180181
// if there are multiple arms, make sure they all agree on
181182
// what the type of the binding `x` ought to be
182-
let canon_id = *pcx.map.get(&path.node.name).unwrap();
183+
let canon_id = *pcx.map.get(&mtwt::resolve(path.node)).unwrap();
183184
if canon_id != pat.id {
184185
let ct = fcx.local_ty(pat.span, canon_id);
185186
demand::eqtype(fcx, pat.span, ct, typ);

src/test/run-pass/issue-29746.rs

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// zip!(a1,a2,a3,a4) is equivalent to:
12+
// a1.zip(a2).zip(a3).zip(a4).map(|(((x1,x2),x3),x4)| (x1,x2,x3,x4))
13+
macro_rules! zip {
14+
// Entry point
15+
([$a:expr, $b:expr, $($rest:expr),*]) => {
16+
zip!([$($rest),*], $a.zip($b), (x,y), [x,y])
17+
};
18+
19+
// Intermediate steps to build the zipped expression, the match pattern, and
20+
// and the output tuple of the closure, using macro hygene to repeatedly
21+
// introduce new variables named 'x'.
22+
([$a:expr, $($rest:expr),*], $zip:expr, $pat:pat, [$($flat:expr),*]) => {
23+
zip!([$($rest),*], $zip.zip($a), ($pat,x), [$($flat),*, x])
24+
};
25+
26+
// Final step
27+
([], $zip:expr, $pat:pat, [$($flat:expr),+]) => {
28+
$zip.map(|$pat| ($($flat),+))
29+
};
30+
31+
// Comma
32+
([$a:expr], $zip:expr, $pat:pat, [$($flat:expr),*]) => {
33+
zip!([$a,], $zip, $pat, [$($flat),*])
34+
};
35+
}
36+
37+
fn main() {
38+
let p1 = vec![1i32, 2].into_iter();
39+
let p2 = vec!["10", "20"].into_iter();
40+
let p3 = vec![100u16, 200].into_iter();
41+
let p4 = vec![1000i64, 2000].into_iter();
42+
43+
let e = zip!([p1,p2,p3,p4]).collect::<Vec<_>>();
44+
assert_eq!(e[0], (1i32,"10",100u16,1000i64));
45+
}

0 commit comments

Comments
 (0)