Skip to content

Commit

Permalink
Use visible_crates rather than crates for solving and diagnostics
Browse files Browse the repository at this point in the history
For places where we don't want stdlib-private crates to be accessible,
use `.visible_crates()` rather than `.crates()`. The current effect is
that items in stdlib-private crates will no longer show up in
diagnostics related to trait selection.

Fixes: rust-lang#135232
  • Loading branch information
tgross35 committed Jan 12, 2025
1 parent e7098e3 commit 73b07b0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2080,7 +2080,7 @@ impl<'tcx> TyCtxt<'tcx> {

pub fn all_traits(self) -> impl Iterator<Item = DefId> + 'tcx {
iter::once(LOCAL_CRATE)
.chain(self.crates(()).iter().copied())
.chain(self.visible_crates(()).iter().copied())
.flat_map(move |cnum| self.traits(cnum).iter().copied())
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/diagnostic_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn all_diagnostic_items(tcx: TyCtxt<'_>, (): ()) -> DiagnosticItems {
let mut items = DiagnosticItems::default();

// Collect diagnostic items in other crates.
for &cnum in tcx.crates(()).iter().chain(std::iter::once(&LOCAL_CRATE)) {
for &cnum in tcx.visible_crates(()).iter().chain(std::iter::once(&LOCAL_CRATE)) {
for (&name, &def_id) in &tcx.diagnostic_items(cnum).name_to_id {
collect_item(tcx, &mut items, name, def_id);
}
Expand Down

0 comments on commit 73b07b0

Please sign in to comment.