Skip to content

Commit

Permalink
Auto merge of rust-lang#117772 - surechen:for_117448, r=petrochenkov
Browse files Browse the repository at this point in the history
Tracking import use types for more accurate redundant import checking

fixes rust-lang#117448

By tracking import use types to check whether it is scope uses or the other situations like module-relative uses,  we can do more accurate redundant import checking.

For example unnecessary imports in std::prelude that can be eliminated:

```rust
use std::option::Option::Some;//~ WARNING the item `Some` is imported redundantly
use std::option::Option::None; //~ WARNING the item `None` is imported redundantly
```
  • Loading branch information
bors committed Feb 18, 2024
2 parents 6b17dba + 5db0494 commit 1c10aa4
Show file tree
Hide file tree
Showing 19 changed files with 20 additions and 34 deletions.
2 changes: 1 addition & 1 deletion crates/hir-def/src/body/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use itertools::Itertools;

use crate::{
hir::{
Array, BindingAnnotation, BindingId, CaptureBy, ClosureKind, Literal, LiteralOrConst,
Array, BindingAnnotation, CaptureBy, ClosureKind, Literal, LiteralOrConst,
Movability, Statement,
},
pretty::{print_generic_args, print_path, print_type_ref},
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::{fmt, hash::BuildHasherDefault};

use base_db::CrateId;
use fst::{self, raw::IndexedValue, Automaton, Streamer};
use fst::{raw::IndexedValue, Automaton, Streamer};
use hir_expand::name::Name;
use indexmap::IndexMap;
use itertools::Itertools;
Expand Down
8 changes: 4 additions & 4 deletions crates/hir-def/src/item_tree/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

use std::collections::hash_map::Entry;

use hir_expand::{ast_id_map::AstIdMap, span_map::SpanMapRef, HirFileId};
use syntax::ast::{self, HasModuleItem, HasTypeBounds, IsString};
use hir_expand::{ast_id_map::AstIdMap, span_map::SpanMapRef};
use syntax::ast::{HasModuleItem, HasTypeBounds, IsString};

use crate::{
generics::{GenericParams, GenericParamsCollector, TypeParamData, TypeParamProvenance},
type_ref::{LifetimeRef, TraitBoundModifier, TraitRef},
generics::{GenericParamsCollector, TypeParamData, TypeParamProvenance},
type_ref::{LifetimeRef, TraitBoundModifier},
LocalLifetimeParamId, LocalTypeOrConstParamId,
};

Expand Down
5 changes: 2 additions & 3 deletions crates/hir-def/src/item_tree/pretty.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
//! `ItemTree` debug printer.

use std::fmt::{self, Write};
use std::fmt::Write;

use span::ErasedFileAstId;

use crate::{
generics::{TypeOrConstParamData, WherePredicate, WherePredicateTypeTarget},
generics::{WherePredicate, WherePredicateTypeTarget},
pretty::{print_path, print_type_bounds, print_type_ref},
visibility::RawVisibility,
};

use super::*;
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/nameres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub mod proc_macro;
#[cfg(test)]
mod tests;

use std::{cmp::Ord, ops::Deref};
use std::ops::Deref;

use base_db::{CrateId, Edition, FileId};
use hir_expand::{
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/diagnostics/match_check/pat_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! Originates from `rustc_hir::pat_util`

use std::iter::{Enumerate, ExactSizeIterator};
use std::iter::Enumerate;

pub(crate) struct EnumerateAndAdjust<I> {
enumerate: Enumerate<I>,
Expand Down
6 changes: 1 addition & 5 deletions crates/hir-ty/src/mir/eval/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
use std::cmp;

use chalk_ir::TyKind;
use hir_def::{
builtin_type::{BuiltinInt, BuiltinUint},
resolver::HasResolver,
};
use hir_expand::mod_path::ModPath;
use hir_def::builtin_type::{BuiltinInt, BuiltinUint};

use super::*;

Expand Down
10 changes: 3 additions & 7 deletions crates/hir-ty/src/mir/lower.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! This module generates a polymorphic MIR from a hir body

use std::{fmt::Write, iter, mem};
use std::{fmt::Write, mem};

use base_db::{salsa::Cycle, FileId};
use chalk_ir::{BoundVar, ConstData, DebruijnIndex, TyKind};
Expand All @@ -14,23 +14,19 @@ use hir_def::{
lang_item::{LangItem, LangItemTarget},
path::Path,
resolver::{resolver_for_expr, HasResolver, ResolveValueResult, ValueNs},
AdtId, DefWithBodyId, EnumVariantId, GeneralConstId, HasModule, ItemContainerId, LocalFieldId,
AdtId, EnumVariantId, GeneralConstId, HasModule, ItemContainerId, LocalFieldId,
Lookup, TraitId, TupleId, TypeOrConstParamId,
};
use hir_expand::name::Name;
use la_arena::ArenaMap;
use rustc_hash::FxHashMap;
use syntax::TextRange;
use triomphe::Arc;

use crate::{
consteval::ConstEvalError,
db::{HirDatabase, InternedClosure},
display::HirDisplay,
db::InternedClosure,
infer::{CaptureKind, CapturedItem, TypeMismatch},
inhabitedness::is_ty_uninhabited_from,
layout::LayoutError,
mapping::ToChalk,
static_lifetime,
traits::FnTrait,
utils::{generics, ClosureSubst},
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/mir/lower/pattern_matching.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! MIR lowering for patterns

use hir_def::{hir::LiteralOrConst, resolver::HasResolver, AssocItemId};
use hir_def::AssocItemId;

use crate::BindingMode;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use hir::{self, HasCrate, HasVisibility};
use hir::{HasCrate, HasVisibility};
use ide_db::{path_transform::PathTransform, FxHashSet};
use syntax::{
ast::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
//! }
//! ```

use hir::{self, HasAttrs};
use hir::HasAttrs;
use ide_db::{
documentation::HasDocs, path_transform::PathTransform,
syntax_helpers::insert_whitespace_into_node, traits::get_missing_assoc_items, SymbolKind,
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-db/src/symbol_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use base_db::{
salsa::{self, ParallelDatabase},
SourceDatabaseExt, SourceRootId, Upcast,
};
use fst::{self, raw::IndexedValue, Automaton, Streamer};
use fst::{raw::IndexedValue, Automaton, Streamer};
use hir::{
db::HirDatabase,
import_map::{AssocSearchMode, SearchMode},
Expand Down
2 changes: 1 addition & 1 deletion crates/rust-analyzer/src/cargo_target_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::mem;

use cfg::{CfgAtom, CfgExpr};
use ide::{Cancellable, CrateId, FileId, RunnableKind, TestId};
use project_model::{self, CargoFeatures, ManifestPath, TargetKind};
use project_model::{CargoFeatures, ManifestPath, TargetKind};
use rustc_hash::FxHashSet;
use vfs::AbsPathBuf;

Expand Down
2 changes: 1 addition & 1 deletion crates/rust-analyzer/src/cli/lsif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use ide_db::{
LineIndexDatabase,
};
use load_cargo::{load_workspace, LoadCargoConfig, ProcMacroServerChoice};
use lsp_types::{self, lsif};
use lsp_types::lsif;
use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace, RustLibSource};
use rustc_hash::FxHashMap;
use vfs::{AbsPathBuf, Vfs};
Expand Down
1 change: 0 additions & 1 deletion crates/salsa/salsa-macros/src/query_group.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//!
use std::{convert::TryFrom, iter::FromIterator};

use crate::parenthesized::Parenthesized;
use heck::ToUpperCamelCase;
Expand Down
1 change: 0 additions & 1 deletion crates/salsa/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::durability::Durability;
use crate::plumbing::QueryStorageOps;
use crate::Query;
use crate::QueryTable;
use std::iter::FromIterator;

/// Additional methods on queries that can be used to "peek into"
/// their current state. These methods are meant for debugging and
Expand Down
1 change: 0 additions & 1 deletion crates/salsa/src/derived.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::Runtime;
use crate::{Database, DatabaseKeyIndex, QueryDb, Revision};
use parking_lot::RwLock;
use std::borrow::Borrow;
use std::convert::TryFrom;
use std::hash::Hash;
use std::marker::PhantomData;
use triomphe::Arc;
Expand Down
1 change: 0 additions & 1 deletion crates/salsa/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use crate::Runtime;
use crate::{DatabaseKeyIndex, QueryDb};
use indexmap::map::Entry;
use parking_lot::RwLock;
use std::convert::TryFrom;
use std::iter;
use tracing::debug;

Expand Down
1 change: 0 additions & 1 deletion crates/salsa/src/interned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::{Database, DatabaseKeyIndex, QueryDb};
use parking_lot::RwLock;
use rustc_hash::FxHashMap;
use std::collections::hash_map::Entry;
use std::convert::From;
use std::fmt::Debug;
use std::hash::Hash;
use triomphe::Arc;
Expand Down

0 comments on commit 1c10aa4

Please sign in to comment.