Skip to content

Commit 32ab0b8

Browse files
committed
respect doc(hidden) when suggesting available fields
1 parent cbaeec1 commit 32ab0b8

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

compiler/rustc_typeck/src/check/expr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1794,6 +1794,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17941794
.1;
17951795
field.vis.is_accessible_from(def_scope, self.tcx)
17961796
})
1797+
.filter(|field| !self.tcx.is_doc_hidden(field.did))
17971798
.map(|field| field.name)
17981799
.collect()
17991800
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#[derive(Default)]
2+
pub struct A {
3+
#[doc(hidden)]
4+
pub hello: i32,
5+
pub bye: i32,
6+
}
7+
8+
#[derive(Default)]
9+
pub struct B {
10+
pub hello: i32,
11+
pub bye: i32,
12+
}
13+
14+
fn main() {
15+
A::default().hey;
16+
//~^ ERROR no field `hey` on type `A`
17+
//~| NOTE unknown field
18+
//~| NOTE available fields are: `bye`
19+
20+
B::default().hey;
21+
//~^ ERROR no field `hey` on type `B`
22+
//~| NOTE unknown field
23+
//~| NOTE available fields are: `hello`, `bye`
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0609]: no field `hey` on type `A`
2+
--> $DIR/issue-93210-ignore-doc-hidden.rs:15:18
3+
|
4+
LL | A::default().hey;
5+
| ^^^ unknown field
6+
|
7+
= note: available fields are: `bye`
8+
9+
error[E0609]: no field `hey` on type `B`
10+
--> $DIR/issue-93210-ignore-doc-hidden.rs:20:18
11+
|
12+
LL | B::default().hey;
13+
| ^^^ unknown field
14+
|
15+
= note: available fields are: `hello`, `bye`
16+
17+
error: aborting due to 2 previous errors
18+
19+
For more information about this error, try `rustc --explain E0609`.

0 commit comments

Comments
 (0)