-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Suggest calling Self::associated_function()
#96507
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Suggest calling Self::associated_function()
#96507
Conversation
r? @lcnr (rust-highfive has picked a reviewer for you, use r? to override) |
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.
some small questions
&& 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() |
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 do you only suggest that if there are no inputs?
I am not too familiar with this function
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.
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) = |
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.
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?
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.
I agree with you. I'll fix it just like you said.
59b8a24
to
bdd3cfb
Compare
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.
after that r=me
debug!( | ||
"self.diagnostic_metadata.current_impl_items={:?}", | ||
self.diagnostic_metadata.current_impl_items | ||
); | ||
debug!( | ||
"self.diagnostic_metadata.current_function={:?}", | ||
self.diagnostic_metadata.current_function | ||
); |
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.
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); |
&& 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 | ||
}) |
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.
&& 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() |
debug!("name={}", item_str.name); | ||
debug!("fn_.sig.decl.inputs={:?}", fn_.sig.decl.inputs); |
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.
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
bdd3cfb
to
df25189
Compare
@bors r=lcnr |
@TaKO8Ki: 🔑 Insufficient privileges: Not in reviewers |
Thanks 👍 @bors r+ rollup |
@bors r+ rollup |
📌 Commit df25189 has been approved by |
…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
closes #96453