Skip to content

rustc_has_incoherent_impl breaks rustdoc in subtle ways #161699

Open

Description

@SludgePhD

Code

I tried this code:

/// [`std::io::Error::last_os_error`]
pub struct Strukt;

I expected to see this happen: cargo doc finishes without warnings.

Instead, this happened:

warning: unresolved link to `std::io::Error::last_os_error`
 --> dep/src/lib.rs:3:7
  |
3 | /// [`std::io::Error::last_os_error`].
  |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the struct `Error` has no field or associated item named `last_os_error`
  |
  = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default

warning: `dep` (lib doc) generated 1 warning

Version it worked on

It most recently worked on: 1.97

Version with regression

rustc --version --verbose:

rustc 1.98.0 (88d9e12ae 2026-08-18)
binary: rustc
commit-hash: 88d9e12ae178fab0fb5cc050a94da85685d449ea
commit-date: 2026-08-18
host: x86_64-unknown-linux-gnu
release: 1.98.0
LLVM version: 22.1.8

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Aug 24, 2026
  2. maxdexh commented on Aug 24, 2026

    @maxdexh
    Member

    searched nightlies: from nightly-2026-06-01 to nightly-2026-08-24
    regressed nightly: nightly-2026-06-30
    searched commit range: df6ee90...0966944
    regressed commit: 7fb284d

    bisected with cargo-bisect-rustc v0.6.11

    Host triple: x86_64-unknown-linux-gnu
    Reproduce with:

    cargo bisect-rustc --start=2026-06-01 -- doc 

    Welp, I could have guessed that it came from that
    @rustbot label S-has-bisection T-rustdoc T-libs

  3. added
    S-has-bisectionStatus: A bisection has been found for this issue
    T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    on Aug 24, 2026
  4. clarfonthey commented on Aug 25, 2026

    @clarfonthey
    Contributor

    This honestly feels like a rustdoc bug, not a libs bug, but I may be wrong there. If you check the generated rustdoc for the std crate, this method is present, so…

  5. maxdexh commented on Aug 25, 2026

    @maxdexh
    Member

    My LSP is also fine with it, even when linking to core::io::Error::last_os_error in no_std. If I had to guess, this is an issue with the fact that last_os_error is an incoherent inherent impl that lives in std. Probably the lint is only searching in core, since that's where Error is defined

  6. clarfonthey commented on Aug 25, 2026

    @clarfonthey
    Contributor

    Hmm, are there any other incoherent impls that might be triggered by this, that aren't primitives?

  7. maxdexh commented on Aug 25, 2026

    @maxdexh
    Member

    core::io::Error::other is also affected and is a better example since it has less stuff on it.

    Also affected:

    pub type X = dyn std::error::Error;
    
    /// [`X::downcast`]
    pub struct Strukt;

    @rustbot label -T-libs

  8. removed
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    on Aug 25, 2026
  9. maxdexh commented on Aug 25, 2026

    @maxdexh
    Member

    Yeah it seems to just be any inherent method on a non-primitive type (marked with rustc_allow_incoherent_impl) that's not in the same crate as the type.

    Conveniently, we have alloc::bstr::ByteString::to_string (inherent method, not on ToString) that's also marked with rustc_allow_incoherent_impl for some reason despite living in alloc (like 20 lines below the declaration of ByteString even). It does not give a warning. (ByteStr::to_string does give a warning, as you'd expect)

  10. changed the title [-]Doc links to `std::io::Error::last_os_error` fail to resolve in 1.98[/-] [+]`rustc_has_incoherent_impl` breaks `rustdoc` in subtle ways[/+] on Aug 27, 2026
  11. changed the title [-]`rustc_has_incoherent_impl` breaks `rustdoc` in subtle ways[/-] [+]`rustc_has_incoherent_impl` breaks rustdoc in subtle ways[/+] on Aug 27, 2026
  12. clarfonthey commented on Aug 27, 2026

    @clarfonthey
    Contributor

    @rustbot claim

    Going to try and see if I can fix this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}S-has-bisectionStatus: A bisection has been found for this issueT-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triagingregression-untriagedUntriaged performance or correctness regression.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions