Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
…associated types. Resolving a method through the deref chain calls `try_get_deref_func_and_target`, which assumed the resolved `Deref`/`DerefMut` impl has exactly one associated type and `unwrap()`/`panic!`-ed otherwise. A `Deref` impl that omits `type Target` (or adds an extra type) — reported elsewhere as a trait-item mismatch (E0004/E2014) — crashed the compiler when the type was used through deref, before that diagnostic could surface. Return `Ok(None)` (no usable deref)
366f39e to
c527ae0
Compare
PR SummaryLow Risk Overview In A deref diagnostic test was added for a Reviewed by Cursor Bugbot for commit c527ae0. Bugbot is set up for automated code reviews on this repo. Configure here. |
TomerStarkware
left a comment
There was a problem hiding this comment.
@TomerStarkware reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on eytan-starkware).

Summary
When resolving method calls that walk the deref chain,
try_get_deref_func_and_targetpreviously usedunwrap()calls that would panic (ICE) if aDerefimpl was missing its associatedTargettype. The function now uses?-based error propagation and gracefully returnsNonewhen the impl definition data is unavailable or the associated type list does not contain exactly one entry.A test case was added covering the scenario where a
Derefimpl omitstype Target, verifying that the compiler emits a proper diagnostic (Not all trait items are implemented. Missing: 'Target'.) rather than crashing.Type of change
Please check one:
Why is this change needed?
When a
Derefimpl was written without the requiredtype Targetassociated type, the compiler would ICE (internal compiler error / panic) instead of reporting a user-facing diagnostic. This made it impossible to get actionable feedback from the compiler in this situation.What was the behavior or documentation before?
Calling a method on a type whose
Derefimpl was missingtype Targetcaused the compiler to panic with an unwrap failure insidetry_get_deref_func_and_targetwhile walking the deref chain.What is the behavior or documentation after?
The compiler now emits a proper
E0004diagnostic (Not all trait items are implemented. Missing: 'Target'.) and continues to report method resolution failures normally, without crashing.Related issue or discussion (if any)
N/A
Additional context
The fix replaces
unwrap()calls with?-based propagation and usesexactly_one()to guard against unexpected numbers of associated types, returningOk(None)in error cases so the caller can handle the missing deref target gracefully.