1
Fork 0

Rollup merge of #136027 - estebank:issue-135989, r=compiler-errors

Skip suggestions in `derive`d code

Do not suggest

```
help: use parentheses to call these
  |
5 |     (callback: Rc<dyn Fn()>)(),
  |     +                      +++
```

Skip all "call function for this binop" suggestions when in a derive context.

Fix #135989.
This commit is contained in:
Matthias Krüger 2025-01-25 08:03:37 +01:00 committed by GitHub
commit 06349ec2dd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 0 deletions

View file

@ -185,6 +185,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
rhs_ty: Ty<'tcx>,
can_satisfy: impl FnOnce(Ty<'tcx>, Ty<'tcx>) -> bool,
) -> bool {
if lhs_expr.span.in_derive_expansion() || rhs_expr.span.in_derive_expansion() {
return false;
}
let Some((_, lhs_output_ty, lhs_inputs)) = self.extract_callable_info(lhs_ty) else {
return false;
};

View file

@ -0,0 +1,8 @@
use std::rc::Rc;
#[derive(PartialEq)] //~ NOTE in this expansion
pub struct Function {
callback: Rc<dyn Fn()>, //~ ERROR binary operation `==` cannot be applied to type `Rc<dyn Fn()>`
}
fn main() {}

View file

@ -0,0 +1,14 @@
error[E0369]: binary operation `==` cannot be applied to type `Rc<dyn Fn()>`
--> $DIR/do-not-suggest-calling-fn-in-derive-macro.rs:5:5
|
LL | #[derive(PartialEq)]
| --------- in this derive macro expansion
LL | pub struct Function {
LL | callback: Rc<dyn Fn()>,
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0369`.