Skip to content

Dont strip const blocks in array lengths#152234

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
BoxyUwU:dont_strip_const_blocks
Feb 7, 2026
Merged

Dont strip const blocks in array lengths#152234
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
BoxyUwU:dont_strip_const_blocks

Conversation

@BoxyUwU
Copy link
Member

@BoxyUwU BoxyUwU commented Feb 6, 2026

r? oli-obk

mGCA now handles const blocks by always handling them during lower_expr_to_const_arg_direct instead of sometimes stripping them out at parse time. This is just generally a lot clearer/nicer but also means parsing isn't lossy which is just straight up wrong.

We now use MgcaDisambiguation::Direct for const blocks because we "directly" represent a const block as hir::ConstArgKind::Anon :> The only time that an anon const for const generics uses MgcaDisambiguation::AnonConst is for unbraced literals.

Once we properly support literals in hir::ConstArgKind (see #152139 #152001) then MgcaDisambiguation can be renamed to AnonConstKind with TypeSystem and NonTypeSystem variants. We can also get rid of mgca_direct_lit_hack. I expect this to be a very nice cleanup :)

Fixes rust-lang/rustfmt#6788

The diff relating to passing spans around is to avoid a bunch of mGCA diagnostics changing from const {} to {}. I'm not entirely sure why this was happening.

cc @rust-lang/rustfmt

How do I run the tests in the rustfmt repo from here? x test rustfmt only seems to run like 100 tests and doesn't result in a target/issue-6788.rs getting created. I've verified locally that this formats correctly though

@rustbot
Copy link
Collaborator

rustbot commented Feb 6, 2026

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue. labels Feb 6, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 6, 2026

oli-obk is not on the review rotation at the moment.
They may take a while to respond.

@BoxyUwU
Copy link
Member Author

BoxyUwU commented Feb 6, 2026

I don't think this should be beta backported to fix rustfmt so I'm going to file a separate PR for that

@rust-log-analyzer

This comment has been minimized.

@oli-obk
Copy link
Contributor

oli-obk commented Feb 6, 2026

r=me with CI green

@BoxyUwU

This comment was marked as outdated.

@rust-bors

This comment was marked as outdated.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 6, 2026
@BoxyUwU

This comment was marked as outdated.

@rust-bors rust-bors bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 6, 2026
@BoxyUwU BoxyUwU force-pushed the dont_strip_const_blocks branch from 545ceb7 to a86cfbb Compare February 6, 2026 19:36
@BoxyUwU
Copy link
Member Author

BoxyUwU commented Feb 6, 2026

@bors r=oli-obk

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 6, 2026

📌 Commit a86cfbb has been approved by oli-obk

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 6, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 6, 2026
…=oli-obk

Dont strip const blocks in array lengths

r? oli-obk

mGCA now handles const blocks by *always* handling them during `lower_expr_to_const_arg_direct` instead of *sometimes* stripping them out at parse time. This is just generally a lot clearer/nicer but also means parsing isn't lossy which is just straight up wrong.

We now use `MgcaDisambiguation::Direct` for const blocks because we "directly" represent a const block as `hir::ConstArgKind::Anon` :> The only time that an anon const for const generics uses `MgcaDisambiguation::AnonConst` is for unbraced literals.

Once we properly support literals in `hir::ConstArgKind` (see rust-lang#152139 rust-lang#152001) then `MgcaDisambiguation` can be renamed to `AnonConstKind` with `TypeSystem` and `NonTypeSystem` variants. We can also get rid of `mgca_direct_lit_hack`. I expect this to be a very nice cleanup :)

Fixes rust-lang/rustfmt#6788

The diff relating to passing spans around is to avoid a bunch of mGCA diagnostics changing from  `const {}` to `{}`. I'm not entirely sure why this was happening.

cc @rust-lang/rustfmt

How do I run the tests in the rustfmt repo from here? `x test rustfmt` only seems to run like 100 tests and doesn't result in a `target/issue-6788.rs` getting created. I've verified locally that this formats correctly though
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 6, 2026
…=oli-obk

Dont strip const blocks in array lengths

r? oli-obk

mGCA now handles const blocks by *always* handling them during `lower_expr_to_const_arg_direct` instead of *sometimes* stripping them out at parse time. This is just generally a lot clearer/nicer but also means parsing isn't lossy which is just straight up wrong.

We now use `MgcaDisambiguation::Direct` for const blocks because we "directly" represent a const block as `hir::ConstArgKind::Anon` :> The only time that an anon const for const generics uses `MgcaDisambiguation::AnonConst` is for unbraced literals.

Once we properly support literals in `hir::ConstArgKind` (see rust-lang#152139 rust-lang#152001) then `MgcaDisambiguation` can be renamed to `AnonConstKind` with `TypeSystem` and `NonTypeSystem` variants. We can also get rid of `mgca_direct_lit_hack`. I expect this to be a very nice cleanup :)

Fixes rust-lang/rustfmt#6788

The diff relating to passing spans around is to avoid a bunch of mGCA diagnostics changing from  `const {}` to `{}`. I'm not entirely sure why this was happening.

cc @rust-lang/rustfmt

How do I run the tests in the rustfmt repo from here? `x test rustfmt` only seems to run like 100 tests and doesn't result in a `target/issue-6788.rs` getting created. I've verified locally that this formats correctly though
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 6, 2026
…=oli-obk

Dont strip const blocks in array lengths

r? oli-obk

mGCA now handles const blocks by *always* handling them during `lower_expr_to_const_arg_direct` instead of *sometimes* stripping them out at parse time. This is just generally a lot clearer/nicer but also means parsing isn't lossy which is just straight up wrong.

We now use `MgcaDisambiguation::Direct` for const blocks because we "directly" represent a const block as `hir::ConstArgKind::Anon` :> The only time that an anon const for const generics uses `MgcaDisambiguation::AnonConst` is for unbraced literals.

Once we properly support literals in `hir::ConstArgKind` (see rust-lang#152139 rust-lang#152001) then `MgcaDisambiguation` can be renamed to `AnonConstKind` with `TypeSystem` and `NonTypeSystem` variants. We can also get rid of `mgca_direct_lit_hack`. I expect this to be a very nice cleanup :)

Fixes rust-lang/rustfmt#6788

The diff relating to passing spans around is to avoid a bunch of mGCA diagnostics changing from  `const {}` to `{}`. I'm not entirely sure why this was happening.

cc @rust-lang/rustfmt

How do I run the tests in the rustfmt repo from here? `x test rustfmt` only seems to run like 100 tests and doesn't result in a `target/issue-6788.rs` getting created. I've verified locally that this formats correctly though
rust-bors bot pushed a commit that referenced this pull request Feb 6, 2026
…uwer

Rollup of 5 pull requests

Successful merges:

 - #149960 (add `unreachable_cfg_select_predicates` lint)
 - #152126 (Convert to inline diagnostics in `rustc_mir_build`)
 - #152186 (Convert to inline diagnostics in `rustc_const_eval`)
 - #152234 (Dont strip const blocks in array lengths)
 - #152243 (Use relative paths for std links in rustc-docs)
rust-bors bot pushed a commit that referenced this pull request Feb 7, 2026
…uwer

Rollup of 4 pull requests

Successful merges:

 - #152126 (Convert to inline diagnostics in `rustc_mir_build`)
 - #152186 (Convert to inline diagnostics in `rustc_const_eval`)
 - #152234 (Dont strip const blocks in array lengths)
 - #152243 (Use relative paths for std links in rustc-docs)
rust-bors bot pushed a commit that referenced this pull request Feb 7, 2026
…uwer

Rollup of 4 pull requests

Successful merges:

 - #152126 (Convert to inline diagnostics in `rustc_mir_build`)
 - #152186 (Convert to inline diagnostics in `rustc_const_eval`)
 - #152234 (Dont strip const blocks in array lengths)
 - #152243 (Use relative paths for std links in rustc-docs)
@rust-bors rust-bors bot merged commit 98ae26c into rust-lang:main Feb 7, 2026
11 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Feb 7, 2026
rust-timer added a commit that referenced this pull request Feb 7, 2026
Rollup merge of #152234 - BoxyUwU:dont_strip_const_blocks, r=oli-obk

Dont strip const blocks in array lengths

r? oli-obk

mGCA now handles const blocks by *always* handling them during `lower_expr_to_const_arg_direct` instead of *sometimes* stripping them out at parse time. This is just generally a lot clearer/nicer but also means parsing isn't lossy which is just straight up wrong.

We now use `MgcaDisambiguation::Direct` for const blocks because we "directly" represent a const block as `hir::ConstArgKind::Anon` :> The only time that an anon const for const generics uses `MgcaDisambiguation::AnonConst` is for unbraced literals.

Once we properly support literals in `hir::ConstArgKind` (see #152139 #152001) then `MgcaDisambiguation` can be renamed to `AnonConstKind` with `TypeSystem` and `NonTypeSystem` variants. We can also get rid of `mgca_direct_lit_hack`. I expect this to be a very nice cleanup :)

Fixes rust-lang/rustfmt#6788

The diff relating to passing spans around is to avoid a bunch of mGCA diagnostics changing from  `const {}` to `{}`. I'm not entirely sure why this was happening.

cc @rust-lang/rustfmt

How do I run the tests in the rustfmt repo from here? `x test rustfmt` only seems to run like 100 tests and doesn't result in a `target/issue-6788.rs` getting created. I've verified locally that this formats correctly though
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression in 1.94.0 beta: Rustfmt produces broken code for const blocks in array lengths

4 participants