Skip to content
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

Suggest calling Self::associated_function() #96507

Merged
merged 1 commit into from
May 5, 2022

Conversation

TaKO8Ki
Copy link
Member

@TaKO8Ki TaKO8Ki commented Apr 28, 2022

closes #96453

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 28, 2022
@rust-highfive
Copy link
Collaborator

r? @lcnr

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 28, 2022
Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

some small questions

compiler/rustc_resolve/src/late/diagnostics.rs Outdated Show resolved Hide resolved
&& let FnCtxt::Assoc(_) = function_ctxt
&& let Some(item) = items.iter().find(|i| {
if let AssocItemKind::Fn(fn_) = &i.kind
&& fn_.sig.decl.inputs.is_empty()
Copy link
Contributor

Choose a reason for hiding this comment

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

why do you only suggest that if there are no inputs?

I am not too familiar with this function

Copy link
Member Author

@TaKO8Ki TaKO8Ki May 5, 2022

Choose a reason for hiding this comment

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

I fixed it to suggest that if inputs don't include self, &self, or &mut self.

@@ -147,10 +147,12 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
let mut expected = source.descr_expected();
let path_str = Segment::names_to_string(path);
let item_str = path.last().unwrap().ident;
let (base_msg, fallback_label, base_span, could_be_expr) = if let Some(res) = res {
let (base_msg, fallback_label, base_span, could_be_expr, suggestion) = if let Some(res) =
Copy link
Contributor

Choose a reason for hiding this comment

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

i dislike large tuples like this. it's just personal preference, but what's your take on moving these 4 fields to a helper struct?

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree with you. I'll fix it just like you said.

@TaKO8Ki TaKO8Ki requested a review from lcnr May 4, 2022 14:54
@TaKO8Ki TaKO8Ki force-pushed the suggest-calling-associated-function branch from 59b8a24 to bdd3cfb Compare May 4, 2022 14:54
Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

after that r=me

Comment on lines 186 to 193
debug!(
"self.diagnostic_metadata.current_impl_items={:?}",
self.diagnostic_metadata.current_impl_items
);
debug!(
"self.diagnostic_metadata.current_function={:?}",
self.diagnostic_metadata.current_function
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
debug!(
"self.diagnostic_metadata.current_impl_items={:?}",
self.diagnostic_metadata.current_impl_items
);
debug!(
"self.diagnostic_metadata.current_function={:?}",
self.diagnostic_metadata.current_function
);
debug!(?self.diagnostic_metadata.current_impl_items);
debug!(?self.diagnostic_metadata.current_function);

Comment on lines 200 to 207
&& fn_.sig.decl.inputs.iter().all(|i| match &i.ty.kind {
TyKind::Rptr(_, ty) => match ty.ty.kind {
TyKind::ImplicitSelf => false,
_ => true,
}
TyKind::ImplicitSelf => false,
_ => true
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
&& fn_.sig.decl.inputs.iter().all(|i| match &i.ty.kind {
TyKind::Rptr(_, ty) => match ty.ty.kind {
TyKind::ImplicitSelf => false,
_ => true,
}
TyKind::ImplicitSelf => false,
_ => true
})
&& !fn_.sig.decl.has_self()

Comment on lines 210 to 211
debug!("name={}", item_str.name);
debug!("fn_.sig.decl.inputs={:?}", fn_.sig.decl.inputs);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
debug!("name={}", item_str.name);
debug!("fn_.sig.decl.inputs={:?}", fn_.sig.decl.inputs);
debug!(?item_str.name);
debug!(?fn_.sig.decl.inputs);

or completely remove these debug statements '^^

do not suggest when trait_ref is some

Update compiler/rustc_resolve/src/late/diagnostics.rs

Co-authored-by: lcnr <rust@lcnr.de>

use helper struct

add a test for functions with some params

refactor debug log
@TaKO8Ki TaKO8Ki force-pushed the suggest-calling-associated-function branch from bdd3cfb to df25189 Compare May 5, 2022 07:44
@TaKO8Ki
Copy link
Member Author

TaKO8Ki commented May 5, 2022

@bors r=lcnr

@bors
Copy link
Contributor

bors commented May 5, 2022

@TaKO8Ki: 🔑 Insufficient privileges: Not in reviewers

@lcnr
Copy link
Contributor

lcnr commented May 5, 2022

Thanks 👍

@bors r+ rollup

@lcnr lcnr closed this May 5, 2022
@lcnr lcnr reopened this May 5, 2022
@lcnr
Copy link
Contributor

lcnr commented May 5, 2022

@bors r+ rollup

@bors
Copy link
Contributor

bors commented May 5, 2022

📌 Commit df25189 has been approved by lcnr

@bors bors 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 May 5, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request May 5, 2022
…askrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#95359 (Update `int_roundings` methods from feedback)
 - rust-lang#95843 (Improve Rc::new_cyclic and Arc::new_cyclic documentation)
 - rust-lang#96507 (Suggest calling `Self::associated_function()`)
 - rust-lang#96635 (Use "strict" mode in JS scripts)
 - rust-lang#96673 (Report that opaque types are not allowed in impls even in the presence of other errors)
 - rust-lang#96682 (Show invisible delimeters (within comments) when pretty printing.)
 - rust-lang#96714 (interpret/validity: debug-check ScalarPair layout information)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 34bf620 into rust-lang:master May 5, 2022
@rustbot rustbot added this to the 1.62.0 milestone May 5, 2022
@TaKO8Ki TaKO8Ki deleted the suggest-calling-associated-function branch May 6, 2022 00:44
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.

suggest calling Self::associated_function()
5 participants