Skip to content

Conversation

@Keith-Cancel
Copy link
Contributor

@Keith-Cancel Keith-Cancel commented Jan 8, 2026

This commit fixes #148729 for min_const_generic_args #132980.

It's pretty small PR. The first commit makes sure that the type_consts are made into normal consts in const expressions.

The next one just handles the case #148729 of where the type of the const was omitted at which point it was trying to treat a type_const again as a regular const. That obviously will fail since a type_const does not have a body.

@rustbot label +F-associated_const_equality +F-min_generic_const_args +I-ICE

@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. labels Jan 8, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 8, 2026

r? @matthewjasper

rustbot has assigned @matthewjasper.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot

This comment has been minimized.

@rustbot rustbot added F-associated_const_equality `#![feature(associated_const_equality)]` F-min_generic_const_args `#![feature(min_generic_const_args)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Jan 8, 2026
@rust-log-analyzer

This comment has been minimized.

@Keith-Cancel
Copy link
Contributor Author

@matthewjasper are there any other cases that your aware of? I played around a bit with this after making the changes and not coming across any other cases of this exact ICE.

@BoxyUwU Your doing a lot working on min_const_generic_args. So probably want to look this over as well.

@rust-log-analyzer

This comment has been minimized.

@BoxyUwU
Copy link
Member

BoxyUwU commented Jan 8, 2026

r? BoxyUwU

@rustbot rustbot assigned BoxyUwU and unassigned matthewjasper Jan 8, 2026
Copy link
Member

@BoxyUwU BoxyUwU left a comment

Choose a reason for hiding this comment

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

Can you add tests from both of the fixed issues

View changes since this review

Comment on lines 101 to 108
if is_type_const(tcx, def_id) {
let uneval = ty::UnevaluatedConst::new(def_id, args);

let ct = ty::Const::new_unevaluated(tcx, uneval);
let const_ = Const::Ty(ty, ct);
return ConstOperand { user_ty: None, span, const_ };
}

Copy link
Member

Choose a reason for hiding this comment

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

I think type_const can't be applied to const blocks so this should be unnecessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay easy enough, I can remove that.

}
ExprKind::NamedConst { def_id, args, ref user_ty } => {
let user_ty = user_ty.as_ref().and_then(push_cuta);
if is_type_const(tcx, def_id) {
Copy link
Member

Choose a reason for hiding this comment

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

You link the same issue twice in your description, but I think one of them is supposed to be for #150615?

Copy link
Contributor Author

@Keith-Cancel Keith-Cancel Jan 8, 2026

Choose a reason for hiding this comment

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

Sorry, I could have been clearer. I mainly meant I noticed a couple different cases of triggering the span bug check in #148729.

The check:

let body_id = node.body_id().unwrap_or_else(|| {
span_bug!(span, "can't type-check body of {:?}", def_id);
});

I noticed when testing around various permutations of the below I ended up at the same check.

trait BadTr {
    const NUM: usize;
}

struct GoodS;

impl BadTr for GoodS {
    #[type_const]
    const NUM:  = 84;
}

and

#[type_const] const A: u8 = A;

Lastly, looking over that issue you just linked, I think this fixes that too.

@BoxyUwU
Copy link
Member

BoxyUwU commented Jan 8, 2026

are there any other cases that your aware of

on this note it wouldn't surprise me if there are more cases but they can probably all be handled independently (ie different PRs) as each ICE is gonna be a random unrelated part of the compiler which isn't aware of type_consts yet

@programmerjake

This comment was marked as resolved.

@Keith-Cancel
Copy link
Contributor Author

Keith-Cancel commented Jan 8, 2026

Can you add tests from both of the fixed issues

View changes since this review

Sure, I can get to that to this evening.

--Edit--
@BoxyUwU, Wait when you say both issues, are you also talking about that issue you linked to, just to clarify.

@Keith-Cancel
Copy link
Contributor Author

sorry if you already know how to fix it and my instructions are unnecessary, but it looks like you tried to fix the below warning by adding the new commit 6219c73, the issue rustbot is warning you about is in your commit message, not the code you wrote. so you need to rebase and edit the commit's message to fix it. you can do that by running git rebase -i ad34eaac (you can probably also do this using some git guis but I'm not as familiar with them), then changing the pick 58396... line to start with reword instead of pick. If you no longer need 6219c73 then you can also delete the pick 6219c73... line. then just save and exit the editor git ran, it should then start an editor that you can use to change the commit message, which is where you need to remove the #148729 text. once you save and exit you'll need to force push which you can do with git push -f.

⚠️ Warning ⚠️

  • There are issue links (such as #123) in the commit messages of the following commits.
    Please move them to the PR description, to avoid spamming the issues with references to the commit, and so this bot can automatically canonicalize them to avoid issues with subtree.

Ah, okay thanks can do.

@fmease fmease removed the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jan 8, 2026
@matthiaskrgr
Copy link
Member

are there any other cases that your aware of

idk if it helps but here are some of the query-stacks that lead to this ICE while fuzzing for around 5 mins

~/vcs/github/rust_misc_stuff_2/tests/ui/const-generics/mgca on  main [?] via 🦀 v1.94.0-nightly
at 22:06:46 ❯ cat errors_tmp.json| grep error_and | sort -n | uniq -c  | less  | grep type-check | awk 'NF>1{print $NF}'| sort -n | uniq -c
    128 'typeck::check_match::mir_built::trivial_const::eval_to_allocation_raw::eval_to_valtree::check_well_formed::check_type_wf::analysis'",
    109 'typeck::check_match::mir_built::trivial_const::eval_to_allocation_raw::eval_to_valtree::typeck::analysis'",
     41 'typeck::check_match::mir_built::trivial_const::eval_to_const_value_raw::collect_and_partition_mono_items'",
      1 'typeck::check_match::mir_built::trivial_const::eval_to_const_value_raw::collect_and_partition_mono_items::exported_generic_symbols'",

@BoxyUwU
Copy link
Member

BoxyUwU commented Jan 8, 2026

@Keith-Cancel yeah the examples from that issue should be added as tests too since theyre fixed by this PR.

@matthiaskrgr do you have lines from further up the call stack than the eval_ methods?

edit: I've been informed those do go past the eval_ methods 😆

@Keith-Cancel
Copy link
Contributor Author

Keith-Cancel commented Jan 9, 2026

are there any other cases that your aware of

idk if it helps but here are some of the query-stacks that lead to this ICE while fuzzing for around 5 mins

~/vcs/github/rust_misc_stuff_2/tests/ui/const-generics/mgca on  main [?] via 🦀 v1.94.0-nightly
at 22:06:46 ❯ cat errors_tmp.json| grep error_and | sort -n | uniq -c  | less  | grep type-check | awk 'NF>1{print $NF}'| sort -n | uniq -c
    128 'typeck::check_match::mir_built::trivial_const::eval_to_allocation_raw::eval_to_valtree::check_well_formed::check_type_wf::analysis'",
    109 'typeck::check_match::mir_built::trivial_const::eval_to_allocation_raw::eval_to_valtree::typeck::analysis'",
     41 'typeck::check_match::mir_built::trivial_const::eval_to_const_value_raw::collect_and_partition_mono_items'",
      1 'typeck::check_match::mir_built::trivial_const::eval_to_const_value_raw::collect_and_partition_mono_items::exported_generic_symbols'",

@matthewjasper Do you have the code or fuzzing script that generated those ices?

@Keith-Cancel Keith-Cancel force-pushed the mcga branch 2 times, most recently from d9b2fec to 28a7809 Compare January 9, 2026 01:56
@rustbot
Copy link
Collaborator

rustbot commented Jan 9, 2026

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

Some changes occurred to constck

cc @fee1-dead

@rust-log-analyzer

This comment has been minimized.

@Keith-Cancel
Copy link
Contributor Author

Keith-Cancel commented Jan 9, 2026

@BoxyUwU So I added some tests like asked. I also did move the is_type_const() function to some where more central so if it needs updated it's in a central location.

I am curious what the code the fuzzer generated that found some more ICE. Depending on the cause hopefully it is something I can address.

@Keith-Cancel
Copy link
Contributor Author

Keith-Cancel commented Jan 9, 2026

@BoxyUwU So when playing around and experimenting more with mgca with this fix, I did manage to find one more ICE. Before the fix it's ICEs with can't type-check body of DefId, after the fix I got an ICE I did not expect index out of bounds: the len is 0 but the index is 0.

It seems in this case the inherent named const has no args. So I made a slight change instead for #[type_const] ExprKind::NamedConst instead always going to a UnevaluatedConst, if there no args instantiate it instead. This fixes the new ice that I encountered.

Code in question:

#![expect(incomplete_features)]
#![feature(min_generic_const_args)]
pub struct A;

impl A {
    #[type_const]
    const LEN: usize = 4;

    #[allow(unused_braces)]
    fn arr() -> [u8; const { Self::LEN }] {
        return [0u8; const { Self::LEN }];
    }
}

fn main() {
    let _ = A::arr();
}

Comment on lines 75 to 76
let ct = if args.is_empty() {
tcx.const_of_item(def_id).instantiate_identity()
Copy link
Member

Choose a reason for hiding this comment

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

The underlying cause of the ICE you fix by doing this instantiate_identity and no args check is probably that we aren't handling inherent associated consts elsewhere in mGCA. I think we shouldn't handle this here and instead continue letting it ICE and this will get fixed at some point once IACs are handled properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@BoxyUwU Okay easy enough to remove. I do see in #132980

  • Make inherent associated constants behave correctly

However, I don't see any linked issues. Is there a spot I can put the example I found.

Copy link
Member

Choose a reason for hiding this comment

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

I'd file a new issue and label it as min_generic_const_args

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd file a new issue and label it as min_generic_const_args

Can do.

@BoxyUwU Also should I squash my commits and get it ready for a merge, or should I wait to hear from @matthewjasper since it sounds like he may have found some related ICEs?

Copy link
Member

Choose a reason for hiding this comment

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

If you can squash that would be great. I think there is more ICEs here but those can be follow up PRs and I'd like to get these fixes in tree as not being able to use type_consts in HIR bodies is quite a big flaw in the current impl 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you can squash that would be great. I think there is more ICEs here but those can be follow up PRs and I'd like to get these fixes in tree as not being able to use type_consts in HIR bodies is quite a big flaw in the current impl 😅

Yea definitely makes it hard to use type_consts otherwise.

@rustbot
Copy link
Collaborator

rustbot commented Jan 9, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rustbot

This comment has been minimized.

@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 9, 2026
… a body.

Handling for inherent associated consts is missing elsewhere, remove so it can be handled later in that handling.

Diagnostic not always be emitted on associated constant

Add a test case and Fix for a different ICE I encountered.

I noticed when trying various permuations of the test case code to see if I could find anymore ICEs. I did, but not one that I expected. So in the instances of the a named const not having any args, insantiate it directly. Since it is likely an inherent assocaiated const.

Added tests.

Centralize the is_type_const() logic.

I also noticed basically the exact same check in other part the code.

Const blocks can't be a type_const, therefore this check is uneeded.

Fix comment spelling error.

get_all_attrs is not valid to call for all DefIds it seems.

Make sure that if the type is omitted for a type_const that we don't ICE.

Co-Authored-By: Boxy <[email protected]>
@rustbot rustbot removed has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 9, 2026
@Keith-Cancel
Copy link
Contributor Author

@BoxyUwU Not sure if you saw, but I did squash it all too one commit and rebase it to main.

@BoxyUwU
Copy link
Member

BoxyUwU commented Jan 10, 2026

@bors r+ rollup

@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 Jan 10, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 10, 2026

📌 Commit f982bc6 has been approved by BoxyUwU

It is now in the queue for this repository.

Zalathar added a commit to Zalathar/rust that referenced this pull request Jan 10, 2026
Fix ICE: can't type-check body of DefId  for issue rust-lang#148729

This commit fixes the issue rust-lang#148729 for min_const_generic_args rust-lang#132980.

It's pretty small PR. The first commit makes sure that the `type_const`s are made into normal consts in const expressions.

The next one just handles the case rust-lang#148729 of where the type of the const was omitted at which point it was trying to treat a `type_const` again as a regular const. That obviously will fail since a type_const does not have a body.

@rustbot label +F-associated_const_equality +F-min_generic_const_args +I-ICE
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 10, 2026
Fix ICE: can't type-check body of DefId  for issue rust-lang#148729

This commit fixes the issue rust-lang#148729 for min_const_generic_args rust-lang#132980.

It's pretty small PR. The first commit makes sure that the `type_const`s are made into normal consts in const expressions.

The next one just handles the case rust-lang#148729 of where the type of the const was omitted at which point it was trying to treat a `type_const` again as a regular const. That obviously will fail since a type_const does not have a body.

@rustbot label +F-associated_const_equality +F-min_generic_const_args +I-ICE
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jan 10, 2026
Fix ICE: can't type-check body of DefId  for issue rust-lang#148729

This commit fixes the issue rust-lang#148729 for min_const_generic_args rust-lang#132980.

It's pretty small PR. The first commit makes sure that the `type_const`s are made into normal consts in const expressions.

The next one just handles the case rust-lang#148729 of where the type of the const was omitted at which point it was trying to treat a `type_const` again as a regular const. That obviously will fail since a type_const does not have a body.

@rustbot label +F-associated_const_equality +F-min_generic_const_args +I-ICE
rust-bors bot added a commit that referenced this pull request Jan 11, 2026
Rollup of 11 pull requests

Successful merges:

 - #148196 (Implement create_dir_all() to operate iteratively instead of recursively)
 - #150494 ( Fix dso_local for external statics with linkage)
 - #150788 (THIR patterns: Replace `AscribeUserType` and `ExpandedConstant` wrappers with per-node data)
 - #150799 (Fix ICE: can't type-check body of DefId  for issue #148729)
 - #150804 (Remove std_detect_file_io and std_detect_dlsym_getauxval features)
 - #150852 (std: sys: fs: uefi: Implement File::write)
 - #150871 (Use f64 NaN in documentation instead of sqrt(-1.0))
 - #150878 (Emit an error for linking staticlibs on BPF)
 - #150911 (Add missing documentation for globs feature)
 - #150913 (compiler: Forward attributes to eii-expanded macros)
 - #150916 (Once again, reorganize the EII tests a bit)

r? @ghost
rust-bors bot added a commit that referenced this pull request Jan 11, 2026
Rollup of 12 pull requests

Successful merges:

 - #150947 (alloctests: Don't run the longer partial-sort tests under Miri)
 - #148196 (Implement create_dir_all() to operate iteratively instead of recursively)
 - #150494 ( Fix dso_local for external statics with linkage)
 - #150788 (THIR patterns: Replace `AscribeUserType` and `ExpandedConstant` wrappers with per-node data)
 - #150799 (Fix ICE: can't type-check body of DefId  for issue #148729)
 - #150804 (Remove std_detect_file_io and std_detect_dlsym_getauxval features)
 - #150852 (std: sys: fs: uefi: Implement File::write)
 - #150871 (Use f64 NaN in documentation instead of sqrt(-1.0))
 - #150878 (Emit an error for linking staticlibs on BPF)
 - #150911 (Add missing documentation for globs feature)
 - #150913 (compiler: Forward attributes to eii-expanded macros)
 - #150916 (Once again, reorganize the EII tests a bit)

r? @ghost
@rust-bors rust-bors bot merged commit e25d7a8 into rust-lang:main Jan 11, 2026
11 checks passed
@rustbot rustbot added this to the 1.94.0 milestone Jan 11, 2026
rust-timer added a commit that referenced this pull request Jan 11, 2026
Rollup merge of #150799 - mcga, r=BoxyUwU

Fix ICE: can't type-check body of DefId  for issue #148729

This commit fixes #148729 for min_const_generic_args #132980.

It's pretty small PR. The first commit makes sure that the `type_const`s are made into normal consts in const expressions.

The next one just handles the case #148729 of where the type of the const was omitted at which point it was trying to treat a `type_const` again as a regular const. That obviously will fail since a type_const does not have a body.

@rustbot label +F-associated_const_equality +F-min_generic_const_args +I-ICE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-associated_const_equality `#![feature(associated_const_equality)]` F-min_generic_const_args `#![feature(min_generic_const_args)]` 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICE: can't type-check body of DefId

8 participants