Skip to content

rustdoc's automatic link suggestion is syntactically invalid when the link is in a #[doc] attribute #135851

Closed
@Fulgen301

Description

@Fulgen301
#[doc = "https://rust-lang.org"]
pub fn doc_attribute() {}

/// https://rust-lang.org
pub fn doc_comment() {}

Running rustdoc on that code produces the following output:

warning: this URL is not a hyperlink
 --> issue.rs:1:9
  |
1 | #[doc = "https://rust-lang.org"]
  |         ^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: bare URLs are not automatically turned into clickable links
  = note: `#[warn(rustdoc::bare_urls)]` on by default
help: use an automatic link instead
  |
1 | #[doc = <"https://rust-lang.org">]
  |         +                       +

warning: this URL is not a hyperlink
 --> issue.rs:4:5
  |
4 | /// https://rust-lang.org
  |     ^^^^^^^^^^^^^^^^^^^^^
  |
  = note: bare URLs are not automatically turned into clickable links
help: use an automatic link instead
  |
4 | /// <https://rust-lang.org>
  |     +                     +

warning: 2 warnings emitted

The replacement suggestion is correct for the link in the doc comment, but syntactically incorrect for the one in the #[doc] attribute - it should suggest #[doc = "<https://rust-lang.org>"] instead.

The bug happens on both stable (rustdoc 1.84.0 (9fc6b4312 2025-01-07)) and nightly (rustdoc 1.86.0-nightly (f3d1d47fd 2025-01-20)).

Metadata

Metadata

Assignees

Labels

A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.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