Skip to content

Commit 2c33b07

Browse files
committed
use ufcs in derive(Ord) and derive(PartialOrd)
1 parent c648bd5 commit 2c33b07

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

compiler/rustc_builtin_macros/src/deriving/cmp/ord.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ pub fn ordering_collapsed(
4747
span: Span,
4848
self_arg_tags: &[Ident],
4949
) -> P<ast::Expr> {
50-
let lft = cx.expr_ident(span, self_arg_tags[0]);
50+
let lft = cx.expr_addr_of(span, cx.expr_ident(span, self_arg_tags[0]));
5151
let rgt = cx.expr_addr_of(span, cx.expr_ident(span, self_arg_tags[1]));
52-
cx.expr_method_call(span, lft, Ident::new(sym::cmp, span), vec![rgt])
52+
let fn_cmp_path = cx.std_path(&[sym::cmp, sym::Ord, sym::cmp]);
53+
cx.expr_call_global(span, fn_cmp_path, vec![lft, rgt])
5354
}
5455

5556
pub fn cs_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P<Expr> {

compiler/rustc_builtin_macros/src/deriving/cmp/partial_ord.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,11 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_
107107
if self_args.len() != 2 {
108108
cx.span_bug(span, "not exactly 2 arguments in `derive(PartialOrd)`")
109109
} else {
110-
let lft = cx.expr_ident(span, tag_tuple[0]);
110+
let lft = cx.expr_addr_of(span, cx.expr_ident(span, tag_tuple[0]));
111111
let rgt = cx.expr_addr_of(span, cx.expr_ident(span, tag_tuple[1]));
112-
cx.expr_method_call(span, lft, Ident::new(sym::partial_cmp, span), vec![rgt])
112+
let fn_partial_cmp_path =
113+
cx.std_path(&[sym::cmp, sym::PartialOrd, sym::partial_cmp]);
114+
cx.expr_call_global(span, fn_partial_cmp_path, vec![lft, rgt])
113115
}
114116
}),
115117
cx,

0 commit comments

Comments
 (0)