Skip to content

Commit e9ca0af

Browse files
committedNov 29, 2023
check redundant prelude imports
detects unnecessary imports in std::prelude that can be eliminated. For example import: ```rust use std::{option::{Iter, IterMut, IntoIter, Option::{self, Some}}, convert::{TryFrom, TryInto}, mem::drop}; ``` delete : `Option::{self, Some}` and `mem::drop`
1 parent f440b5f commit e9ca0af

File tree

97 files changed

+231
-207
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+231
-207
lines changed
 

‎compiler/rustc_macros/src/hash_stable.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use proc_macro2::{self, Ident};
1+
use proc_macro2::Ident;
22
use quote::quote;
3-
use syn::{self, parse_quote};
3+
use syn::parse_quote;
44

55
struct Attributes {
66
ignore: bool,

‎compiler/rustc_resolve/src/build_reduced_graph.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::Namespace::{self, MacroNS, TypeNS, ValueNS};
1212
use crate::{errors, BindingKey, MacroData, NameBindingData};
1313
use crate::{Determinacy, ExternPreludeEntry, Finalize, Module, ModuleKind, ModuleOrUniformRoot};
1414
use crate::{NameBinding, NameBindingKind, ParentScope, PathResult, PerNS, ResolutionError};
15-
use crate::{Resolver, ResolverArenas, Segment, ToNameBinding, VisResolutionError};
15+
use crate::{Resolver, ResolverArenas, Segment, ToNameBinding, Used, VisResolutionError};
1616

1717
use rustc_ast::visit::{self, AssocCtxt, Visitor};
1818
use rustc_ast::{self as ast, AssocItem, AssocItemKind, MetaItemKind, StmtKind};
@@ -358,7 +358,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
358358
root_span,
359359
root_id,
360360
vis: Cell::new(Some(vis)),
361-
used: Cell::new(false),
361+
used: Default::default(),
362362
});
363363

364364
self.r.indeterminate_imports.push(import);
@@ -852,7 +852,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
852852
span: item.span,
853853
module_path: Vec::new(),
854854
vis: Cell::new(Some(vis)),
855-
used: Cell::new(used),
855+
used: Cell::new(used.then_some(Used::Other)),
856856
});
857857
self.r.potentially_unused_imports.push(import);
858858
let imported_binding = self.r.import(binding, import);
@@ -1061,7 +1061,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
10611061
span,
10621062
module_path: Vec::new(),
10631063
vis: Cell::new(Some(ty::Visibility::Restricted(CRATE_DEF_ID))),
1064-
used: Cell::new(false),
1064+
used: Default::default(),
10651065
})
10661066
};
10671067

@@ -1225,7 +1225,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
12251225
span,
12261226
module_path: Vec::new(),
12271227
vis: Cell::new(Some(vis)),
1228-
used: Cell::new(true),
1228+
used: Cell::new(Some(Used::Other)),
12291229
});
12301230
let import_binding = self.r.import(binding, import);
12311231
self.r.define(self.r.graph_root, ident, MacroNS, import_binding);

0 commit comments

Comments
 (0)