rustc: Use tcx.used_crates(()) more

And explain when it should be used.
This commit is contained in:
Vadim Petrochenkov 2024-05-10 17:29:02 +03:00
parent 4363278c73
commit 765baba165

View File

@ -647,7 +647,7 @@ fn item_children_by_name(tcx: TyCtxt<'_>, def_id: DefId, name: Symbol) -> Vec<Re
/// This function is expensive and should be used sparingly. /// This function is expensive and should be used sparingly.
pub fn def_path_res(cx: &LateContext<'_>, path: &[&str]) -> Vec<Res> { pub fn def_path_res(cx: &LateContext<'_>, path: &[&str]) -> Vec<Res> {
fn find_crates(tcx: TyCtxt<'_>, name: Symbol) -> impl Iterator<Item = DefId> + '_ { fn find_crates(tcx: TyCtxt<'_>, name: Symbol) -> impl Iterator<Item = DefId> + '_ {
tcx.crates(()) tcx.crates_including_speculative(())
.iter() .iter()
.copied() .copied()
.filter(move |&num| tcx.crate_name(num) == name) .filter(move |&num| tcx.crate_name(num) == name)