提交 351a5fd2 编写于 作者: J John Clements

added unit and standalone test for 15221, extra debugging output

上级 e100d26d
......@@ -54,7 +54,6 @@ pub fn expand_expr(e: Gc<ast::Expr>, fld: &mut MacroExpander) -> Gc<ast::Expr> {
}
let extname = pth.segments.get(0).identifier;
let extnamestr = token::get_ident(extname);
// leaving explicit deref here to highlight unbox op:
let marked_after = match fld.extsbox.find(&extname.name) {
None => {
fld.cx.span_err(
......@@ -1294,6 +1293,19 @@ fn z() {match 8 {x => bad_macro!(x)}}",
0)
}
// FIXME #15221, somehow pats aren't getting labeled correctly?
// should expand into
// fn main(){let g1_1 = 13; g1_1}}
#[test] fn pat_expand_issue_15221(){
run_renaming_test(
&("macro_rules! inner ( ($e:pat ) => ($e))
macro_rules! outer ( ($e:pat ) => (inner!($e)))
fn main() { let outer!(g) = 13; g;}",
vec!(vec!(0)),
true),
0)
}
// create a really evil test case where a $x appears inside a binding of $x
// but *shouldnt* bind because it was inserted by a different macro....
// can't write this test case until we have macro-generating macros.
......@@ -1343,9 +1355,13 @@ fn run_renaming_test(t: &RenamingTest, test_idx: uint) {
.ctxt,
invalid_name);
if !(varref_name==binding_name) {
let varref_idents : Vec<ast::Ident>
= varref.segments.iter().map(|s|
s.identifier)
.collect();
println!("uh oh, should match but doesn't:");
println!("varref #{:?}: {:?}",idx, varref);
println!("binding #{:?}: {:?}", binding_idx, *bindings.get(binding_idx));
println!("varref #{}: {}",idx, varref_idents);
println!("binding #{}: {}", binding_idx, *bindings.get(binding_idx));
mtwt::with_sctable(|x| mtwt::display_sctable(x));
}
assert_eq!(varref_name,binding_name);
......@@ -1360,11 +1376,15 @@ fn run_renaming_test(t: &RenamingTest, test_idx: uint) {
== binding_name);
// temp debugging:
if fail {
let varref_idents : Vec<ast::Ident>
= varref.segments.iter().map(|s|
s.identifier)
.collect();
println!("failure on test {}",test_idx);
println!("text of test case: \"{}\"", teststr);
println!("");
println!("uh oh, matches but shouldn't:");
println!("varref: {:?}",varref);
println!("varref: {}",varref_idents);
// good lord, you can't make a path with 0 segments, can you?
let string = token::get_ident(varref.segments
.get(0)
......@@ -1372,7 +1392,7 @@ fn run_renaming_test(t: &RenamingTest, test_idx: uint) {
println!("varref's first segment's uint: {}, and string: \"{}\"",
varref.segments.get(0).identifier.name,
string.get());
println!("binding: {:?}", *bindings.get(binding_idx));
println!("binding: {}", *bindings.get(binding_idx));
mtwt::with_sctable(|x| mtwt::display_sctable(x));
}
assert!(!fail);
......@@ -1442,5 +1462,6 @@ fn crate_idents(){
assert_eq!(idents, strs_to_idents(vec!("a","b","None","i","i","z","y")));
}
//
}
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(macro_rules)]
macro_rules! inner_bind (
( $p:pat, $id:ident) => ({let $p = 13; $id}))
macro_rules! outer_bind (
($p:pat, $id:ident ) => (inner_bind!($p, $id)))
fn main() {
outer_bind!(g1,g1);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册