-
Notifications
You must be signed in to change notification settings - Fork 14k
Cleanup and refactor FnCtxt::report_no_match_method_error #148652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Cleanup and refactor FnCtxt::report_no_match_method_error #148652
Conversation
|
r? @wesleywiser rustbot has assigned @wesleywiser. Use |
|
r? @lcnr |
Currently this method is quiet long and complex, this commit improves its readability by adding sub-fns
9a8910e to
177bb33
Compare
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
For changes which move a bunch of code around it's really helpful to split it into individual commits, e.g. if you have "move things into a |
| Some(sugg_span), | ||
| ); | ||
| } | ||
| custom_span_label |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return true here and do a fast return if static_candidates.is_empty(). Or probably even only call this function is static_candidates aren't empty
| item_kind: &str, | ||
| mode: Mode, | ||
| source: SelfSource<'tcx>, | ||
| unsatisfied_predicates: &Vec<( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&Vec should pretty much always be a slice?
| ) { | ||
| let mut find_candidate_for_method = false; | ||
|
|
||
| if should_label_not_found && !custom_span_label { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do this in the caller and only have a single bool argument?
| if rcvr_ty.references_error() { | ||
| err.downgrade_to_delayed_bug(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
odd, why does this happen here and not at the start of the fn/before we even start building the error? Can you move this up as far as possible
| let mut static_candidates = no_match_data.static_candidates.clone(); | ||
|
|
||
| // `static_candidates` may have same candidates appended by | ||
| // inherent and extension, which may result in incorrect | ||
| // diagnostic. | ||
| static_candidates.dedup(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does this happen outside of suggest_static_method_candidates? do we use the deduplicated static_candidates anywhere else?
| let mut restrict_type_params = false; | ||
| let mut suggested_derive = false; | ||
| let mut unsatisfied_bounds = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these 3 bools are very ☠️ would be nice to look into how to make them unnecessary or somehow unify their intended impact
| ) { | ||
| return guar; | ||
| } | ||
| span = item_ident.span; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's weird. why? and could we just use item_ident.span directly below this point?
As discussed on zulip with @lcnr, this is a proposal for refactorizing this method.
See #t-compiler/help > (PR #144674) Merge multiple suggestions into a single @ 💬