mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-12 20:16:49 +00:00
Fixes #1184 where reordering import items could cause a panic.
Also extends an existing test to avoid regression.
This commit is contained in:
parent
8494d5f89c
commit
f933d31115
@ -158,7 +158,10 @@ impl<'a> FmtVisitor<'a> {
|
||||
// Find the location immediately before the first use item in the run. This must not lie
|
||||
// before the current `self.last_pos`
|
||||
let pos_before_first_use_item = use_items.first()
|
||||
.map(|p_i| cmp::max(self.last_pos, p_i.span.lo))
|
||||
.map(|p_i| {
|
||||
cmp::max(self.last_pos,
|
||||
p_i.attrs.iter().map(|attr| attr.span.lo).min().unwrap_or(p_i.span.lo))
|
||||
})
|
||||
.unwrap_or(self.last_pos);
|
||||
// Construct a list of pairs, each containing a `use` item and the start of span before
|
||||
// that `use` item.
|
||||
|
@ -1,6 +1,7 @@
|
||||
// rustfmt-reorder_imports: true
|
||||
// rustfmt-reorder_imported_names: true
|
||||
|
||||
/// This comment should stay with `use std::str;`
|
||||
use std::str;
|
||||
use std::cmp::{d, c, b, a};
|
||||
use std::ddd::aaa;
|
||||
|
@ -6,4 +6,5 @@ use std::ddd::{a, b, c as g, d as p};
|
||||
use std::ddd::aaa;
|
||||
// This comment should stay with `use std::ddd:bbb;`
|
||||
use std::ddd::bbb;
|
||||
/// This comment should stay with `use std::str;`
|
||||
use std::str;
|
||||
|
Loading…
Reference in New Issue
Block a user