Use UnordSet instead of FxHashSet for names_imported_by_glob_use query.
This commit is contained in:
parent
ee8bc5b0b2
commit
422208ae52
@ -109,6 +109,12 @@ pub fn flat_map<U, F, O>(self, f: F) -> UnordItems<O, impl Iterator<Item = O>>
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> UnordItems<T, std::iter::Empty<T>> {
|
||||
pub fn empty() -> Self {
|
||||
UnordItems(std::iter::empty())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Clone + 'a, I: Iterator<Item = &'a T>> UnordItems<&'a T, I> {
|
||||
#[inline]
|
||||
pub fn cloned(self) -> UnordItems<T, impl Iterator<Item = T>> {
|
||||
@ -133,6 +139,20 @@ pub fn into_sorted<HCX>(self, hcx: &HCX) -> Vec<T>
|
||||
items
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn into_sorted_stable_ord(self, use_stable_sort: bool) -> Vec<T>
|
||||
where
|
||||
T: Ord + StableOrd,
|
||||
{
|
||||
let mut items: Vec<T> = self.0.collect();
|
||||
if use_stable_sort {
|
||||
items.sort();
|
||||
} else {
|
||||
items.sort_unstable()
|
||||
}
|
||||
items
|
||||
}
|
||||
|
||||
pub fn into_sorted_small_vec<HCX, const LEN: usize>(self, hcx: &HCX) -> SmallVec<[T; LEN]>
|
||||
where
|
||||
T: ToStableHashKey<HCX>,
|
||||
@ -175,6 +195,11 @@ pub fn len(&self) -> usize {
|
||||
self.inner.len()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.inner.is_empty()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn insert(&mut self, v: V) -> bool {
|
||||
self.inner.insert(v)
|
||||
@ -253,7 +278,7 @@ pub fn into_sorted<HCX>(self, hcx: &HCX, cache_sort_key: bool) -> Vec<V>
|
||||
// We can safely extend this UnordSet from a set of unordered values because that
|
||||
// won't expose the internal ordering anywhere.
|
||||
#[inline]
|
||||
pub fn extend<I: Iterator<Item = V>>(&mut self, items: UnordItems<V, I>) {
|
||||
pub fn extend_unord<I: Iterator<Item = V>>(&mut self, items: UnordItems<V, I>) {
|
||||
self.inner.extend(items.0)
|
||||
}
|
||||
|
||||
@ -277,6 +302,12 @@ fn from_iter<T: IntoIterator<Item = V>>(iter: T) -> Self {
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: Hash + Eq> From<FxHashSet<V>> for UnordSet<V> {
|
||||
fn from(value: FxHashSet<V>) -> Self {
|
||||
UnordSet { inner: value }
|
||||
}
|
||||
}
|
||||
|
||||
impl<HCX, V: Hash + Eq + HashStable<HCX>> HashStable<HCX> for UnordSet<V> {
|
||||
#[inline]
|
||||
fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) {
|
||||
|
@ -1826,7 +1826,7 @@
|
||||
query maybe_unused_trait_imports(_: ()) -> &'tcx FxIndexSet<LocalDefId> {
|
||||
desc { "fetching potentially unused trait imports" }
|
||||
}
|
||||
query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx FxHashSet<Symbol> {
|
||||
query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx UnordSet<Symbol> {
|
||||
desc { |tcx| "finding names imported by glob use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
|
||||
}
|
||||
|
||||
|
@ -37,6 +37,7 @@
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_data_structures::steal::Steal;
|
||||
use rustc_data_structures::sync::{self, Lock, Lrc, MappedReadGuard, ReadGuard, WorkerLocal};
|
||||
use rustc_data_structures::unord::UnordSet;
|
||||
use rustc_errors::{
|
||||
DecorateLint, DiagnosticBuilder, DiagnosticMessage, ErrorGuaranteed, MultiSpan,
|
||||
};
|
||||
@ -2488,7 +2489,9 @@ pub fn provide(providers: &mut ty::query::Providers) {
|
||||
providers.maybe_unused_trait_imports =
|
||||
|tcx, ()| &tcx.resolutions(()).maybe_unused_trait_imports;
|
||||
providers.names_imported_by_glob_use = |tcx, id| {
|
||||
tcx.arena.alloc(tcx.resolutions(()).glob_map.get(&id).cloned().unwrap_or_default())
|
||||
tcx.arena.alloc(UnordSet::from(
|
||||
tcx.resolutions(()).glob_map.get(&id).cloned().unwrap_or_default(),
|
||||
))
|
||||
};
|
||||
|
||||
providers.extern_mod_stmt_cnum =
|
||||
|
@ -41,7 +41,7 @@
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast::expand::allocator::AllocatorKind;
|
||||
use rustc_attr as attr;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
|
||||
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
|
||||
use rustc_data_structures::steal::Steal;
|
||||
use rustc_data_structures::svh::Svh;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
|
@ -371,7 +371,7 @@ fn visit_variant_data(&mut self, def: &'tcx hir::VariantData<'tcx>) {
|
||||
}
|
||||
if tcx.visibility(def_id).is_public() { Some(def_id) } else { None }
|
||||
});
|
||||
Extend::extend(&mut self.live_symbols, live_fields);
|
||||
self.live_symbols.extend(live_fields);
|
||||
|
||||
intravisit::walk_struct_def(self, def);
|
||||
}
|
||||
|
@ -155,14 +155,10 @@ fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
|
||||
)
|
||||
};
|
||||
|
||||
let imports_string = if used_imports.len() == 1 {
|
||||
used_imports.iter().next().unwrap().to_string()
|
||||
let mut imports = used_imports.items().map(ToString::to_string).into_sorted_stable_ord(false);
|
||||
let imports_string = if imports.len() == 1 {
|
||||
imports.pop().unwrap()
|
||||
} else {
|
||||
let mut imports = used_imports
|
||||
.iter()
|
||||
.map(ToString::to_string)
|
||||
.collect::<Vec<_>>();
|
||||
imports.sort();
|
||||
if braced_glob {
|
||||
imports.join(", ")
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user