Skip to content

Commit cccc088

Browse files
committed
Add filename to Parser
1 parent b9e61c9 commit cccc088

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/libsyntax/parse/parser.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ pub struct Parser<'a> {
273273
/// extra detail when the same error is seen twice
274274
pub obsolete_set: HashSet<ObsoleteSyntax>,
275275
/// Used to determine the path to externally loaded source files
276+
pub filename: Option<String>,
276277
pub mod_path_stack: Vec<InternedString>,
277278
/// Stack of spans of open delimiters. Used for error message.
278279
pub open_braces: Vec<Span>,
@@ -354,6 +355,9 @@ impl<'a> Parser<'a> {
354355
{
355356
let tok0 = rdr.real_token();
356357
let span = tok0.sp;
358+
let filename = if span != codemap::DUMMY_SP {
359+
Some(sess.codemap().span_to_filename(span))
360+
} else { None };
357361
let placeholder = TokenAndSpan {
358362
tok: token::Underscore,
359363
sp: span,
@@ -382,6 +386,7 @@ impl<'a> Parser<'a> {
382386
quote_depth: 0,
383387
obsolete_set: HashSet::new(),
384388
mod_path_stack: Vec::new(),
389+
filename: filename,
385390
open_braces: Vec::new(),
386391
owns_directory: true,
387392
root_module_name: None,
@@ -5325,7 +5330,7 @@ impl<'a> Parser<'a> {
53255330
id: ast::Ident,
53265331
outer_attrs: &[ast::Attribute],
53275332
id_sp: Span) -> PResult<'a, ModulePathSuccess> {
5328-
let mut prefix = PathBuf::from(&self.sess.codemap().span_to_filename(self.span));
5333+
let mut prefix = PathBuf::from(self.filename.as_ref().unwrap());
53295334
prefix.pop();
53305335
let mut dir_path = prefix;
53315336
for part in &self.mod_path_stack {

0 commit comments

Comments
 (0)