diff options
| author | Trevor Gross <tmgross@umich.edu> | 2025-01-13 04:44:58 +0000 |
|---|---|---|
| committer | Trevor Gross <tmgross@umich.edu> | 2025-01-14 08:51:19 +0000 |
| commit | 2da9accab989b8640c7b345371b08886e9332f7e (patch) | |
| tree | 6289be7e4938a35f59ebf5381d2657366295c829 /compiler/rustc_passes/src | |
| parent | 9c3425376243966476d07d4a35a87ff228fb890b (diff) | |
| download | rust-2da9accab989b8640c7b345371b08886e9332f7e.tar.gz rust-2da9accab989b8640c7b345371b08886e9332f7e.zip | |
Add `tcx.visible_traits()` and use it for producing diagnostics
Add an alternative to `tcx.all_traits()` that only shows traits that the user might be able to use, for diagnostic purposes. With this available, make use of it for diagnostics including associated type errors, which is part of the problem with [1]. Includes a few comment updates for related API. [1]: https://github.com/rust-lang/rust/issues/135232
Diffstat (limited to 'compiler/rustc_passes/src')
| -rw-r--r-- | compiler/rustc_passes/src/diagnostic_items.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/compiler/rustc_passes/src/diagnostic_items.rs b/compiler/rustc_passes/src/diagnostic_items.rs index 7b02aecdfae..323b414cca0 100644 --- a/compiler/rustc_passes/src/diagnostic_items.rs +++ b/compiler/rustc_passes/src/diagnostic_items.rs @@ -79,8 +79,14 @@ fn all_diagnostic_items(tcx: TyCtxt<'_>, (): ()) -> DiagnosticItems { // Initialize the collector. let mut items = DiagnosticItems::default(); - // Collect diagnostic items in other crates. - for &cnum in tcx.crates(()).iter().chain(std::iter::once(&LOCAL_CRATE)) { + // Collect diagnostic items in visible crates. + for cnum in tcx + .crates(()) + .iter() + .copied() + .filter(|cnum| tcx.is_user_visible_dep(*cnum)) + .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); } |
