Skip to content

Conversation

@rperier
Copy link
Contributor

@rperier rperier commented Nov 7, 2025

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 @ 💬

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

rustbot commented Nov 7, 2025

r? @wesleywiser

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

@rperier
Copy link
Contributor Author

rperier commented Nov 7, 2025

r? @lcnr

@rustbot rustbot assigned lcnr and unassigned wesleywiser Nov 7, 2025
Currently this method is quiet long and complex, this commit
improves its readability by adding sub-fns
@rperier rperier force-pushed the report_no_match_method_error-refactoring branch from 9a8910e to 177bb33 Compare November 7, 2025 15:25
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
 Documenting proc_macro_test v0.1.0 (/checkout/tests/rustdoc-gui/src/proc_macro_test)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.80s
   Generated /checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc-gui/doc/proc_macro_test/index.html
npm WARN deprecated puppeteer@22.15.0: < 24.10.2 is no longer supported
npm ERR! code 127
npm ERR! git dep preparation failed
npm ERR! command /node/bin/node /node/lib/node_modules/npm/bin/npm-cli.js install --force --cache=/home/user/.npm --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit --include=dev --include=peer --include=optional --no-package-lock-only --no-dry-run
npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR! npm WARN deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm ERR! npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm ERR! npm WARN deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm ERR! npm WARN deprecated readdir-scoped-modules@1.1.0: This functionality has been moved to @npmcli/fs
npm ERR! npm WARN deprecated read-package-json@2.1.2: This package is no longer supported. Please use @npmcli/package-json instead.
npm ERR! npm WARN deprecated debuglog@1.0.1: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
npm ERR! npm WARN deprecated read-installed@4.0.3: This package is no longer supported.
npm ERR! npm ERR! code 127
npm ERR! npm ERR! path /home/user/.npm/_cacache/tmp/git-cloneXXXXXX54ZpIE/node_modules/rollup
npm ERR! npm ERR! command failed
npm ERR! npm ERR! command sh -c patch-package
npm ERR! npm ERR! sh: 1: patch-package: not found
npm ERR! 
npm ERR! npm ERR! A complete log of this run can be found in: /home/user/.npm/_logs/2025-11-07T16_34_13_945Z-debug-0.log

npm ERR! A complete log of this run can be found in: /home/user/.npm/_logs/2025-11-07T16_34_06_629Z-debug-0.log
npm install did not exit successfully

thread 'main' (59440) panicked at src/tools/rustdoc-gui-test/src/main.rs:63:10:
unable to install browser-ui-test: Custom { kind: Other, error: "npm install returned exit code exit status: 127" }
stack backtrace:
   0: __rustc::rust_begin_unwind
             at /rustc/3b4dd9bf1410f8da6329baa36ce5e37673cbbd1f/library/std/src/panicking.rs:698:5
   1: core::panicking::panic_fmt
             at /rustc/3b4dd9bf1410f8da6329baa36ce5e37673cbbd1f/library/core/src/panicking.rs:80:14

@lcnr lcnr changed the title Cleanup and refactorize FnCtxt::report_no_match_method_error Cleanup and refactor FnCtxt::report_no_match_method_error Nov 7, 2025
@lcnr
Copy link
Contributor

lcnr commented Nov 7, 2025

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 whatever_its_called sub-fn" this is a lot nicer to review as a separate commit. Think this is fine for now, but please do so in future PRs

Some(sugg_span),
);
}
custom_span_label
Copy link
Contributor

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<(
Copy link
Contributor

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 {
Copy link
Contributor

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?

Comment on lines +1126 to +1128
if rcvr_ty.references_error() {
err.downgrade_to_delayed_bug();
}
Copy link
Contributor

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

Comment on lines +1146 to +1151
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();
Copy link
Contributor

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?

Comment on lines +1165 to +1167
let mut restrict_type_params = false;
let mut suggested_derive = false;
let mut unsatisfied_bounds = false;
Copy link
Contributor

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;
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants