cargo-deadlinks icon indicating copy to clipboard operation
cargo-deadlinks copied to clipboard

Broken links when linking to publicly re-exported private items from another crate.

Open Shadow53 opened this issue 3 years ago • 4 comments

I ran into this with miette::Report and miette::Diagnostic, but I believe it is not specific to just miette.

I have a struct defined something like this (simplified):

use miette::{Diagnostic, Report};

/// This implements [`Diagnostic`] and contains a [`Report`].
#[derive(Diagnostic)]
struct MyDiagnostic {
    #[diagnostic_source]
    source: Report,
}

When running cargo deadlinks --check-intra-doc-links, Report and Diagnostic get flagged, as well as Diagnostic::labels and Diagnostic::source_code, where the latter two are linked in echo other's doc strings.

Report and Diagnostic are only publicly accessible at the top level, as shown in the example, but are privately defined at miette::eyreish::Report and miette::protocol::Diagnostic, respectively.

If I view the generated docs, clicking a link takes me to a page that redirects to the correct page, so these links are not actually "broken".

Shadow53 avatar Nov 04 '22 20:11 Shadow53

I can't reproduce this.

; cargo new --lib issue-159
; cd issue-159
; cargo add miette
    Updating crates.io index
      Adding miette v5.5.0 to dependencies.
; cargo deadlinks --check-intra-doc-links
 Documenting issue-159 v0.1.0 (/home/jnelson/rust-community/cargo-deadlinks/issue-159)
    Finished dev [unoptimized + debuginfo] target(s) in 5.43s

jyn514 avatar Nov 27 '22 02:11 jyn514

Did you add a custom struct that derives Diagnostic, as in the example snippet? That's where the error occurs, in the docs for the Diagnostic trait implementation on MyDiagnostic.

Am on mobile, but I can double check with latest cargo-deadlinks in a little bit.

Shadow53 avatar Nov 27 '22 03:11 Shadow53

Yes, like so:

use miette::{Diagnostic, Report};
use std::error::Error;
use std::fmt;

/// This implements [`Diagnostic`] and contains a [`Report`].
#[derive(Diagnostic, Debug)]
struct MyDiagnostic {
    #[diagnostic_source]
    source: Report,
}

impl Error for MyDiagnostic {}
impl fmt::Display for MyDiagnostic {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        todo!()
    }
}

jyn514 avatar Nov 27 '22 03:11 jyn514

I'm able to reproduce with the snippet you mentioned, after changing struct MyDiagnostic to pub struct Diagnostic so that docs are generate for it.

Alternatively:

 cargo deadlinks --check-intra-doc-links -- --document-private-items

Shadow53 avatar Nov 27 '22 06:11 Shadow53