Skip to content

Commit 985befe

Browse files
authoredMar 9, 2024
Rollup merge of #122160 - jieyouxu:eager-translate-help-use-latest-edition, r=cjgillot
Eagerly translate `HelpUseLatestEdition` in parser diagnostics Fixes #122130. This makes me suspicious of these other two usage of `add_to_diagnostic()`. Would they *also* crash? I haven't attempted to construct test cases for them. ``` compiler/rustc_parse/src/parser/expr.rs 3453: errors::HelpUseLatestEdition::new().add_to_diagnostic(e); compiler/rustc_hir_typeck/src/expr.rs 2603: HelpUseLatestEdition::new().add_to_diagnostic(&mut err); ``` This also seems like a footgun?
2 parents a979f97 + 4663fbb commit 985befe

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed
 

‎compiler/rustc_parse/src/parser/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ impl<'a> Parser<'a> {
667667
{
668668
err.note("you may be trying to write a c-string literal");
669669
err.note("c-string literals require Rust 2021 or later");
670-
HelpUseLatestEdition::new().add_to_diagnostic(&mut err);
670+
err.subdiagnostic(self.dcx(), HelpUseLatestEdition::new());
671671
}
672672

673673
// `pub` may be used for an item or `pub(crate)`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
enum will {
2+
s#[c"owned_box"]
3+
//~^ERROR expected one of `(`, `,`, `=`, `{`, or `}`, found `#`
4+
//~|ERROR expected item, found `"owned_box"`
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error: expected one of `(`, `,`, `=`, `{`, or `}`, found `#`
2+
--> $DIR/help-set-edition-ice-122130.rs:2:6
3+
|
4+
LL | s#[c"owned_box"]
5+
| ^ expected one of `(`, `,`, `=`, `{`, or `}`
6+
|
7+
= note: you may be trying to write a c-string literal
8+
= note: c-string literals require Rust 2021 or later
9+
= help: pass `--edition 2021` to `rustc`
10+
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
11+
12+
error: expected item, found `"owned_box"`
13+
--> $DIR/help-set-edition-ice-122130.rs:2:9
14+
|
15+
LL | s#[c"owned_box"]
16+
| ^^^^^^^^^^^ expected item
17+
|
18+
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
19+
20+
error: aborting due to 2 previous errors
21+

0 commit comments

Comments
 (0)
Please sign in to comment.