Skip to content

Commit a115ba8

Browse files
committed
Specify how cargo fix will act
Since it had not been discussed, we had left unspecified whether running `cargo fix` would automatically replace fragment specifiers whose behavior had changed with the new fragment specifiers that had been added to preserve the old behavior. However, this is probably the right thing to do, so let's go ahead and specify it. (Thanks to Ralf Jung for asking about this.)
1 parent ee6e943 commit a115ba8

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

text/3531-macro-fragment-policy.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,17 @@ When we have changed the syntax of Rust such that the syntax matched by a fragme
3333

3434
- Add a new fragment specifier that preserves the behavior of the fragment specifier in the last edition. If there is some semantically meaningful name that makes sense to use for this new fragment specifier, we'll use that. Otherwise, we'll use the existing name with the identifier of the last edition added as a suffix.
3535
- Change the behavior of the fragment specifier to match the underlying grammar as of the release of Rust corresponding to first release of the new edition.
36+
- Have `cargo fix` replace all instances of the original fragment specifier in macro matchers with the new one that preserves the old behavior.
3637

37-
For example, suppose that the behavior of the `expr` fragment specifier fell out of sync with the grammar for a Rust [expression][] during Rust 2021 and that Rust 2024 is the next edition. Then in Rust 2024, we would add a new fragment specifier named `expr2021` (assuming no better semantically meaningful name could be found) that would preserve the behavior `expr` had in Rust 2021, and we would change the behavior of `expr` to match the underlying grammar.
38+
For example, suppose that the behavior of the `expr` fragment specifier fell out of sync with the grammar for a Rust [expression][] during Rust 2021 and that Rust 2024 is the next edition. Then in Rust 2024, we would add a new fragment specifier named `expr2021` (assuming no better semantically meaningful name could be found) that would preserve the behavior `expr` had in Rust 2021, we would change the behavior of `expr` to match the underlying grammar, and we would have `cargo fix` replace all instances of `expr` fragment specifiers with `expr2021`.
3839

3940
# Alternatives
4041

4142
## Keep the old, add specifiers for the new
4243

4344
Changing the behavior of existing fragment specifiers, even over an edition, has an obvious cost: we may change the meaning of existing macros and consequently change the code that they generate.
4445

45-
One way to mitigate this would be for `cargo fix` to replace all instances of a changed fragment specifier with the new fragment specifier added for backward compatibility. But that has some cost in terms of code churn.
46+
Having `cargo fix` replace all instances of a changed fragment specifier with the new fragment specifier added for backward compatibility does mitigate this. But that has some cost in terms of code churn.
4647

4748
Another alternative would be to *never* change the meaning of existing fragment specifiers. Instead, when changing the grammar of Rust, we would add *new* fragment specifiers that would correspond with this new grammar. We would not have to wait for new editions to add these. We could add, e.g., `expr2023_11`, `expr2023_12`, etc. each time that we change the grammar.
4849

0 commit comments

Comments
 (0)