Skip to content

Commit a05b7eb

Browse files
Don’t suggest foreign doc(hidden) types in E0277 diagnostics
1 parent a454fcc commit a05b7eb

File tree

5 files changed

+94
-15
lines changed

5 files changed

+94
-15
lines changed

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1894,6 +1894,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
18941894
other: bool,
18951895
param_env: ty::ParamEnv<'tcx>,
18961896
) -> bool {
1897+
let parent_map = self.tcx.visible_parent_map(());
18971898
let alternative_candidates = |def_id: DefId| {
18981899
let mut impl_candidates: Vec<_> = self
18991900
.tcx
@@ -1918,7 +1919,21 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
19181919
// FIXME(compiler-errors): This could be generalized, both to
19191920
// be more granular, and probably look past other `#[fundamental]`
19201921
// types, too.
1921-
self.tcx.visibility(def.did()).is_accessible_from(body_def_id, self.tcx)
1922+
let mut did = def.did();
1923+
if self.tcx.visibility(did).is_accessible_from(body_def_id, self.tcx) {
1924+
// don't suggest foreign `#[doc(hidden)]` types
1925+
if !did.is_local() {
1926+
while let Some(parent) = parent_map.get(&did) {
1927+
if self.tcx.is_doc_hidden(did) {
1928+
return false;
1929+
}
1930+
did = *parent;
1931+
}
1932+
}
1933+
true
1934+
} else {
1935+
false
1936+
}
19221937
} else {
19231938
true
19241939
}

tests/ui/proc-macro/quote/not-quotable.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ LL | let _ = quote! { $ip };
1515
Cow<'_, T>
1616
Option<T>
1717
Rc<T>
18-
RepInterp<T>
19-
and 25 others
18+
bool
19+
and 24 others
2020

2121
error: aborting due to 1 previous error
2222

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,35 @@
1+
// `Foo` and `Bar` should not be suggested in diagnostics of dependents
2+
13
#[doc(hidden)]
24
pub mod hidden {
35
pub struct Foo;
46
}
57

68
pub mod hidden1 {
79
#[doc(hidden)]
8-
pub struct Foo;
10+
pub struct Bar;
911
}
1012

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

1215
#[doc(hidden)]
13-
pub(crate) mod hidden2 {
14-
pub struct Bar;
16+
pub mod hidden2 {
17+
pub struct Baz;
18+
}
19+
20+
pub use hidden2::Baz;
21+
22+
#[doc(hidden)]
23+
pub(crate) mod hidden3 {
24+
pub struct Quux;
1525
}
1626

17-
pub use hidden2::Bar;
27+
pub use hidden3::Quux;
28+
29+
pub trait Marker {}
30+
31+
impl Marker for Option<u32> {}
32+
impl Marker for hidden::Foo {}
33+
impl Marker for hidden1::Bar {}
34+
impl Marker for Baz {}
35+
impl Marker for Quux {}
Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@ aux-build:hidden-struct.rs
2-
//@ compile-flags: --crate-type lib
32

43
extern crate hidden_struct;
54

@@ -9,7 +8,20 @@ mod local {
98
}
109

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

1413
pub fn test2(_: Bar) {}
15-
//~^ ERROR cannot find type `Bar` in this scope
14+
//~^ ERROR [E0412]
15+
16+
pub fn tes3(_: Baz) {}
17+
//~^ ERROR [E0412]
18+
19+
pub fn test4(_: Quux) {}
20+
//~^ ERROR [E0412]
21+
22+
fn test5<T: hidden_struct::Marker>() {}
23+
24+
fn main() {
25+
test5::<i32>();
26+
//~^ ERROR [E0277]
27+
}
Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0412]: cannot find type `Foo` in this scope
2-
--> $DIR/dont-suggest-foreign-doc-hidden.rs:11:16
2+
--> $DIR/dont-suggest-foreign-doc-hidden.rs:10:16
33
|
44
LL | pub fn test(_: Foo) {}
55
| ^^^ not found in this scope
@@ -10,16 +10,50 @@ LL + use local::Foo;
1010
|
1111

1212
error[E0412]: cannot find type `Bar` in this scope
13-
--> $DIR/dont-suggest-foreign-doc-hidden.rs:14:17
13+
--> $DIR/dont-suggest-foreign-doc-hidden.rs:13:17
1414
|
1515
LL | pub fn test2(_: Bar) {}
1616
| ^^^ not found in this scope
17+
18+
error[E0412]: cannot find type `Baz` in this scope
19+
--> $DIR/dont-suggest-foreign-doc-hidden.rs:16:16
20+
|
21+
LL | pub fn tes3(_: Baz) {}
22+
| ^^^ not found in this scope
1723
|
1824
help: consider importing this struct
1925
|
20-
LL + use hidden_struct::Bar;
26+
LL + use hidden_struct::Baz;
27+
|
28+
29+
error[E0412]: cannot find type `Quux` in this scope
30+
--> $DIR/dont-suggest-foreign-doc-hidden.rs:19:17
31+
|
32+
LL | pub fn test4(_: Quux) {}
33+
| ^^^^ not found in this scope
34+
|
35+
help: consider importing this struct
36+
|
37+
LL + use hidden_struct::Quux;
38+
|
39+
40+
error[E0277]: the trait bound `i32: Marker` is not satisfied
41+
--> $DIR/dont-suggest-foreign-doc-hidden.rs:25:13
42+
|
43+
LL | test5::<i32>();
44+
| ^^^ the trait `Marker` is not implemented for `i32`
45+
|
46+
= help: the following other types implement trait `Marker`:
47+
Baz
48+
Option<u32>
49+
Quux
50+
note: required by a bound in `test5`
51+
--> $DIR/dont-suggest-foreign-doc-hidden.rs:22:13
2152
|
53+
LL | fn test5<T: hidden_struct::Marker>() {}
54+
| ^^^^^^^^^^^^^^^^^^^^^ required by this bound in `test5`
2255

23-
error: aborting due to 2 previous errors
56+
error: aborting due to 5 previous errors
2457

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

0 commit comments

Comments
 (0)