Skip to content

Commit 8873c18

Browse files
committed
Skip suggestions in derived 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 rust-lang#135989.
1 parent 8231e85 commit 8873c18

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

Diff for: compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+3
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
185185
rhs_ty: Ty<'tcx>,
186186
can_satisfy: impl FnOnce(Ty<'tcx>, Ty<'tcx>) -> bool,
187187
) -> bool {
188+
if lhs_expr.span.in_derive_expansion() || rhs_expr.span.in_derive_expansion() {
189+
return false;
190+
}
188191
let Some((_, lhs_output_ty, lhs_inputs)) = self.extract_callable_info(lhs_ty) else {
189192
return false;
190193
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use std::rc::Rc;
2+
3+
#[derive(PartialEq)] //~ NOTE in this expansion
4+
pub struct Function {
5+
callback: Rc<dyn Fn()>, //~ ERROR binary operation `==` cannot be applied to type `Rc<dyn Fn()>`
6+
}
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0369]: binary operation `==` cannot be applied to type `Rc<dyn Fn()>`
2+
--> $DIR/do-not-suggest-calling-fn-in-derive-macro.rs:5:5
3+
|
4+
LL | #[derive(PartialEq)]
5+
| --------- in this derive macro expansion
6+
LL | pub struct Function {
7+
LL | callback: Rc<dyn Fn()>,
8+
| ^^^^^^^^^^^^^^^^^^^^^^
9+
|
10+
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0369`.

0 commit comments

Comments
 (0)