remove redundant imports

detects redundant imports that can be eliminated.

for #117772 :

In order to facilitate review and modification, split the checking code and
removing redundant imports code into two PR.
This commit is contained in:
surechen 2023-11-10 10:11:24 +08:00
parent 9c809ce8de
commit 1b9bf8adf3
12 changed files with 4 additions and 16 deletions

View File

@ -1,6 +1,6 @@
// Formatting and tools for comments. // Formatting and tools for comments.
use std::{self, borrow::Cow, iter}; use std::{borrow::Cow, iter};
use itertools::{multipeek, MultiPeek}; use itertools::{multipeek, MultiPeek};
use lazy_static::lazy_static; use lazy_static::lazy_static;
@ -1847,7 +1847,6 @@ fn remove_comment_header(comment: &str) -> &str {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
use crate::shape::{Indent, Shape};
#[test] #[test]
fn char_classes() { fn char_classes() {

View File

@ -6,7 +6,7 @@
use std::{cmp, fmt, iter, str}; use std::{cmp, fmt, iter, str};
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
use rustc_span::{self, SourceFile}; use rustc_span::SourceFile;
use serde::{ser, Deserialize, Deserializer, Serialize, Serializer}; use serde::{ser, Deserialize, Deserializer, Serialize, Serializer};
use serde_json as json; use serde_json as json;
use thiserror::Error; use thiserror::Error;

View File

@ -1,5 +1,4 @@
use std::cell::Cell; use std::cell::Cell;
use std::default::Default;
use std::fs::File; use std::fs::File;
use std::io::{Error, ErrorKind, Read}; use std::io::{Error, ErrorKind, Read};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@ -1017,7 +1016,6 @@ fn test_override_single_line_if_else_max_width_exceeds_max_width() {
#[cfg(test)] #[cfg(test)]
mod partially_unstable_option { mod partially_unstable_option {
use super::mock::{Config, PartiallyUnstableOption}; use super::mock::{Config, PartiallyUnstableOption};
use super::*;
/// From the command line, we can override with a stable variant. /// From the command line, we can override with a stable variant.
#[test] #[test]

View File

@ -1,7 +1,6 @@
use self::xml::XmlEscaped; use self::xml::XmlEscaped;
use super::*; use super::*;
use crate::rustfmt_diff::{make_diff, DiffLine, Mismatch}; use crate::rustfmt_diff::{make_diff, DiffLine, Mismatch};
use std::io::{self, Write};
mod xml; mod xml;

View File

@ -51,8 +51,6 @@ fn emit_formatted_file(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::config::Config;
use crate::FileName;
use std::path::PathBuf; use std::path::PathBuf;
#[test] #[test]

View File

@ -2,7 +2,6 @@
use crate::rustfmt_diff::{make_diff, DiffLine, Mismatch}; use crate::rustfmt_diff::{make_diff, DiffLine, Mismatch};
use serde::Serialize; use serde::Serialize;
use serde_json::to_string as to_json_string; use serde_json::to_string as to_json_string;
use std::io::{self, Write};
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub(crate) struct JsonEmitter { pub(crate) struct JsonEmitter {
@ -106,7 +105,6 @@ fn add_misformatted_file(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::FileName;
use std::path::PathBuf; use std::path::PathBuf;
#[test] #[test]

View File

@ -1,6 +1,5 @@
use super::*; use super::*;
use crate::rustfmt_diff::{make_diff, ModifiedLines}; use crate::rustfmt_diff::{make_diff, ModifiedLines};
use std::io::Write;
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub(crate) struct ModifiedLinesEmitter; pub(crate) struct ModifiedLinesEmitter;

View File

@ -1,6 +1,5 @@
use super::*; use super::*;
use crate::config::Verbosity; use crate::config::Verbosity;
use std::io::Write;
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct StdoutEmitter { pub(crate) struct StdoutEmitter {

View File

@ -1,4 +1,4 @@
use ignore::{self, gitignore}; use ignore::gitignore;
use crate::config::{FileName, IgnoreList}; use crate::config::{FileName, IgnoreList};

View File

@ -1102,7 +1102,6 @@ enum SharedPrefix {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
use rustc_span::DUMMY_SP;
// Parse the path part of an import. This parser is not robust and is only // Parse the path part of an import. This parser is not robust and is only
// suitable for use in a test harness. // suitable for use in a test harness.

View File

@ -6,7 +6,7 @@
// FIXME(#2455): Reorder trait items. // FIXME(#2455): Reorder trait items.
use std::cmp::{Ord, Ordering}; use std::cmp::Ordering;
use rustc_ast::{ast, attr}; use rustc_ast::{ast, attr};
use rustc_span::{symbol::sym, Span}; use rustc_span::{symbol::sym, Span};

View File

@ -1,4 +1,3 @@
use std::iter::ExactSizeIterator;
use std::ops::Deref; use std::ops::Deref;
use rustc_ast::ast::{self, FnRetTy, Mutability, Term}; use rustc_ast::ast::{self, FnRetTy, Mutability, Term};