Skip to content
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

rustdoc prints <unknown> as name of crate root #83365

Closed
camelid opened this issue Mar 22, 2021 · 2 comments · Fixed by #83399
Closed

rustdoc prints <unknown> as name of crate root #83365

camelid opened this issue Mar 22, 2021 · 2 comments · Fixed by #83399
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name C-bug Category: This is a bug. D-papercut Diagnostics: An error or lint that needs small tweaks. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@camelid
Copy link
Member

camelid commented Mar 22, 2021

//! [my_module]

mod my_module {}
warning: public documentation for `<unknown>` links to private item `my_module`
 --> foo.rs:1:6
  |
1 | //! [my_module]
  |      ^^^^^^^^^ this item is private
  |
  = note: `#[warn(private_intra_doc_links)]` on by default
  = note: this link will resolve properly if you pass `--document-private-items`

warning: 1 warning emitted

It should say foo instead.

@camelid camelid added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-papercut Diagnostics: An error or lint that needs small tweaks. labels Mar 22, 2021
@camelid camelid self-assigned this Mar 22, 2021
@jyn514 jyn514 added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name labels Mar 22, 2021
@jyn514
Copy link
Member

jyn514 commented Mar 22, 2021

Relevant code:

fn privacy_error(cx: &DocContext<'_>, item: &Item, path_str: &str, dox: &str, link: &MarkdownLink) {
let sym;
let item_name = match item.name {
Some(name) => {
sym = name.as_str();
&*sym
}
None => "<unknown>",
};

crate fn visit(mut self, krate: &'tcx hir::Crate<'_>) -> Module<'tcx> {
let mut top_level_module = self.visit_mod_contents(
krate.item.span,
&Spanned { span: rustc_span::DUMMY_SP, node: hir::VisibilityKind::Public },
hir::CRATE_HIR_ID,
&krate.item.module,
None,
);

I think the fix is to use the crate name instead of None.

@jyn514 jyn514 added the E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. label Mar 22, 2021
@jyn514
Copy link
Member

jyn514 commented Mar 22, 2021

Also, I would be curious to see if you can remove Module::name altogether by using tcx.item_name:

let what_rustc_thinks = Item::from_hir_id_and_parts(
self.id,
self.name,
ModuleItem(Module { is_crate: self.is_crate, items }),
cx,
);
. That might break renamed modules maybe? I don't remember how modules interact with re-exports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name C-bug Category: This is a bug. D-papercut Diagnostics: An error or lint that needs small tweaks. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants