Skip to content

fix ICE in suggest_add_reference_to_arg for non-callable items - #160628

Open
im-lunex wants to merge 1 commit into
rust-lang:mainfrom
im-lunex:fix_#160591
Open

fix ICE in suggest_add_reference_to_arg for non-callable items#160628
im-lunex wants to merge 1 commit into
rust-lang:mainfrom
im-lunex:fix_#160591

Conversation

@im-lunex

@im-lunex im-lunex commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

tcx.fn_sig(def_id) panicked ("unexpected sort of node in fn_sig()") when
the def_id in a WhereClauseInExpr obligation was the struct being
constructed, not the impl. This happens when a struct literal argument is
missing a field.

Guard both fn_sig call sites in suggest_add_reference_to_arg so the
suggestion only fires for callable defs.

Fixes #160591.

@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 Aug 6, 2026
@rustbot

rustbot commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

r? @JohnTitor

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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 75 candidates
  • Random selection from 19 candidates

@JohnTitor JohnTitor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@rust-bors

rust-bors Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 0d75b8c has been approved by JohnTitor

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 6. This pull request will be tested once the tree is reopened.

Reason for tree closure: Github problems

@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 Aug 6, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 7, 2026
fix ICE in `suggest_add_reference_to_arg` for non-callable items

`tcx.fn_sig(def_id)` panicked ("unexpected sort of node in fn_sig()") when
the `def_id` in a `WhereClauseInExpr` obligation was the struct being
constructed, not the impl. This happens when a struct literal argument is
missing a field.

Guard both `fn_sig` call sites in `suggest_add_reference_to_arg` so the
suggestion only fires for callable defs.

Fixes rust-lang#160591.
@Kivooeo

Kivooeo commented Aug 7, 2026

Copy link
Copy Markdown
Member

hi, i want to ask it due to our new policy: was LLM used for this and if so how?

jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 7, 2026
fix ICE in `suggest_add_reference_to_arg` for non-callable items

`tcx.fn_sig(def_id)` panicked ("unexpected sort of node in fn_sig()") when
the `def_id` in a `WhereClauseInExpr` obligation was the struct being
constructed, not the impl. This happens when a struct literal argument is
missing a field.

Guard both `fn_sig` call sites in `suggest_add_reference_to_arg` so the
suggestion only fires for callable defs.

Fixes rust-lang#160591.
rust-bors Bot pushed a commit that referenced this pull request Aug 7, 2026
Rollup of 14 pull requests

Successful merges:

 - #150885 (Revive L4Re target)
 - #159643 (Add support for splatted function pointers)
 - #160433 (delegation: add support for wrapping of the return value with `From::from`)
 - #160530 (refactor handling of target features in Session)
 - #160606 (bootstrap: Store and use an explicit CheckKind in `check::Rustc`)
 - #160628 (fix ICE in `suggest_add_reference_to_arg` for non-callable items)
 - #160634 (miri subtree update)
 - #158904 (Fix FutureDropPoll shim for by-move async closures)
 - #160335 (dlopen offload)
 - #160445 (codegen: classify localized MSVC linker progress as linker_info)
 - #160504 (cleanup borrowck, improve c-variadic handling)
 - #160587 (Add regression test for associated type outlives bound at call site)
 - #160625 (platform-support/netbsd.md: No longer mention 8.x, due to EoL.)
 - #160636 (derive(Diagnostic): link to proper docs)
@im-lunex

im-lunex commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

@Kivooeo yeah used here for the text stuff tests/ui/structs/ice-missing-field-fn-sig.stderr used LLM for this file.

@Kivooeo

Kivooeo commented Aug 7, 2026

Copy link
Copy Markdown
Member

you mean you used llm to generate .stderr file?

@im-lunex

im-lunex commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

@Kivooeo yeah, 1st tried doing it by my self then saw there was typo mistakes and many more then used LLM on this .stderr file. LLM can be used in stderr type of files right ?

@Kivooeo

Kivooeo commented Aug 7, 2026

Copy link
Copy Markdown
Member

we have --bless flag to generate .stderr files

./x test test-name --bless it will generate correct test-name.stderr

@im-lunex

im-lunex commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

@Kivooeo nice im really new to this repo soo didn't knew that. thanks for you guidance

@Kivooeo

Kivooeo commented Aug 7, 2026

Copy link
Copy Markdown
Member

It is highly encouraged to ask questions on Zulip.

@im-lunex

im-lunex commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

It is highly encouraged to ask questions on Zulip.

yeah will try that out thanks for it. (btw i verified this with --bless and everything looks good tho)

@Kivooeo

Kivooeo commented Aug 7, 2026

Copy link
Copy Markdown
Member

btw, @teor2345 do you have opinion on that fix?

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 7, 2026
fix ICE in `suggest_add_reference_to_arg` for non-callable items

`tcx.fn_sig(def_id)` panicked ("unexpected sort of node in fn_sig()") when
the `def_id` in a `WhereClauseInExpr` obligation was the struct being
constructed, not the impl. This happens when a struct literal argument is
missing a field.

Guard both `fn_sig` call sites in `suggest_add_reference_to_arg` so the
suggestion only fires for callable defs.

Fixes rust-lang#160591.
rust-bors Bot pushed a commit that referenced this pull request Aug 7, 2026
…uwer

Rollup of 21 pull requests

Successful merges:

 - #159784 (Hint that memchr returns an in-bounds index)
 - #150885 (Revive L4Re target)
 - #159643 (Add support for splatted function pointers)
 - #160433 (delegation: add support for wrapping of the return value with `From::from`)
 - #160530 (refactor handling of target features in Session)
 - #160606 (bootstrap: Store and use an explicit CheckKind in `check::Rustc`)
 - #160628 (fix ICE in `suggest_add_reference_to_arg` for non-callable items)
 - #160634 (miri subtree update)
 - #157641 (Do not promote extern statics)
 - #158904 (Fix FutureDropPoll shim for by-move async closures)
 - #160103 (Add regression test for GAT bound mismatched type error)
 - #160335 (dlopen offload)
 - #160445 (codegen: classify localized MSVC linker progress as linker_info)
 - #160499 (rustc_resolve: move diagnostic attribute linting to attr parsing)
 - #160504 (cleanup borrowck, improve c-variadic handling)
 - #160577 (expand: Feature gate AST-based attribute macros on expressions and statements)
 - #160587 (Add regression test for associated type outlives bound at call site)
 - #160625 (platform-support/netbsd.md: No longer mention 8.x, due to EoL.)
 - #160636 (derive(Diagnostic): link to proper docs)
 - #160644 (Clean up some manual debug impls)
 - #160649 (move naked function ui tests)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 7, 2026
fix ICE in `suggest_add_reference_to_arg` for non-callable items

`tcx.fn_sig(def_id)` panicked ("unexpected sort of node in fn_sig()") when
the `def_id` in a `WhereClauseInExpr` obligation was the struct being
constructed, not the impl. This happens when a struct literal argument is
missing a field.

Guard both `fn_sig` call sites in `suggest_add_reference_to_arg` so the
suggestion only fires for callable defs.

Fixes rust-lang#160591.
rust-bors Bot pushed a commit that referenced this pull request Aug 7, 2026
…uwer

Rollup of 20 pull requests

Successful merges:

 - #159784 (Hint that memchr returns an in-bounds index)
 - #150885 (Revive L4Re target)
 - #159643 (Add support for splatted function pointers)
 - #160433 (delegation: add support for wrapping of the return value with `From::from`)
 - #160530 (refactor handling of target features in Session)
 - #160606 (bootstrap: Store and use an explicit CheckKind in `check::Rustc`)
 - #160628 (fix ICE in `suggest_add_reference_to_arg` for non-callable items)
 - #160634 (miri subtree update)
 - #157641 (Do not promote extern statics)
 - #158904 (Fix FutureDropPoll shim for by-move async closures)
 - #160103 (Add regression test for GAT bound mismatched type error)
 - #160335 (dlopen offload)
 - #160445 (codegen: classify localized MSVC linker progress as linker_info)
 - #160499 (rustc_resolve: move diagnostic attribute linting to attr parsing)
 - #160504 (cleanup borrowck, improve c-variadic handling)
 - #160577 (expand: Feature gate AST-based attribute macros on expressions and statements)
 - #160587 (Add regression test for associated type outlives bound at call site)
 - #160625 (platform-support/netbsd.md: No longer mention 8.x, due to EoL.)
 - #160636 (derive(Diagnostic): link to proper docs)
 - #160644 (Clean up some manual debug impls)
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 7, 2026
fix ICE in `suggest_add_reference_to_arg` for non-callable items

`tcx.fn_sig(def_id)` panicked ("unexpected sort of node in fn_sig()") when
the `def_id` in a `WhereClauseInExpr` obligation was the struct being
constructed, not the impl. This happens when a struct literal argument is
missing a field.

Guard both `fn_sig` call sites in `suggest_add_reference_to_arg` so the
suggestion only fires for callable defs.

Fixes rust-lang#160591.

@teor2345 teor2345 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems fine to merge, but it would be good to add some more test coverage soon.

As well as the impl case, it might also be worth adding a UI test for closures (if it's possible to construct one):

pub fn is_fn_like(self) -> bool {
matches!(
self,
DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::SyntheticCoroutineBody
)
}

View changes since this review

c @ ObligationCauseCode::WhereClauseInExpr(def_id, _, hir_id, idx)
if let hir::Node::Expr(expr) = self.tcx.hir_node(*hir_id)
&& let hir::ExprKind::MethodCall(_segment, rcvr, args, ..) = expr.kind
// The `def_id` can also point at the impl, which has no fn sig.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It would be good to have a test case for this change.
I think the current UI test only checks the struct case.

It's slightly odd that the method impl doesn't have a fn_sig, are you sure about that?
(This is a genuine question, because I don't know for sure.)

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 7, 2026
fix ICE in `suggest_add_reference_to_arg` for non-callable items

`tcx.fn_sig(def_id)` panicked ("unexpected sort of node in fn_sig()") when
the `def_id` in a `WhereClauseInExpr` obligation was the struct being
constructed, not the impl. This happens when a struct literal argument is
missing a field.

Guard both `fn_sig` call sites in `suggest_add_reference_to_arg` so the
suggestion only fires for callable defs.

Fixes rust-lang#160591.
rust-bors Bot pushed a commit that referenced this pull request Aug 7, 2026
…uwer

Rollup of 28 pull requests

Successful merges:

 - #159784 (Hint that memchr returns an in-bounds index)
 - #160673 (Improve `canonical_param_env_cache`)
 - #150885 (Revive L4Re target)
 - #159643 (Add support for splatted function pointers)
 - #160433 (delegation: add support for wrapping of the return value with `From::from`)
 - #160530 (refactor handling of target features in Session)
 - #160606 (bootstrap: Store and use an explicit CheckKind in `check::Rustc`)
 - #160628 (fix ICE in `suggest_add_reference_to_arg` for non-callable items)
 - #160683 (Add regression test for unknown feaeture name reported with other errors)
 - #157641 (Do not promote extern statics)
 - #158904 (Fix FutureDropPoll shim for by-move async closures)
 - #159816 (added note/help about iterator invalidation when mutating a collection inside a for loop)
 - #160103 (Add regression test for GAT bound mismatched type error)
 - #160335 (dlopen offload)
 - #160445 (codegen: classify localized MSVC linker progress as linker_info)
 - #160499 (rustc_resolve: move diagnostic attribute linting to attr parsing)
 - #160504 (cleanup borrowck, improve c-variadic handling)
 - #160577 (expand: Feature gate AST-based attribute macros on expressions and statements)
 - #160587 (Add regression test for associated type outlives bound at call site)
 - #160625 (platform-support/netbsd.md: No longer mention 8.x, due to EoL.)
 - #160633 (delegation: fix determining wrong `FnKind` when delegation is inside const arg)
 - #160636 (derive(Diagnostic): link to proper docs)
 - #160644 (Clean up some manual debug impls)
 - #160649 (move naked function ui tests)
 - #160672 (Improve `MaybeLiveLocals`)
 - #160693 (Add branch config for perf. unrolling in bors)
 - #160696 (rustc_codegen_llvm: handle sm_101* features being an alias)
 - #160706 (renovate: clarify that vulnerability PRs are opened automatically)
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ICE]: unexpected sort of node in fn_sig() with missing stuct field

5 participants