mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-01 10:25:41 +00:00
rollup merge of #21825: kmcallister/ttdelim-span
This commit is contained in:
commit
075588a493
@ -755,6 +755,7 @@ mod test {
|
|||||||
use ast;
|
use ast;
|
||||||
use abi;
|
use abi;
|
||||||
use attr::{first_attr_value_str_by_name, AttrMetaMethods};
|
use attr::{first_attr_value_str_by_name, AttrMetaMethods};
|
||||||
|
use parse;
|
||||||
use parse::parser::Parser;
|
use parse::parser::Parser;
|
||||||
use parse::token::{str_to_ident};
|
use parse::token::{str_to_ident};
|
||||||
use print::pprust::item_to_string;
|
use print::pprust::item_to_string;
|
||||||
@ -1214,4 +1215,26 @@ mod test {
|
|||||||
let doc = first_attr_value_str_by_name(item.attrs.as_slice(), "doc").unwrap();
|
let doc = first_attr_value_str_by_name(item.attrs.as_slice(), "doc").unwrap();
|
||||||
assert_eq!(doc.get(), "/** doc comment\n * with CRLF */");
|
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"),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2742,7 +2742,7 @@ impl<'a> Parser<'a> {
|
|||||||
self.open_braces.pop().unwrap();
|
self.open_braces.pop().unwrap();
|
||||||
|
|
||||||
// Expand to cover the entire delimited token tree
|
// 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 {
|
TtDelimited(span, Rc::new(Delimited {
|
||||||
delim: delim,
|
delim: delim,
|
||||||
|
Loading…
Reference in New Issue
Block a user