Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1894,6 +1894,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
other: bool,
param_env: ty::ParamEnv<'tcx>,
) -> bool {
let parent_map = self.tcx.visible_parent_map(());
let alternative_candidates = |def_id: DefId| {
let mut impl_candidates: Vec<_> = self
.tcx
Expand All @@ -1918,7 +1919,21 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
// FIXME(compiler-errors): This could be generalized, both to
// be more granular, and probably look past other `#[fundamental]`
// types, too.
self.tcx.visibility(def.did()).is_accessible_from(body_def_id, self.tcx)
let mut did = def.did();
if self.tcx.visibility(did).is_accessible_from(body_def_id, self.tcx) {
// don't suggest foreign `#[doc(hidden)]` types
if !did.is_local() {
while let Some(parent) = parent_map.get(&did) {
if self.tcx.is_doc_hidden(did) {
return false;
}
did = *parent;
}
}
true
} else {
false
}
} else {
true
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/proc-macro/quote/not-quotable.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ LL | let _ = quote! { $ip };
Cow<'_, T>
Option<T>
Rc<T>
RepInterp<T>
and 25 others
bool
and 24 others

error: aborting due to 1 previous error

Expand Down
26 changes: 22 additions & 4 deletions tests/ui/suggestions/auxiliary/hidden-struct.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
// `Foo` and `Bar` should not be suggested in diagnostics of dependents

#[doc(hidden)]
pub mod hidden {
pub struct Foo;
}

pub mod hidden1 {
#[doc(hidden)]
pub struct Foo;
pub struct Bar;
}

// `Baz` and `Quux` *should* be suggested in diagnostics of dependents

#[doc(hidden)]
pub(crate) mod hidden2 {
pub struct Bar;
pub mod hidden2 {
pub struct Baz;
}

pub use hidden2::Baz;

#[doc(hidden)]
pub(crate) mod hidden3 {
pub struct Quux;
}

pub use hidden2::Bar;
pub use hidden3::Quux;

pub trait Marker {}

impl Marker for Option<u32> {}
impl Marker for hidden::Foo {}
impl Marker for hidden1::Bar {}
impl Marker for Baz {}
impl Marker for Quux {}
18 changes: 15 additions & 3 deletions tests/ui/suggestions/dont-suggest-foreign-doc-hidden.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@ aux-build:hidden-struct.rs
//@ compile-flags: --crate-type lib

extern crate hidden_struct;

Expand All @@ -9,7 +8,20 @@ mod local {
}

pub fn test(_: Foo) {}
//~^ ERROR cannot find type `Foo` in this scope
//~^ ERROR [E0412]

pub fn test2(_: Bar) {}
//~^ ERROR cannot find type `Bar` in this scope
//~^ ERROR [E0412]

pub fn test3(_: Baz) {}
//~^ ERROR [E0412]

pub fn test4(_: Quux) {}
//~^ ERROR [E0412]

fn test5<T: hidden_struct::Marker>() {}

fn main() {
test5::<i32>();
//~^ ERROR [E0277]
}
44 changes: 39 additions & 5 deletions tests/ui/suggestions/dont-suggest-foreign-doc-hidden.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0412]: cannot find type `Foo` in this scope
--> $DIR/dont-suggest-foreign-doc-hidden.rs:11:16
--> $DIR/dont-suggest-foreign-doc-hidden.rs:10:16
|
LL | pub fn test(_: Foo) {}
| ^^^ not found in this scope
Expand All @@ -10,16 +10,50 @@ LL + use local::Foo;
|

error[E0412]: cannot find type `Bar` in this scope
--> $DIR/dont-suggest-foreign-doc-hidden.rs:14:17
--> $DIR/dont-suggest-foreign-doc-hidden.rs:13:17
|
LL | pub fn test2(_: Bar) {}
| ^^^ not found in this scope

error[E0412]: cannot find type `Baz` in this scope
--> $DIR/dont-suggest-foreign-doc-hidden.rs:16:17
|
LL | pub fn test3(_: Baz) {}
| ^^^ not found in this scope
|
help: consider importing this struct
|
LL + use hidden_struct::Bar;
LL + use hidden_struct::Baz;
|

error[E0412]: cannot find type `Quux` in this scope
--> $DIR/dont-suggest-foreign-doc-hidden.rs:19:17
|
LL | pub fn test4(_: Quux) {}
| ^^^^ not found in this scope
|
help: consider importing this struct
|
LL + use hidden_struct::Quux;
|

error[E0277]: the trait bound `i32: Marker` is not satisfied
--> $DIR/dont-suggest-foreign-doc-hidden.rs:25:13
|
LL | test5::<i32>();
| ^^^ the trait `Marker` is not implemented for `i32`
|
= help: the following other types implement trait `Marker`:
Baz
Option<u32>
Quux
note: required by a bound in `test5`
--> $DIR/dont-suggest-foreign-doc-hidden.rs:22:13
|
LL | fn test5<T: hidden_struct::Marker>() {}
| ^^^^^^^^^^^^^^^^^^^^^ required by this bound in `test5`

error: aborting due to 2 previous errors
error: aborting due to 5 previous errors

For more information about this error, try `rustc --explain E0412`.
Some errors have detailed explanations: E0277, E0412.
For more information about an error, try `rustc --explain E0277`.
Loading