fix TrailingWhitespace when using line breaks in macros arguments (#3768)
This commit is contained in:
parent
ad5d9fba9b
commit
2bf67b6e5c
@ -188,7 +188,7 @@ fn format_file(
|
||||
format_lines(
|
||||
&mut visitor.buffer,
|
||||
&path,
|
||||
&visitor.skipped_range,
|
||||
&visitor.skipped_range.borrow(),
|
||||
&self.config,
|
||||
&self.report,
|
||||
);
|
||||
@ -203,7 +203,7 @@ fn format_file(
|
||||
self.report.add_macro_format_failure();
|
||||
}
|
||||
self.report
|
||||
.add_non_formatted_ranges(visitor.skipped_range.clone());
|
||||
.add_non_formatted_ranges(visitor.skipped_range.borrow().clone());
|
||||
|
||||
self.handler.handle_formatted_file(
|
||||
self.parse_session.source_map(),
|
||||
|
@ -181,6 +181,11 @@ fn return_macro_parse_failure_fallback(
|
||||
return trim_left_preserve_layout(context.snippet(span), indent, &context.config);
|
||||
}
|
||||
|
||||
context.skipped_range.borrow_mut().push((
|
||||
context.source_map.lookup_line(span.lo()).unwrap().line,
|
||||
context.source_map.lookup_line(span.hi()).unwrap().line,
|
||||
));
|
||||
|
||||
// Return the snippet unmodified if the macro is not block-like
|
||||
Some(context.snippet(span).to_owned())
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
// A generic trait to abstract the rewriting of an element (of the AST).
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
use syntax::parse::ParseSess;
|
||||
use syntax::ptr;
|
||||
@ -41,6 +42,7 @@ pub(crate) struct RewriteContext<'a> {
|
||||
pub(crate) macro_rewrite_failure: RefCell<bool>,
|
||||
pub(crate) report: FormatReport,
|
||||
pub(crate) skip_context: SkipContext,
|
||||
pub(crate) skipped_range: Rc<RefCell<Vec<(usize, usize)>>>,
|
||||
}
|
||||
|
||||
impl<'a> RewriteContext<'a> {
|
||||
|
@ -1,4 +1,5 @@
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
use syntax::parse::ParseSess;
|
||||
use syntax::source_map::{self, BytePos, Pos, SourceMap, Span};
|
||||
@ -65,7 +66,7 @@ pub(crate) struct FmtVisitor<'a> {
|
||||
pub(crate) line_number: usize,
|
||||
/// List of 1-based line ranges which were annotated with skip
|
||||
/// Both bounds are inclusifs.
|
||||
pub(crate) skipped_range: Vec<(usize, usize)>,
|
||||
pub(crate) skipped_range: Rc<RefCell<Vec<(usize, usize)>>>,
|
||||
pub(crate) macro_rewrite_failure: bool,
|
||||
pub(crate) report: FormatReport,
|
||||
pub(crate) skip_context: SkipContext,
|
||||
@ -652,7 +653,7 @@ pub(crate) fn push_skipped_with_span(
|
||||
let lo = std::cmp::min(attrs_end + 1, first_line);
|
||||
self.push_rewrite_inner(item_span, None);
|
||||
let hi = self.line_number + 1;
|
||||
self.skipped_range.push((lo, hi));
|
||||
self.skipped_range.borrow_mut().push((lo, hi));
|
||||
}
|
||||
|
||||
pub(crate) fn from_context(ctx: &'a RewriteContext<'_>) -> FmtVisitor<'a> {
|
||||
@ -684,7 +685,7 @@ pub(crate) fn from_source_map(
|
||||
is_if_else_block: false,
|
||||
snippet_provider,
|
||||
line_number: 0,
|
||||
skipped_range: vec![],
|
||||
skipped_range: Rc::new(RefCell::new(vec![])),
|
||||
macro_rewrite_failure: false,
|
||||
report,
|
||||
skip_context: Default::default(),
|
||||
@ -877,6 +878,7 @@ pub(crate) fn get_context(&self) -> RewriteContext<'_> {
|
||||
macro_rewrite_failure: RefCell::new(false),
|
||||
report: self.report.clone(),
|
||||
skip_context: self.skip_context.clone(),
|
||||
skipped_range: self.skipped_range.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
2
tests/target/issue-2916.rs
Normal file
2
tests/target/issue-2916.rs
Normal file
@ -0,0 +1,2 @@
|
||||
a_macro!(name<Param1, Param2>,
|
||||
);
|
Loading…
Reference in New Issue
Block a user