Skip to content

Commit

Permalink
Rollup merge of #136027 - estebank:issue-135989, r=compiler-errors
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
matthiaskrgr authored Jan 25, 2025
2 parents 2080d66 + 8873c18 commit 06349ec
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -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() {}
14 changes: 14 additions & 0 deletions tests/ui/deriving/do-not-suggest-calling-fn-in-derive-macro.stderr
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit 06349ec

Please sign in to comment.