mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 19:17:43 +00:00
Merge pull request #1207 from Fraser999/master
Fixes #1184 where reordering import items could cause a panic.
This commit is contained in:
commit
664f646979
@ -275,14 +275,14 @@ enum CharClassesStatus {
|
|||||||
LineComment,
|
LineComment,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Distinguish between functionnal part of code and comments
|
/// Distinguish between functional part of code and comments
|
||||||
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
|
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
|
||||||
pub enum CodeCharKind {
|
pub enum CodeCharKind {
|
||||||
Normal,
|
Normal,
|
||||||
Comment,
|
Comment,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Distinguish between functionnal part of code and comments,
|
/// Distinguish between functional part of code and comments,
|
||||||
/// describing opening and closing of comments for ease when chunking
|
/// describing opening and closing of comments for ease when chunking
|
||||||
/// code from tagged characters
|
/// code from tagged characters
|
||||||
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
|
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
|
||||||
|
@ -158,7 +158,10 @@ impl<'a> FmtVisitor<'a> {
|
|||||||
// Find the location immediately before the first use item in the run. This must not lie
|
// Find the location immediately before the first use item in the run. This must not lie
|
||||||
// before the current `self.last_pos`
|
// before the current `self.last_pos`
|
||||||
let pos_before_first_use_item = use_items.first()
|
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);
|
.unwrap_or(self.last_pos);
|
||||||
// Construct a list of pairs, each containing a `use` item and the start of span before
|
// Construct a list of pairs, each containing a `use` item and the start of span before
|
||||||
// that `use` item.
|
// that `use` item.
|
||||||
|
@ -179,7 +179,7 @@ impl<'a> FmtVisitor<'a> {
|
|||||||
pub fn visit_item(&mut self, item: &ast::Item) {
|
pub fn visit_item(&mut self, item: &ast::Item) {
|
||||||
// This is where we bail out if there is a skip attribute. This is only
|
// This is where we bail out if there is a skip attribute. This is only
|
||||||
// complex in the module case. It is complex because the module could be
|
// complex in the module case. It is complex because the module could be
|
||||||
// in a seperate file and there might be attributes in both files, but
|
// in a separate file and there might be attributes in both files, but
|
||||||
// the AST lumps them all together.
|
// the AST lumps them all together.
|
||||||
match item.node {
|
match item.node {
|
||||||
ast::ItemKind::Mod(ref m) => {
|
ast::ItemKind::Mod(ref m) => {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// rustfmt-reorder_imports: true
|
// rustfmt-reorder_imports: true
|
||||||
// rustfmt-reorder_imported_names: true
|
// rustfmt-reorder_imported_names: true
|
||||||
|
|
||||||
|
/// This comment should stay with `use std::str;`
|
||||||
use std::str;
|
use std::str;
|
||||||
use std::cmp::{d, c, b, a};
|
use std::cmp::{d, c, b, a};
|
||||||
use std::ddd::aaa;
|
use std::ddd::aaa;
|
||||||
|
@ -33,7 +33,7 @@ fn get_path_string(dir_entry: io::Result<fs::DirEntry>) -> String {
|
|||||||
|
|
||||||
// Integration tests. The files in the tests/source are formatted and compared
|
// Integration tests. The files in the tests/source are formatted and compared
|
||||||
// to their equivalent in tests/target. The target file and config can be
|
// to their equivalent in tests/target. The target file and config can be
|
||||||
// overriden by annotations in the source file. The input and output must match
|
// overridden by annotations in the source file. The input and output must match
|
||||||
// exactly.
|
// exactly.
|
||||||
// FIXME(#28) would be good to check for error messages and fail on them, or at
|
// FIXME(#28) would be good to check for error messages and fail on them, or at
|
||||||
// least report.
|
// least report.
|
||||||
|
@ -6,4 +6,5 @@ use std::ddd::{a, b, c as g, d as p};
|
|||||||
use std::ddd::aaa;
|
use std::ddd::aaa;
|
||||||
// This comment should stay with `use std::ddd:bbb;`
|
// This comment should stay with `use std::ddd:bbb;`
|
||||||
use std::ddd::bbb;
|
use std::ddd::bbb;
|
||||||
|
/// This comment should stay with `use std::str;`
|
||||||
use std::str;
|
use std::str;
|
||||||
|
Loading…
Reference in New Issue
Block a user