Skip to content

Commit ec79e4b

Browse files
committed
Rollup merge of #21825 - kmcallister:ttdelim-span, r=sanxiyn
2 parents d5593ef + cedc675 commit ec79e4b

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/libsyntax/parse/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@ mod test {
755755
use ast;
756756
use abi;
757757
use attr::{first_attr_value_str_by_name, AttrMetaMethods};
758+
use parse;
758759
use parse::parser::Parser;
759760
use parse::token::{str_to_ident};
760761
use print::pprust::item_to_string;
@@ -1214,4 +1215,26 @@ mod test {
12141215
let doc = first_attr_value_str_by_name(item.attrs.as_slice(), "doc").unwrap();
12151216
assert_eq!(doc.get(), "/** doc comment\n * with CRLF */");
12161217
}
1218+
1219+
#[test]
1220+
fn ttdelim_span() {
1221+
let sess = parse::new_parse_sess();
1222+
let expr = parse::parse_expr_from_source_str("foo".to_string(),
1223+
"foo!( fn main() { body } )".to_string(), vec![], &sess);
1224+
1225+
let tts = match expr.node {
1226+
ast::ExprMac(ref mac) => {
1227+
let ast::MacInvocTT(_, ref tts, _) = mac.node;
1228+
tts.clone()
1229+
}
1230+
_ => panic!("not a macro"),
1231+
};
1232+
1233+
let span = tts.iter().rev().next().unwrap().get_span();
1234+
1235+
match sess.span_diagnostic.cm.span_to_snippet(span) {
1236+
Some(s) => assert_eq!(&s[], "{ body }"),
1237+
None => panic!("could not get snippet"),
1238+
}
1239+
}
12171240
}

src/libsyntax/parse/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2735,7 +2735,7 @@ impl<'a> Parser<'a> {
27352735
self.open_braces.pop().unwrap();
27362736

27372737
// Expand to cover the entire delimited token tree
2738-
let span = Span { hi: self.span.hi, ..pre_span };
2738+
let span = Span { hi: close_span.hi, ..pre_span };
27392739

27402740
TtDelimited(span, Rc::new(Delimited {
27412741
delim: delim,

0 commit comments

Comments
 (0)