Skip to content

Commit 351a5fd

Browse files
committed
added unit and standalone test for 15221, extra debugging output
1 parent e100d26 commit 351a5fd

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

src/libsyntax/ext/expand.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ pub fn expand_expr(e: Gc<ast::Expr>, fld: &mut MacroExpander) -> Gc<ast::Expr> {
5454
}
5555
let extname = pth.segments.get(0).identifier;
5656
let extnamestr = token::get_ident(extname);
57-
// leaving explicit deref here to highlight unbox op:
5857
let marked_after = match fld.extsbox.find(&extname.name) {
5958
None => {
6059
fld.cx.span_err(
@@ -1294,6 +1293,19 @@ mod test {
12941293
0)
12951294
}
12961295

1296+
// FIXME #15221, somehow pats aren't getting labeled correctly?
1297+
// should expand into
1298+
// fn main(){let g1_1 = 13; g1_1}}
1299+
#[test] fn pat_expand_issue_15221(){
1300+
run_renaming_test(
1301+
&("macro_rules! inner ( ($e:pat ) => ($e))
1302+
macro_rules! outer ( ($e:pat ) => (inner!($e)))
1303+
fn main() { let outer!(g) = 13; g;}",
1304+
vec!(vec!(0)),
1305+
true),
1306+
0)
1307+
}
1308+
12971309
// create a really evil test case where a $x appears inside a binding of $x
12981310
// but *shouldnt* bind because it was inserted by a different macro....
12991311
// can't write this test case until we have macro-generating macros.
@@ -1343,9 +1355,13 @@ mod test {
13431355
.ctxt,
13441356
invalid_name);
13451357
if !(varref_name==binding_name) {
1358+
let varref_idents : Vec<ast::Ident>
1359+
= varref.segments.iter().map(|s|
1360+
s.identifier)
1361+
.collect();
13461362
println!("uh oh, should match but doesn't:");
1347-
println!("varref #{:?}: {:?}",idx, varref);
1348-
println!("binding #{:?}: {:?}", binding_idx, *bindings.get(binding_idx));
1363+
println!("varref #{}: {}",idx, varref_idents);
1364+
println!("binding #{}: {}", binding_idx, *bindings.get(binding_idx));
13491365
mtwt::with_sctable(|x| mtwt::display_sctable(x));
13501366
}
13511367
assert_eq!(varref_name,binding_name);
@@ -1360,19 +1376,23 @@ mod test {
13601376
== binding_name);
13611377
// temp debugging:
13621378
if fail {
1379+
let varref_idents : Vec<ast::Ident>
1380+
= varref.segments.iter().map(|s|
1381+
s.identifier)
1382+
.collect();
13631383
println!("failure on test {}",test_idx);
13641384
println!("text of test case: \"{}\"", teststr);
13651385
println!("");
13661386
println!("uh oh, matches but shouldn't:");
1367-
println!("varref: {:?}",varref);
1387+
println!("varref: {}",varref_idents);
13681388
// good lord, you can't make a path with 0 segments, can you?
13691389
let string = token::get_ident(varref.segments
13701390
.get(0)
13711391
.identifier);
13721392
println!("varref's first segment's uint: {}, and string: \"{}\"",
13731393
varref.segments.get(0).identifier.name,
13741394
string.get());
1375-
println!("binding: {:?}", *bindings.get(binding_idx));
1395+
println!("binding: {}", *bindings.get(binding_idx));
13761396
mtwt::with_sctable(|x| mtwt::display_sctable(x));
13771397
}
13781398
assert!(!fail);
@@ -1442,5 +1462,6 @@ foo_module!()
14421462
assert_eq!(idents, strs_to_idents(vec!("a","b","None","i","i","z","y")));
14431463
}
14441464

1465+
//
14451466

14461467
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2014 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+
#![feature(macro_rules)]
12+
13+
macro_rules! inner_bind (
14+
( $p:pat, $id:ident) => ({let $p = 13; $id}))
15+
16+
macro_rules! outer_bind (
17+
($p:pat, $id:ident ) => (inner_bind!($p, $id)))
18+
19+
fn main() {
20+
outer_bind!(g1,g1);
21+
}
22+

0 commit comments

Comments
 (0)