Skip to content

Skip suggestions in derived code #136027

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

Merged
merged 1 commit into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`.
Loading