Skip to content

Respect doc(hidden) when suggesting available fields #93214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1794,6 +1794,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.1;
field.vis.is_accessible_from(def_scope, self.tcx)
})
.filter(|field| !self.tcx.is_doc_hidden(field.did))
.map(|field| field.name)
.collect()
}
Expand Down
24 changes: 24 additions & 0 deletions src/test/ui/did_you_mean/issue-93210-ignore-doc-hidden.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#[derive(Default)]
pub struct A {
#[doc(hidden)]
pub hello: i32,
pub bye: i32,
}

#[derive(Default)]
pub struct B {
pub hello: i32,
pub bye: i32,
}

fn main() {
A::default().hey;
Comment on lines +14 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fn main() {
A::default().hey;
fn main() {
A::default().hallo;
A::default().hey;

.hallo may trigger similarly-named field suggestions, which may also be interesting behavior to test

//~^ ERROR no field `hey` on type `A`
//~| NOTE unknown field
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why this note is needed, it doesn't show up in the stderr output 🤔

//~| NOTE available fields are: `bye`

B::default().hey;
//~^ ERROR no field `hey` on type `B`
//~| NOTE unknown field
//~| NOTE available fields are: `hello`, `bye`
}
19 changes: 19 additions & 0 deletions src/test/ui/did_you_mean/issue-93210-ignore-doc-hidden.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0609]: no field `hey` on type `A`
--> $DIR/issue-93210-ignore-doc-hidden.rs:15:18
|
LL | A::default().hey;
| ^^^ unknown field
|
= note: available fields are: `bye`

error[E0609]: no field `hey` on type `B`
--> $DIR/issue-93210-ignore-doc-hidden.rs:20:18
|
LL | B::default().hey;
| ^^^ unknown field
|
= note: available fields are: `hello`, `bye`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0609`.