Skip to content

rustdoc fails to properly resolve Self in a submodule when the type is not in scope  #84827

Open
@de-vri-es

Description

@de-vri-es

When a doc comment refers to Self inside an impl block for a type that is not in scope, rustdoc can't properly resolve Self.

It does resolve Self to a more specific name (Foo in the example below), but then it can't find that name.

A minimum example:

struct Foo {
	foo: i32,
}

mod bar {
	impl crate::Foo {
		/// Baz the [`Self::foo`].
		pub fn baz(&self) {
			println!("bazzing the foo");
		}
	}
}

This produces a broken link in the documentation and the following warning:

$ cargo doc
 Documenting foo v0.1.0 (/tmp/2021-05-02-18-45-24/foo)
warning: unresolved link to `Foo::foo`
 --> src/main.rs:7:16
  |
7 |         /// Baz the [`Self::foo`].
  |                      ^^^^^^^^^^^ no item named `Foo` in scope
  |
  = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default

warning: 1 warning emitted

    Finished dev [unoptimized + debuginfo] target(s) in 0.66s

Meta

I tested this using:

  • rustdoc 1.53.0-nightly (42816d6 2021-04-24)
  • rustdoc 1.51.0 (2fd73fa 2021-03-23)

Both show the same problem.

@rustbot modify labels: +A-rustdoc

Metadata

Metadata

Assignees

Labels

A-intra-doc-linksArea: Intra-doc links, the ability to link to items in docs by nameC-bugCategory: This is a bug.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions