Skip to content

Commit ce1bf80

Browse files
committed
Merge PR #315: Add page for missing_fragment_specifier
2 parents b3a034b + 7234b8e commit ce1bf80

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
- [Rustfmt: Combine all delimited exprs as last argument](rust-2024/rustfmt-overflow-delimited-expr.md)
5050
- [`gen` keyword](rust-2024/gen-keyword.md)
5151
- [Macro fragment specifiers](rust-2024/macro-fragment-specifiers.md)
52+
- [Missing macro fragment specifiers](rust-2024/missing-macro-fragment-specifiers.md)
5253
- [Never type fallback change](rust-2024/never-type-fallback.md)
5354
- [`unsafe extern` blocks](rust-2024/unsafe-extern.md)
5455
- [Unsafe attributes](rust-2024/unsafe-attributes.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Missing macro fragment specifiers
2+
3+
🚧 The 2024 Edition has not yet been released and hence this section is still "under construction".
4+
More information may be found in the tracking issue at <https://github.com/rust-lang/rust/issues/128143>.
5+
6+
## Summary
7+
8+
- The [`missing_fragment_specifier`] lint is now a hard error.
9+
10+
[`missing_fragment_specifier`]: ../../rustc/lints/listing/deny-by-default.html#missing-fragment-specifier
11+
12+
## Details
13+
14+
The [`missing_fragment_specifier`] lint detects a situation when an **unused** pattern in a `macro_rules!` macro definition has a meta-variable (e.g. `$e`) that is not followed by a fragment specifier (e.g. `:expr`). This is now a hard error in the 2024 Edition.
15+
16+
```rust,compile_fail
17+
macro_rules! foo {
18+
() => {};
19+
($name) => { }; // ERROR: missing fragment specifier
20+
}
21+
22+
fn main() {
23+
foo!();
24+
}
25+
```
26+
27+
Calling the macro with arguments that would match a rule with a missing specifier (e.g., `foo!($name)`) is a hard error in all editions. However, simply defining a macro with missing fragment specifiers is not, though we did add a lint in Rust 1.17.
28+
29+
We'd like to make this a hard error in all editions, but there would be too much breakage right now. So we're starting by making this a hard error in Rust 2024.[^future-incompat]
30+
31+
[^future-incompat]: The lint is marked as a "future-incompatible" warning to indicate that it may become a hard error in all editions in a future release. See [#40107] for more information.
32+
33+
[#40107]: https://github.com/rust-lang/rust/issues/40107
34+
35+
## Migration
36+
37+
To migrate your code to the 2024 Edition, remove the unused matcher rule from the macro. The [`missing_fragment_specifier`] lint is on by default in all editions, and should alert you to macros with this issue.
38+
39+
There is no automatic migration for this change. We expect that this style of macro is extremely rare. The lint has been a future-incompatibility lint since Rust 1.17, a deny-by-default lint since Rust 1.20, and since Rust 1.82, it has warned about dependencies that are using this pattern.

0 commit comments

Comments
 (0)