Retain trailing comments in module when using rustfmt::skip attribute

Resolves 5033

Trailing comments at the end of the root Module were removed because the
module span did not extend until the end of the file.

The root Module's span now encompasses the entire file, which ensures
that no comments are lost when using ``#![rustfmt::skip]``
This commit is contained in:
Yacin Tmimi 2021-10-19 01:14:51 -04:00 committed by Caleb Cartwright
parent 8b766f35bc
commit bc46af9742
3 changed files with 23 additions and 2 deletions

View File

@ -16,7 +16,7 @@ use crate::syntux::parser::{
Directory, DirectoryOwnership, ModError, ModulePathSuccess, Parser, ParserError,
};
use crate::syntux::session::ParseSess;
use crate::utils::contains_skip;
use crate::utils::{contains_skip, mk_sp};
mod visitor;
@ -135,10 +135,12 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
self.visit_mod_from_ast(&krate.items)?;
}
let snippet_provider = self.parse_sess.snippet_provider(krate.span);
self.file_map.insert(
root_filename,
Module::new(
krate.span,
mk_sp(snippet_provider.start_pos(), snippet_provider.end_pos()),
None,
Cow::Borrowed(&krate.items),
Cow::Borrowed(&krate.attrs),

View File

@ -0,0 +1,8 @@
// leading comment
#![rustfmt::skip]
fn main() {
println!("main"); // commented
}
// post comment

View File

@ -0,0 +1,11 @@
#![rustfmt::skip]
mod a {
mod b {
}
// trailing comment b
}
// trailing comment a