Skip to content

Conversation

@InvalidPathException
Copy link
Contributor

Fixes #148838

Root cause:
generics_of currently does not handle hir::Node::ConstArg so defaulted const args nested inside const paths try to inherit generics from the wrong place and trigger ICE.

Symptom:
#148838 ICE

Fix

Handle Node::ConstArg, in fact, similar logic already exists although it is in another branch and slightly more complex, not sure if there is a more elegant way:

// FIXME(#43408) always enable this once `lazy_normalization` is
// stable enough and does not need a feature gate anymore.
Node::AnonConst(_) => {
let parent_did = tcx.parent(def_id.to_def_id());
debug!(?parent_did);
let mut in_param_ty = false;
for (_parent, node) in tcx.hir_parent_iter(hir_id) {
if let Some(generics) = node.generics() {
let mut visitor = AnonConstInParamTyDetector { in_param_ty: false, ct: hir_id };
in_param_ty = visitor.visit_generics(generics).is_break();
break;
}
}

Testing:
1 more test case const-arg-unresolved.rs

@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 Nov 11, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 11, 2025

r? @davidtwco

rustbot has assigned @davidtwco.
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

@BoxyUwU
Copy link
Member

BoxyUwU commented Nov 13, 2025

r? BoxyUwU

@rustbot rustbot assigned BoxyUwU and unassigned davidtwco Nov 13, 2025
@BoxyUwU
Copy link
Member

BoxyUwU commented Nov 17, 2025

As far as I can tell this ICE has nothing to due with defaulted const args, this ICEs too:

#![feature(min_generic_const_args)]
#![feature(generic_const_exprs)]
struct Both {
    a: A<{ B::<1>::M }>,
}

I think what's actually going on here is that generic_const_exprs is allowing for anon consts to have parent generics from dummy defids associated with hir::ConstArg nodes that shouldn't really exist in the first place.

Given that this is a GCE-only bug I'm not too interested in this being fixed. I also think this will probably wind up being indirectly fixed in the long term by fixing the "root" cause of having extra DefIds generated.

With that in mind gonna close this PR. Thanks for making the PR and showing interest in const generics :) This solution does look reasonable for trying to make GCE work properly in this case.

@BoxyUwU BoxyUwU closed this Nov 17, 2025
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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: generics_of: unexpected node kind ConstArg(ConstArg

4 participants