Skip to content

Commit f6a0951

Browse files
committed
add with no visible path if doc hidden
1 parent be500b0 commit f6a0951

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ use rustc_hir::{self as hir, ExprKind, HirId, Node, PathSegment, QPath};
2323
use rustc_infer::infer::{self, RegionVariableOrigin};
2424
use rustc_middle::bug;
2525
use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams, simplify_type};
26+
#[allow(unused_imports)]
2627
use rustc_middle::ty::print::{
27-
PrintTraitRefExt as _, with_crate_prefix, with_forced_trimmed_paths,
28+
PrintTraitRefExt as _, with_crate_prefix, with_forced_trimmed_paths, with_no_trimmed_paths,
29+
with_no_visible_paths, with_no_visible_paths_if_doc_hidden,
2830
};
2931
use rustc_middle::ty::{self, GenericArgKind, IsSuggestable, Ty, TyCtxt, TypeVisitableExt};
3032
use rustc_span::def_id::DefIdSet;
@@ -3337,15 +3339,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
33373339
// );
33383340
format!(
33393341
"{prefix}{}{postfix}\n",
3340-
with_crate_prefix!(self.tcx.def_path_str(*trait_did)),
3342+
with_no_visible_paths_if_doc_hidden!(with_crate_prefix!(
3343+
self.tcx.def_path_str(*trait_did)
3344+
)),
33413345
)
33423346
});
33433347

33443348
let glob_path_strings = globs.iter().map(|trait_did| {
33453349
let parent_did = parent_map.get(trait_did).unwrap();
33463350
format!(
33473351
"{prefix}{}::*{postfix} // trait {}\n",
3348-
with_crate_prefix!(self.tcx.def_path_str(*parent_did)),
3352+
with_no_visible_paths_if_doc_hidden!(with_crate_prefix!(
3353+
self.tcx.def_path_str(*parent_did)
3354+
)),
33493355
self.tcx.item_name(*trait_did),
33503356
)
33513357
});

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ thread_local! {
6363
static FORCE_TRIMMED_PATH: Cell<bool> = const { Cell::new(false) };
6464
static REDUCED_QUERIES: Cell<bool> = const { Cell::new(false) };
6565
static NO_VISIBLE_PATH: Cell<bool> = const { Cell::new(false) };
66+
static NO_VISIBLE_PATH_IF_DOC_HIDDEN: Cell<bool> = const { Cell::new(false) };
6667
static RTN_MODE: Cell<RtnMode> = const { Cell::new(RtnMode::ForDiagnostic) };
6768
}
6869

@@ -134,6 +135,7 @@ define_helper!(
134135
/// Prevent selection of visible paths. `Display` impl of DefId will prefer
135136
/// visible (public) reexports of types as paths.
136137
fn with_no_visible_paths(NoVisibleGuard, NO_VISIBLE_PATH);
138+
fn with_no_visible_paths_if_doc_hidden(NoVisibleIfDocHiddenGuard, NO_VISIBLE_PATH_IF_DOC_HIDDEN);
137139
);
138140

139141
#[must_use]
@@ -491,6 +493,9 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
491493
callers: &mut Vec<DefId>,
492494
) -> Result<bool, PrintError> {
493495
// debug!("try_print_visible_def_path: def_id={:?}", def_id);
496+
if self.tcx().is_doc_hidden(def_id) && with_no_visible_paths_if_doc_hidden() {
497+
return Ok(false);
498+
}
494499

495500
// If `def_id` is a direct or injected extern crate, return the
496501
// path to the crate followed by the path to the item within the crate.

tests/ui/issues/issue-127011.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | Bar::foo();
77
= help: items from traits can only be used if the trait is in scope
88
help: trait `Foo` which provides `foo` is implemented but not in scope; perhaps you want to import it
99
|
10-
LL + use issue_127011_a::Foo;
10+
LL + use issue_127011_b::Foo;
1111
|
1212

1313
error: aborting due to 1 previous error

0 commit comments

Comments
 (0)