Group imports consistently

This corresponds to:

$ cargo +nightly fmt -- --config group_imports=StdExternalCrate

Since this option is only available on nightly, I'm not adding a
rustfmt.toml to enforce this, just doing it as a one-off run.
pull/573/head
Wilfred Hughes 2023-09-12 12:31:22 +07:00
parent 8731a1b908
commit 243a4a5f48
18 changed files with 83 additions and 65 deletions

@ -6,8 +6,9 @@
// body for readability.
#![allow(clippy::if_same_then_else)]
use rayon::prelude::*;
use std::{path::PathBuf, process::Command};
use rayon::prelude::*;
use version_check as rustc;
struct TreeSitterParser {

@ -3,15 +3,16 @@
use std::{cmp::Reverse, env};
use bumpalo::Bump;
use itertools::Itertools;
use radix_heap::RadixHeapMap;
use crate::{
diff::changes::ChangeMap,
diff::graph::{populate_change_map, set_neighbours, Edge, Vertex},
hash::DftHashMap,
parse::syntax::Syntax,
};
use bumpalo::Bump;
use itertools::Itertools;
use radix_heap::RadixHeapMap;
#[derive(Debug)]
pub struct ExceededGraphLimit {}
@ -248,8 +249,11 @@ pub fn mark_syntax<'a>(
#[cfg(test)]
mod tests {
use super::*;
use itertools::Itertools;
use line_numbers::SingleLineSpan;
use typed_arena::Arena;
use super::*;
use crate::{
diff::changes::ChangeKind,
diff::graph::Edge::*,
@ -257,10 +261,6 @@ mod tests {
syntax::{init_all_info, AtomKind},
};
use itertools::Itertools;
use line_numbers::SingleLineSpan;
use typed_arena::Arena;
fn pos_helper(line: u32) -> Vec<SingleLineSpan> {
vec![SingleLineSpan {
line: line.into(),

@ -1,15 +1,17 @@
//! A graph representation for computing tree diffs.
use bumpalo::Bump;
use hashbrown::hash_map::RawEntryMut;
use std::{
cell::{Cell, RefCell},
cmp::min,
fmt,
hash::{Hash, Hasher},
};
use bumpalo::Bump;
use hashbrown::hash_map::RawEntryMut;
use strsim::normalized_levenshtein;
use self::Edge::*;
use crate::{
diff::{
changes::{insert_deep_unchanged, ChangeKind, ChangeMap},
@ -18,7 +20,6 @@ use crate::{
hash::DftHashMap,
parse::syntax::{AtomKind, Syntax, SyntaxId},
};
use Edge::*;
/// A vertex in a directed acyclic graph that represents a diff.
///

@ -1,8 +1,9 @@
//! A fast diff for linear content, using Myer's diff algorithm.
use rustc_hash::FxHashSet;
use std::hash::Hash;
use rustc_hash::FxHashSet;
use crate::hash::DftHashMap;
#[derive(Debug, PartialEq)]

@ -34,9 +34,8 @@ use line_numbers::SingleLineSpan;
use crate::{
diff::changes::{insert_deep_novel, insert_deep_unchanged, ChangeKind::*, ChangeMap},
parse::guess_language,
parse::syntax::Syntax,
parse::syntax::Syntax::{self, *},
};
use Syntax::*;
pub fn fix_all_sliders<'a>(
language: guess_language::Language,
@ -672,14 +671,15 @@ impl<'a> Syntax<'a> {
#[cfg(test)]
mod tests {
use pretty_assertions::assert_eq;
use typed_arena::Arena;
use super::*;
use crate::{
parse::guess_language,
parse::tree_sitter_parser::{from_language, parse},
syntax::{init_all_info, AtomKind},
};
use pretty_assertions::assert_eq;
use typed_arena::Arena;
/// Test that we slide at the start if the unchanged node is
/// closer than the trailing novel node.

@ -6,7 +6,6 @@ use std::hash::Hash;
use crate::diff::changes::{insert_deep_unchanged, ChangeKind, ChangeMap};
use crate::diff::myers_diff;
use crate::parse::syntax::Syntax;
const TINY_TREE_THRESHOLD: u32 = 10;
@ -461,13 +460,14 @@ fn shrink_unchanged_at_ends<'a>(
#[cfg(test)]
mod tests {
use typed_arena::Arena;
use super::*;
use crate::{
parse::guess_language,
parse::tree_sitter_parser::{from_language, parse},
syntax::init_all_info,
};
use typed_arena::Arena;
#[test]
fn test_shrink_unchanged_at_start() {

@ -729,12 +729,12 @@ fn compact_gaps(
mod tests {
use std::iter::FromIterator;
use crate::syntax::TokenKind;
use super::*;
use line_numbers::SingleLineSpan;
use pretty_assertions::assert_eq;
use super::*;
use crate::syntax::TokenKind;
#[test]
fn test_calculate_before_context() {
let num_context_lines = 3;

@ -5,9 +5,10 @@
/// If we exceed this, the lines are stored in separate hunks.
const MAX_DISTANCE: u32 = 4;
use line_numbers::LineNumber;
use std::collections::HashSet;
use line_numbers::LineNumber;
use crate::{
constants::Side,
display::context::{add_context, opposite_positions},
@ -678,15 +679,16 @@ pub fn matched_lines_indexes_for_hunk(
#[cfg(test)]
mod tests {
use line_numbers::SingleLineSpan;
use std::iter::FromIterator;
use line_numbers::SingleLineSpan;
use pretty_assertions::assert_eq;
use super::*;
use crate::{
hash::DftHashMap,
syntax::{MatchKind, TokenKind},
};
use pretty_assertions::assert_eq;
#[test]
fn test_sorted_novel_positions_simple() {

@ -1,3 +1,8 @@
use std::collections::HashMap;
use line_numbers::LineNumber;
use serde::{ser::SerializeStruct, Serialize, Serializer};
use crate::{
display::{
context::{all_matched_lines_filled, opposite_positions},
@ -8,9 +13,6 @@ use crate::{
parse::syntax::{self, MatchedPos},
summary::{DiffResult, FileContent, FileFormat},
};
use line_numbers::LineNumber;
use serde::{ser::SerializeStruct, Serialize, Serializer};
use std::collections::HashMap;
#[derive(Debug, Serialize)]
#[serde(rename_all = "lowercase")]

@ -1,14 +1,14 @@
//! Side-by-side (two column) display of diffs.
use line_numbers::LineNumber;
use line_numbers::SingleLineSpan;
use owo_colors::{OwoColorize, Style};
use std::{
cmp::{max, min},
collections::HashSet,
};
use line_numbers::LineNumber;
use line_numbers::SingleLineSpan;
use owo_colors::{OwoColorize, Style};
use crate::{
constants::Side,
display::context::all_matched_lines_filled,
@ -595,14 +595,14 @@ pub fn print(
#[cfg(test)]
mod tests {
use pretty_assertions::assert_eq;
use super::*;
use crate::{
parse::guess_language::Language,
syntax::{AtomKind, MatchKind, TokenKind},
};
use super::*;
use pretty_assertions::assert_eq;
#[test]
fn test_width_calculations() {
let line_nums = [(Some(1.into()), Some(10.into()))];

@ -1,5 +1,12 @@
//! Apply colours and styling to strings.
use std::cmp::{max, min};
use line_numbers::LineNumber;
use line_numbers::SingleLineSpan;
use owo_colors::{OwoColorize, Style};
use unicode_width::{UnicodeWidthChar, UnicodeWidthStr};
use crate::{
constants::Side,
hash::DftHashMap,
@ -9,12 +16,6 @@ use crate::{
summary::FileFormat,
};
use line_numbers::LineNumber;
use line_numbers::SingleLineSpan;
use owo_colors::{OwoColorize, Style};
use std::cmp::{max, min};
use unicode_width::{UnicodeWidthChar, UnicodeWidthStr};
#[derive(Clone, Copy, Debug)]
pub enum BackgroundColor {
Dark,
@ -496,9 +497,10 @@ pub fn header(
mod tests {
const TAB_WIDTH: usize = 2;
use super::*;
use pretty_assertions::assert_eq;
use super::*;
#[test]
fn split_string_simple() {
assert_eq!(

@ -194,10 +194,11 @@ pub fn change_positions(lhs_src: &str, rhs_src: &str) -> Vec<MatchedPos> {
#[cfg(test)]
mod tests {
use super::*;
use line_numbers::SingleLineSpan;
use pretty_assertions::assert_eq;
use super::*;
#[test]
fn test_split_newlines() {
let s = "foo\nbar\nbaz";

@ -1,8 +1,9 @@
//! Manipulate lines of text and groups of lines.
use line_numbers::LineNumber;
use std::ops::Sub;
use line_numbers::LineNumber;
pub fn format_line_num(line_num: LineNumber) -> String {
format!("{} ", line_num.display())
}
@ -51,9 +52,10 @@ pub fn is_all_whitespace(s: &str) -> bool {
#[cfg(test)]
mod tests {
use super::*;
use pretty_assertions::assert_eq;
use super::*;
#[test]
fn str_max_line() {
let line: String = "foo\nbar".into();

@ -40,6 +40,9 @@ mod version;
#[macro_use]
extern crate log;
use log::info;
use mimalloc::MiMalloc;
use crate::conflicts::apply_conflict_markers;
use crate::conflicts::START_LHS_MARKER;
use crate::diff::changes::ChangeMap;
@ -56,8 +59,6 @@ use crate::files::{
use crate::parse::guess_language::language_globs;
use crate::parse::guess_language::{guess, language_name, Language, LanguageOverride};
use crate::parse::syntax;
use log::info;
use mimalloc::MiMalloc;
/// The global allocator used by difftastic.
///
@ -66,19 +67,20 @@ use mimalloc::MiMalloc;
#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;
use crate::diff::sliders::fix_all_sliders;
use crate::options::{DiffOptions, DisplayMode, DisplayOptions, FileArgument, Mode};
use crate::summary::{DiffResult, FileContent, FileFormat};
use crate::syntax::init_next_prev;
use humansize::{format_size, BINARY};
use owo_colors::OwoColorize;
use rayon::prelude::*;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::{env, path::Path};
use humansize::{format_size, BINARY};
use owo_colors::OwoColorize;
use rayon::prelude::*;
use strum::IntoEnumIterator;
use typed_arena::Arena;
use crate::diff::sliders::fix_all_sliders;
use crate::options::{DiffOptions, DisplayMode, DisplayOptions, FileArgument, Mode};
use crate::summary::{DiffResult, FileContent, FileFormat};
use crate::syntax::init_next_prev;
use crate::{
dijkstra::mark_syntax, lines::MaxLine, parse::syntax::init_all_info,
parse::tree_sitter_parser as tsp,

@ -8,9 +8,10 @@
//! Difftastic does not reuse languages.yml directly. Linguist has a
//! larger set of language detection strategies.
use std::{borrow::Borrow, path::Path};
use lazy_static::lazy_static;
use regex::Regex;
use std::{borrow::Borrow, path::Path};
use strum::{EnumIter, IntoEnumIterator};
/// Languages supported by difftastic. Each language here has a
@ -549,9 +550,10 @@ fn from_glob(path: &Path) -> Option<Language> {
#[cfg(test)]
mod tests {
use super::*;
use pretty_assertions::assert_eq;
use super::*;
#[test]
fn test_guess_by_extension() {
let path = Path::new("foo.el");

@ -2,11 +2,13 @@
#![allow(clippy::mutable_key_type)] // Hash for Syntax doesn't use mutable fields.
use std::{cell::Cell, env, fmt, hash::Hash, num::NonZeroU32};
use line_numbers::LinePositions;
use line_numbers::SingleLineSpan;
use std::{cell::Cell, env, fmt, hash::Hash, num::NonZeroU32};
use typed_arena::Arena;
use self::Syntax::*;
use crate::{
diff::changes::ChangeKind,
diff::changes::{ChangeKind::*, ChangeMap},
@ -14,7 +16,6 @@ use crate::{
hash::DftHashMap,
lines::is_all_whitespace,
};
use Syntax::*;
/// A Debug implementation that does not recurse into the
/// corresponding node mentioned for Unchanged. Otherwise we will
@ -1030,9 +1031,10 @@ pub fn zip_repeat_shorter<Tx: Clone, Ty: Clone>(lhs: &[Tx], rhs: &[Ty]) -> Vec<(
#[cfg(test)]
mod tests {
use super::*;
use pretty_assertions::assert_eq;
use super::*;
/// Consider comment atoms as distinct to other atoms even if the
/// content matches otherwise.
#[test]

@ -2,17 +2,16 @@
use std::collections::HashSet;
use crate::hash::DftHashMap;
use crate::options::DiffOptions;
use crate::parse::guess_language as guess;
use line_numbers::LinePositions;
use tree_sitter as ts;
use typed_arena::Arena;
use crate::parse::syntax::{AtomKind, Syntax};
use super::syntax;
use super::syntax::MatchedPos;
use crate::hash::DftHashMap;
use crate::options::DiffOptions;
use crate::parse::guess_language as guess;
use crate::parse::syntax::{AtomKind, Syntax};
/// A language may contain certain nodes that are in other languages
/// and should be parsed as such (e.g. HTML `<script>` nodes containing

@ -1,6 +1,7 @@
use std::process::Command;
use assert_cmd::prelude::*;
use predicates::prelude::*;
use std::process::Command;
#[test]
fn no_such_files() {