Use a span from the correct file for the inner span of a module
This basically only affects modules which are empty (or only contain comments). Closes #26755
This commit is contained in:
parent
bf34187a2f
commit
f47d20aecd
5 changed files with 29 additions and 13 deletions
|
@ -1947,6 +1947,10 @@ impl Span {
|
||||||
|
|
||||||
impl Clean<Span> for syntax::codemap::Span {
|
impl Clean<Span> for syntax::codemap::Span {
|
||||||
fn clean(&self, cx: &DocContext) -> Span {
|
fn clean(&self, cx: &DocContext) -> Span {
|
||||||
|
if *self == DUMMY_SP {
|
||||||
|
return Span::empty();
|
||||||
|
}
|
||||||
|
|
||||||
let cm = cx.sess().codemap();
|
let cm = cx.sess().codemap();
|
||||||
let filename = cm.span_to_filename(*self);
|
let filename = cm.span_to_filename(*self);
|
||||||
let lo = cm.lookup_char_pos(self.lo);
|
let lo = cm.lookup_char_pos(self.lo);
|
||||||
|
|
|
@ -894,7 +894,7 @@ impl CodeMap {
|
||||||
FileMapAndBytePos {fm: fm, pos: offset}
|
FileMapAndBytePos {fm: fm, pos: offset}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts an absolute BytePos to a CharPos relative to the filemap and above.
|
/// Converts an absolute BytePos to a CharPos relative to the filemap.
|
||||||
pub fn bytepos_to_file_charpos(&self, bpos: BytePos) -> CharPos {
|
pub fn bytepos_to_file_charpos(&self, bpos: BytePos) -> CharPos {
|
||||||
let idx = self.lookup_filemap_idx(bpos);
|
let idx = self.lookup_filemap_idx(bpos);
|
||||||
let files = self.files.borrow();
|
let files = self.files.borrow();
|
||||||
|
|
|
@ -231,6 +231,7 @@ impl<'a> StringReader<'a> {
|
||||||
None => {
|
None => {
|
||||||
if self.is_eof() {
|
if self.is_eof() {
|
||||||
self.peek_tok = token::Eof;
|
self.peek_tok = token::Eof;
|
||||||
|
self.peek_span = codemap::mk_sp(self.filemap.end_pos, self.filemap.end_pos);
|
||||||
} else {
|
} else {
|
||||||
let start_bytepos = self.last_pos;
|
let start_bytepos = self.last_pos;
|
||||||
self.peek_tok = self.next_token_inner();
|
self.peek_tok = self.next_token_inner();
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
//! The main parser interface
|
//! The main parser interface
|
||||||
|
|
||||||
use ast;
|
use ast;
|
||||||
use codemap::{Span, CodeMap, FileMap};
|
use codemap::{self, Span, CodeMap, FileMap};
|
||||||
use diagnostic::{SpanHandler, Handler, Auto, FatalError};
|
use diagnostic::{SpanHandler, Handler, Auto, FatalError};
|
||||||
use parse::attr::ParserAttr;
|
use parse::attr::ParserAttr;
|
||||||
use parse::parser::Parser;
|
use parse::parser::Parser;
|
||||||
|
@ -203,7 +203,14 @@ pub fn new_sub_parser_from_file<'a>(sess: &'a ParseSess,
|
||||||
pub fn filemap_to_parser<'a>(sess: &'a ParseSess,
|
pub fn filemap_to_parser<'a>(sess: &'a ParseSess,
|
||||||
filemap: Rc<FileMap>,
|
filemap: Rc<FileMap>,
|
||||||
cfg: ast::CrateConfig) -> Parser<'a> {
|
cfg: ast::CrateConfig) -> Parser<'a> {
|
||||||
tts_to_parser(sess, filemap_to_tts(sess, filemap), cfg)
|
let end_pos = filemap.end_pos;
|
||||||
|
let mut parser = tts_to_parser(sess, filemap_to_tts(sess, filemap), cfg);
|
||||||
|
|
||||||
|
if parser.token == token::Eof && parser.span == codemap::DUMMY_SP {
|
||||||
|
parser.span = codemap::mk_sp(end_pos, end_pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
parser
|
||||||
}
|
}
|
||||||
|
|
||||||
// must preserve old name for now, because quote! from the *existing*
|
// must preserve old name for now, because quote! from the *existing*
|
||||||
|
|
|
@ -4824,8 +4824,14 @@ impl<'a> Parser<'a> {
|
||||||
return Err(self.fatal(&format!("expected item, found `{}`", token_str)));
|
return Err(self.fatal(&format!("expected item, found `{}`", token_str)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let hi = if self.span == codemap::DUMMY_SP {
|
||||||
|
inner_lo
|
||||||
|
} else {
|
||||||
|
self.span.lo
|
||||||
|
};
|
||||||
|
|
||||||
Ok(ast::Mod {
|
Ok(ast::Mod {
|
||||||
inner: mk_sp(inner_lo, self.span.lo),
|
inner: mk_sp(inner_lo, hi),
|
||||||
items: items
|
items: items
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -4869,8 +4875,7 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
fn push_mod_path(&mut self, id: Ident, attrs: &[Attribute]) {
|
fn push_mod_path(&mut self, id: Ident, attrs: &[Attribute]) {
|
||||||
let default_path = self.id_to_interned_str(id);
|
let default_path = self.id_to_interned_str(id);
|
||||||
let file_path = match ::attr::first_attr_value_str_by_name(attrs,
|
let file_path = match ::attr::first_attr_value_str_by_name(attrs, "path") {
|
||||||
"path") {
|
|
||||||
Some(d) => d,
|
Some(d) => d,
|
||||||
None => default_path,
|
None => default_path,
|
||||||
};
|
};
|
||||||
|
@ -5003,8 +5008,7 @@ impl<'a> Parser<'a> {
|
||||||
included_mod_stack.push(path.clone());
|
included_mod_stack.push(path.clone());
|
||||||
drop(included_mod_stack);
|
drop(included_mod_stack);
|
||||||
|
|
||||||
let mut p0 =
|
let mut p0 = new_sub_parser_from_file(self.sess,
|
||||||
new_sub_parser_from_file(self.sess,
|
|
||||||
self.cfg.clone(),
|
self.cfg.clone(),
|
||||||
&path,
|
&path,
|
||||||
owns_directory,
|
owns_directory,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue