Skip to content

Conversation

@reddevilmidzy
Copy link
Member

@reddevilmidzy reddevilmidzy commented Feb 2, 2026

close: #151625
close: #150983

also fix: #133966 (moved crashes test)

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 2, 2026
@rust-log-analyzer

This comment has been minimized.

@BoxyUwU
Copy link
Member

BoxyUwU commented Feb 4, 2026

very cool :) thanks for working on this

@rust-bors

This comment has been minimized.

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
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 7, 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-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
@rust-log-analyzer

This comment has been minimized.

@reddevilmidzy
Copy link
Member Author

Haha, ICE occurs in other tests...

Copy link
Member Author

@reddevilmidzy reddevilmidzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your quick review. 😊

View changes since this review

@rust-log-analyzer

This comment has been minimized.

Copy link
Member Author

@reddevilmidzy reddevilmidzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In ten crash tests, the ICE disappeared; however, in tests/crashes/117460.rs, tests/crashes/114212-2.rs and tests/crashes/114212.rs, adding the main function caused the ICE to occur again.

View changes since this review

@@ -0,0 +1,23 @@
//! Regression test for <https://github.com/rust-lang/rust/issues/116554>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This issue was closed; is there a need to add further testing?

Copy link
Member

@BoxyUwU BoxyUwU Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsure, I will look over all the GCE tests (outside of this PR) at some point soon and see which ones are worth keeping

@reddevilmidzy
Copy link
Member Author

reddevilmidzy commented Feb 8, 2026

Could the following issues also be closed? 🤔

#119824
#133966
#136416

already closed
#94846
#106473
#116554

@rust-log-analyzer

This comment has been minimized.

@BoxyUwU
Copy link
Member

BoxyUwU commented Feb 8, 2026

cool! sorry for a lot of comments but this is looking really good :)

@reddevilmidzy
Copy link
Member Author

In my current code, an ICE will occur in the tests/ui/const-generics/generic_const_exprs/lit_type_mismatch.rs test.

Looking at the stacktrace and log, it appears that after returning None due to a type mismatch, the path continues without stopping at hir_ty_lowering, which then instantiates the default value. This causes an ICE error as instantiate is called with an empty preceding_args.

How would you recommend handling this situation?

@reddevilmidzy
Copy link
Member Author

cool! sorry for a lot of comments but this is looking really good :)

No worries at all — I really appreciate the detailed feedback. Thanks for taking the time to review (_ _)

@rust-log-analyzer

This comment was marked as duplicate.

9 similar comments
@rust-log-analyzer

This comment was marked as duplicate.

@rust-log-analyzer

This comment was marked as duplicate.

@rust-log-analyzer

This comment was marked as duplicate.

@rust-log-analyzer

This comment was marked as duplicate.

@rust-log-analyzer

This comment was marked as duplicate.

@rust-log-analyzer

This comment was marked as duplicate.

@rust-log-analyzer

This comment was marked as duplicate.

@rust-log-analyzer

This comment was marked as duplicate.

@rust-log-analyzer

This comment has been minimized.

@BoxyUwU
Copy link
Member

BoxyUwU commented Feb 9, 2026

it appears that after returning None due to a type mismatch, the path continues without stopping at hir_ty_lowering, which then instantiates the default value

does it still ICE after removing some of the checks you had for types being equal? If so I'd just remove that test

@rust-bors

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

.map(|l| tcx.at(expr.span).lit_to_const(l))
lit_input.and_then(|l| {
tcx.at(expr.span)
.lit_to_const(l)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we now get a bunch of extra errors I think because this succeeds in more cases and results in duplication between the type checking errors of the anon const this was derived from, and type checking errors for the const arg matching the thing its a parameter to.

I think it would probably make sense (for diagnostics reasons) to do like .filter(|| const_lit_matches_ty()) so that we only do this fast path if the types are ok 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that was the problem!! Added filtering

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and const_lit_matches_ty() is used in two places: compiler/rustc_mir_build/src/thir/pattern/mod.rs and compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs. I was going to create a function for each, but I ended up creating a function in compiler/rustc_middle/src/mir/interpret/mod.rs.

reddevilmidzy and others added 2 commits February 11, 2026 05:01
Co-authored-by: Boxy <rust@boxyuwu.dev>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed tests related to generic_const_args that were causing crashes.

Comment on lines +14 to +25
foo::<{ Foo { field: -1_usize } }>();
//~^ ERROR: type annotations needed for the literal
foo::<{ Foo { field: { -1_usize } } }>();
//~^ ERROR: complex const arguments must be placed inside of a `const` block
foo::<{ Foo { field: -true } }>();
//~^ ERROR: the constant `true` is not of type `isize`
foo::<{ Foo { field: { -true } } }>();
//~^ ERROR: complex const arguments must be placed inside of a `const` block
foo::<{ Foo { field: -"<3" } }>();
//~^ ERROR: the constant `"<3"` is not of type `isize`
foo::<{ Foo { field: { -"<3" } } }>();
//~^ ERROR: complex const arguments must be placed inside of a `const` block
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the test mentioned in #152139.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

4 participants