Skip to content

Commit 8f71112

Browse files
committed
add appropriate
1 parent f6a0951 commit 8f71112

File tree

6 files changed

+54
-6
lines changed

6 files changed

+54
-6
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3337,11 +3337,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
33373337
// trait_did,
33383338
// with_crate_prefix!(self.tcx.def_path_str(*trait_did))
33393339
// );
3340+
// format!(
3341+
// "{prefix}{}{postfix}\n",
3342+
// with_no_visible_paths_if_doc_hidden!(with_crate_prefix!(
3343+
// self.tcx.def_path_str(*trait_did)
3344+
// )),
3345+
// )
33403346
format!(
33413347
"{prefix}{}{postfix}\n",
3342-
with_no_visible_paths_if_doc_hidden!(with_crate_prefix!(
3343-
self.tcx.def_path_str(*trait_did)
3344-
)),
3348+
with_crate_prefix!(self.tcx.def_path_str(*trait_did)),
33453349
)
33463350
});
33473351

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,6 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
493493
callers: &mut Vec<DefId>,
494494
) -> Result<bool, PrintError> {
495495
// 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-
}
499496

500497
// If `def_id` is a direct or injected extern crate, return the
501498
// path to the crate followed by the path to the item within the crate.
@@ -577,6 +574,10 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
577574
return Ok(false);
578575
};
579576

577+
if self.tcx().is_doc_hidden(visible_parent) && with_no_visible_paths_if_doc_hidden() {
578+
return Ok(false);
579+
}
580+
580581
let actual_parent = self.tcx().opt_parent(def_id);
581582
// debug!(
582583
// "try_print_visible_def_path: visible_parent={:?} actual_parent={:?}",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//@ edition: 2021
2+
3+
pub trait Foo {
4+
fn foo();
5+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ edition: 2021
2+
//@ aux-crate:suggest_trait_reexported_as_not_doc_visible_a=suggest-trait-reexported-as-not-doc-visible-a.rs
3+
4+
pub struct Bar;
5+
6+
impl __DocHidden::Foo for Bar {
7+
fn foo() {}
8+
}
9+
10+
#[doc(hidden)]
11+
pub mod __DocHidden {
12+
pub use suggest_trait_reexported_as_not_doc_visible_a::Foo;
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//@ edition: 2021
2+
//@ aux-crate:suggest_trait_reexported_as_not_doc_visible_a=suggest-trait-reexported-as-not-doc-visible-a.rs
3+
//@ aux-crate:suggest_trait_reexported_as_not_doc_visible_b=suggest-trait-reexported-as-not-doc-visible-b.rs
4+
5+
use suggest_trait_reexported_as_not_doc_visible_b::Bar;
6+
7+
fn main() {
8+
Bar::foo();
9+
//~^ ERROR: no function or associated item named `foo` found for struct `Bar` in the current scope [E0599]
10+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0599]: no function or associated item named `foo` found for struct `Bar` in the current scope
2+
--> $DIR/suggest-trait-reexported-as-not-doc-visible.rs:8:10
3+
|
4+
LL | Bar::foo();
5+
| ^^^ function or associated item not found in `Bar`
6+
|
7+
= help: items from traits can only be used if the trait is in scope
8+
help: trait `Foo` which provides `foo` is implemented but not in scope; perhaps you want to import it
9+
|
10+
LL + use suggest_trait_reexported_as_not_doc_visible_b::__DocHidden::Foo;
11+
|
12+
13+
error: aborting due to 1 previous error
14+
15+
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)