Skip to content

Commit

Permalink
expand: fix minor diagnostics bug
Browse files Browse the repository at this point in the history
The error mentions `///`, when it's actually `//!`:

error[E0658]: attributes on expressions are experimental
 --> test.rs:4:9
  |
4 |         //! wah
  |         ^^^^^^^
  |
  = note: see issue rust-lang#15701 <rust-lang#15701> for more information
  = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
  = help: `///` is for documentation comments. For a plain comment, use `//`.
  • Loading branch information
Xiretza committed Apr 22, 2024
1 parent c649c6c commit bfacfe2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion compiler/rustc_expand/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,11 @@ impl<'a> StripUnconfigured<'a> {
);

if attr.is_doc_comment() {
err.help("`///` is for documentation comments. For a plain comment, use `//`.");
err.help(if attr.style == AttrStyle::Outer {
"`///` is used for outer documentation comments; for a plain comment, use `//`"
} else {
"`//!` is used for inner documentation comments; for a plain comment, use `//` by removing the `!` or inserting a space in between them: `// !`"
});
}

err.emit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ LL | /// foo
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= help: `///` is for documentation comments. For a plain comment, use `//`.
= help: `///` is used for outer documentation comments; for a plain comment, use `//`

error[E0658]: attributes on expressions are experimental
--> $DIR/feature-gate-stmt_expr_attributes.rs:10:5
Expand All @@ -28,7 +28,7 @@ LL | //! foo
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= help: `///` is for documentation comments. For a plain comment, use `//`.
= help: `//!` is used for inner documentation comments; for a plain comment, use `//` by removing the `!` or inserting a space in between them: `// !`

error: aborting due to 3 previous errors

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/lint/unused/unused-doc-comments-edge-cases.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ LL | /// useless doc comment
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= help: `///` is for documentation comments. For a plain comment, use `//`.
= help: `///` is used for outer documentation comments; for a plain comment, use `//`

error: unused doc comment
--> $DIR/unused-doc-comments-edge-cases.rs:6:9
Expand Down

0 comments on commit bfacfe2

Please sign in to comment.