Skip to content

Commit 8e9eaff

Browse files
committed
Auto merge of rust-lang#123694 - Xiretza:expand-diagnostics, r=compiler-errors
expand: fix minor diagnostics bug 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 `//`. ```
2 parents 1871252 + 3289a9a commit 8e9eaff

File tree

5 files changed

+46
-5
lines changed

5 files changed

+46
-5
lines changed

Diff for: compiler/rustc_expand/messages.ftl

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ expand_attribute_meta_item =
1010
expand_attribute_single_word =
1111
attribute must only be a single word
1212
13+
expand_attributes_on_expressions_experimental =
14+
attributes on expressions are experimental
15+
.help_outer_doc = `///` is used for outer documentation comments; for a plain comment, use `//`
16+
.help_inner_doc = `//!` is used for inner documentation comments; for a plain comment, use `//` by removing the `!` or inserting a space in between them: `// !`
17+
1318
expand_attributes_wrong_form =
1419
attribute must be of form: `attributes(foo, bar)`
1520

Diff for: compiler/rustc_expand/src/config.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,6 @@ impl<'a> StripUnconfigured<'a> {
382382
}
383383

384384
/// If attributes are not allowed on expressions, emit an error for `attr`
385-
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
386385
#[instrument(level = "trace", skip(self))]
387386
pub(crate) fn maybe_emit_expr_attr_err(&self, attr: &Attribute) {
388387
if self.features.is_some_and(|features| !features.stmt_expr_attributes)
@@ -392,11 +391,15 @@ impl<'a> StripUnconfigured<'a> {
392391
&self.sess,
393392
sym::stmt_expr_attributes,
394393
attr.span,
395-
"attributes on expressions are experimental",
394+
crate::fluent_generated::expand_attributes_on_expressions_experimental,
396395
);
397396

398397
if attr.is_doc_comment() {
399-
err.help("`///` is for documentation comments. For a plain comment, use `//`.");
398+
err.help(if attr.style == AttrStyle::Outer {
399+
crate::fluent_generated::expand_help_outer_doc
400+
} else {
401+
crate::fluent_generated::expand_help_inner_doc
402+
});
400403
}
401404

402405
err.emit();
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
const X: i32 = #[allow(dead_code)] 8;
22
//~^ ERROR attributes on expressions are experimental
33

4+
const Y: i32 =
5+
/// foo
6+
//~^ ERROR attributes on expressions are experimental
7+
8;
8+
9+
const Z: i32 = {
10+
//! foo
11+
//~^ ERROR attributes on expressions are experimental
12+
8
13+
};
14+
415
fn main() {}

Diff for: tests/ui/feature-gates/feature-gate-stmt_expr_attributes.stderr

+23-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,28 @@ LL | const X: i32 = #[allow(dead_code)] 8;
88
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
99
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1010

11-
error: aborting due to 1 previous error
11+
error[E0658]: attributes on expressions are experimental
12+
--> $DIR/feature-gate-stmt_expr_attributes.rs:5:5
13+
|
14+
LL | /// foo
15+
| ^^^^^^^
16+
|
17+
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
18+
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
19+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
20+
= help: `///` is used for outer documentation comments; for a plain comment, use `//`
21+
22+
error[E0658]: attributes on expressions are experimental
23+
--> $DIR/feature-gate-stmt_expr_attributes.rs:10:5
24+
|
25+
LL | //! foo
26+
| ^^^^^^^
27+
|
28+
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
29+
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
30+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
31+
= help: `//!` is used for inner documentation comments; for a plain comment, use `//` by removing the `!` or inserting a space in between them: `// !`
32+
33+
error: aborting due to 3 previous errors
1234

1335
For more information about this error, try `rustc --explain E0658`.

Diff for: tests/ui/lint/unused/unused-doc-comments-edge-cases.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LL | (/// useless doc comment
1313
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
1414
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
1515
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
16-
= help: `///` is for documentation comments. For a plain comment, use `//`.
16+
= help: `///` is used for outer documentation comments; for a plain comment, use `//`
1717

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

0 commit comments

Comments
 (0)