Skip to content
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

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

Open
Fulgen301 opened this issue Jan 21, 2025 · 0 comments
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@Fulgen301
Copy link
Contributor

Fulgen301 commented Jan 21, 2025

#[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)).

@Fulgen301 Fulgen301 added the C-bug Category: This is a bug. label Jan 21, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 21, 2025
@Fulgen301 Fulgen301 changed the title rustdoc's automatic link suggestion is invalid syntax when the link is in a #[doc] attribute rustdoc's automatic link suggestion is syntactically invalid when the link is in a #[doc] attribute Jan 21, 2025
@fmease fmease added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. C-bug Category: This is a bug. labels Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants