@@ -7,7 +7,7 @@ use rustc_errors::Applicability;
7
7
use rustc_hir:: def_id:: LocalDefId ;
8
8
use rustc_hir:: { Block , Body , Expr , ExprKind , ImplItem , ImplItemKind , Item , LangItem , Node , UnOp } ;
9
9
use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
10
- use rustc_middle:: ty:: { EarlyBinder , TraitRef } ;
10
+ use rustc_middle:: ty:: EarlyBinder ;
11
11
use rustc_session:: declare_lint_pass;
12
12
use rustc_span:: sym;
13
13
use rustc_span:: symbol:: kw;
@@ -131,11 +131,18 @@ impl LateLintPass<'_> for NonCanonicalImpls {
131
131
{
132
132
check_clone_on_copy ( cx, impl_item, block) ;
133
133
} else if trait_name == Some ( sym:: PartialOrd )
134
+ // If `Self` and `Rhs` are not the same type, then a corresponding `Ord` impl is not possible,
135
+ // since it doesn't have an `Rhs`
136
+ && match trait_impl. args . as_slice ( ) {
137
+ [ _] => true ,
138
+ [ lhs, rhs] => lhs == rhs,
139
+ _ => false ,
140
+ }
134
141
&& impl_item. ident . name == sym:: partial_cmp
135
142
&& let Some ( ord_def_id) = cx. tcx . get_diagnostic_item ( sym:: Ord )
136
143
&& implements_trait ( cx, trait_impl. self_ty ( ) , ord_def_id, & [ ] )
137
144
{
138
- check_partial_ord_on_ord ( cx, impl_item, item, & trait_impl , body, block) ;
145
+ check_partial_ord_on_ord ( cx, impl_item, item, body, block) ;
139
146
}
140
147
}
141
148
}
@@ -181,7 +188,6 @@ fn check_partial_ord_on_ord<'tcx>(
181
188
cx : & LateContext < ' tcx > ,
182
189
impl_item : & ImplItem < ' _ > ,
183
190
item : & Item < ' _ > ,
184
- trait_impl : & TraitRef < ' _ > ,
185
191
body : & Body < ' _ > ,
186
192
block : & Block < ' tcx > ,
187
193
) {
@@ -207,13 +213,6 @@ fn check_partial_ord_on_ord<'tcx>(
207
213
{
208
214
return ;
209
215
}
210
- // If `Self` and `Rhs` are not the same type, bail. This makes creating a valid
211
- // suggestion tons more complex.
212
- else if let [ lhs, rhs, ..] = trait_impl. args . as_slice ( )
213
- && lhs != rhs
214
- {
215
- return ;
216
- }
217
216
218
217
span_lint_and_then (
219
218
cx,
0 commit comments