Skip to content

Don't suggest rewriting call if resolution was invalid #143014

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

compiler-errors
Copy link
Member

Fixes #143008.

The suggestion to "try calling {ident} as a method" was eating the more relevant suggestion to mark the tuple struct's fields as pub so its ctor is visible.

See inline comment.

@rustbot
Copy link
Collaborator

rustbot commented Jun 25, 2025

r? @petrochenkov

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

@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 Jun 25, 2025
// this if there's no `Res`, since if there was a resolution but it
// was invalid, it's more likely not a typo of this form.
if let Some((call_span, args_span)) = self.call_has_self_arg(source)
&& res.is_none()
Copy link
Member Author

Choose a reason for hiding this comment

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

This doesn't affect any other tests, so I just went with a simple heuristic here.

We could alternatively check if the path segment starts with a capitalized identifier, or match !matches!(res, Some(DefKind::Struct | DefKind::Variant)), or something? I think that's kinda overkill tho.

Copy link
Contributor

Choose a reason for hiding this comment

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

The right condition here is probably res.is_none() || res.has_self_param().

Resolver already has the logic for res.has_self_param() in fn lookup_assoc_candidate in the same file, so it can probably be shared.

                            let has_self = match def_id.as_local() {
                                Some(def_id) => self
                                    .r
                                    .delegation_fn_sigs
                                    .get(&def_id)
                                    .is_some_and(|sig| sig.has_self),
                                None => {
                                    self.r.tcx.fn_arg_idents(def_id).first().is_some_and(|&ident| {
                                        matches!(ident, Some(Ident { name: kw::SelfLower, .. }))
                                    })
                                }
                            };

@rust-log-analyzer

This comment has been minimized.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

Weird error message when trying to use a private constructor in a method
4 participants