Skip to content

Fix end of TtDelimited span #21825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/libsyntax/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,7 @@ mod test {
use ast;
use abi;
use attr::{first_attr_value_str_by_name, AttrMetaMethods};
use parse;
use parse::parser::Parser;
use parse::token::{str_to_ident};
use print::pprust::item_to_string;
Expand Down Expand Up @@ -1214,4 +1215,26 @@ mod test {
let doc = first_attr_value_str_by_name(item.attrs.as_slice(), "doc").unwrap();
assert_eq!(doc.get(), "/** doc comment\n * with CRLF */");
}

#[test]
fn ttdelim_span() {
let sess = parse::new_parse_sess();
let expr = parse::parse_expr_from_source_str("foo".to_string(),
"foo!( fn main() { body } )".to_string(), vec![], &sess);

let tts = match expr.node {
ast::ExprMac(ref mac) => {
let ast::MacInvocTT(_, ref tts, _) = mac.node;
tts.clone()
}
_ => panic!("not a macro"),
};

let span = tts.iter().rev().next().unwrap().get_span();

match sess.span_diagnostic.cm.span_to_snippet(span) {
Some(s) => assert_eq!(&s[], "{ body }"),
None => panic!("could not get snippet"),
}
}
}
2 changes: 1 addition & 1 deletion src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2735,7 +2735,7 @@ impl<'a> Parser<'a> {
self.open_braces.pop().unwrap();

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

TtDelimited(span, Rc::new(Delimited {
delim: delim,
Expand Down