Merge pull request #1841 from emilio/file-lines-fixes
visitor: A few file lines fixes
This commit is contained in:
commit
b9e5afd62e
@ -343,6 +343,7 @@ macro_rules! skip_out_of_file_lines_range {
|
||||
macro_rules! skip_out_of_file_lines_range_visitor {
|
||||
($self:ident, $span:expr) => {
|
||||
if out_of_file_lines_range!($self, $span) {
|
||||
$self.push_rewrite($span, None);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -661,7 +661,19 @@ impl<'a> FmtVisitor<'a> {
|
||||
})
|
||||
.count();
|
||||
let (use_items, rest) = items_left.split_at(use_item_length);
|
||||
self.format_imports(use_items);
|
||||
|
||||
let at_least_one_in_file_lines = use_items
|
||||
.iter()
|
||||
.any(|item| !out_of_file_lines_range!(self, item.span));
|
||||
|
||||
if at_least_one_in_file_lines {
|
||||
self.format_imports(use_items);
|
||||
} else {
|
||||
for item in use_items {
|
||||
self.push_rewrite(item.span, None);
|
||||
}
|
||||
}
|
||||
|
||||
items_left = rest;
|
||||
} else {
|
||||
// `unwrap()` is safe here because we know `items_left`
|
||||
|
@ -1,6 +1,8 @@
|
||||
// rustfmt-file_lines: [{"file":"tests/source/file-lines-item.rs","range":[5,7]}]
|
||||
// rustfmt-file_lines: [{"file":"tests/source/file-lines-item.rs","range":[7,9]}]
|
||||
// rustfmt-reorder_imports: true
|
||||
|
||||
use foo::{c, b, a};
|
||||
use bar;
|
||||
|
||||
fn foo() {
|
||||
bar ( ) ;
|
||||
@ -10,3 +12,11 @@ impl Drop for Context {
|
||||
fn drop(&mut self) {
|
||||
}
|
||||
}
|
||||
|
||||
impl Bar for Baz {
|
||||
fn foo() {
|
||||
bar(
|
||||
baz, // Who knows?
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
// rustfmt-file_lines: [{"file":"tests/source/file-lines-item.rs","range":[5,7]}]
|
||||
// rustfmt-file_lines: [{"file":"tests/source/file-lines-item.rs","range":[7,9]}]
|
||||
// rustfmt-reorder_imports: true
|
||||
|
||||
use foo::{c, b, a};
|
||||
use bar;
|
||||
|
||||
fn foo() {
|
||||
bar();
|
||||
@ -10,3 +12,11 @@ impl Drop for Context {
|
||||
fn drop(&mut self) {
|
||||
}
|
||||
}
|
||||
|
||||
impl Bar for Baz {
|
||||
fn foo() {
|
||||
bar(
|
||||
baz, // Who knows?
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user