Skip to content

Cargo doc spuriously links to random enum variant fields instead of marking links broken #107903

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

Closed
tnull opened this issue Feb 10, 2023 · 3 comments · Fixed by #107912
Closed
Labels
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. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. 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

@tnull
Copy link

tnull commented Feb 10, 2023

Problem

In lightningdevkit/rust-lightning#2027 we stumbled across a bug in cargo doc, as it checking for broken links didn't work for a now renamed field that is also present in another enum variant.

Steps

A minimal example is this, which doesn't fail, but should:

#![deny(broken_intra_doc_links)]

/// Referring to [`TestEnum::Variant1::field_name`]
pub enum TestEnum {
	Variant1 {},
	Variant2 {
		field_name: u64,
	}
}

If TestEnum::Variant1::field_name is present the docs indeed link to the right variant. If it is missing, cargo doc gladly makes the TestEnum::Variant1::field_name link point to TestEnum::Variant2::field_name, without throwing an error.

Possible Solution(s)

No response

Notes

No response

Version

> cargo --version
cargo 1.65.0 (4bc8f24d3 2022-10-20)
@tnull tnull added the C-bug Category: This is a bug. label Feb 10, 2023
@ehuss ehuss transferred this issue from rust-lang/cargo Feb 10, 2023
@ehuss
Copy link
Contributor

ehuss commented Feb 10, 2023

Transferred to rust-lang/rust, as rustdoc issues are tracked here.

@ehuss ehuss added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name labels Feb 10, 2023
@jyn514
Copy link
Member

jyn514 commented Feb 10, 2023

if let Some(field) = def.all_fields().find(|f| f.name == variant_field_name) {
probably needs to consider variant_name, not just variant_field_name and path.

@jyn514 jyn514 added the E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. label Feb 10, 2023
@jyn514
Copy link
Member

jyn514 commented Feb 10, 2023

https://doc.rust-lang.org/stable/nightly-rustc/rustc_middle/ty/adt/struct.AdtDef.html#method.variant_with_id is likely what you want and from there you can iterate variant.fields.

@jyn514 jyn514 added the E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. label Feb 10, 2023
@bors bors closed this as completed in c8614a7 Feb 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. 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.

3 participants