@@ -187,6 +187,7 @@ impl LateLintPass<'_> for NonCanonicalImpls {
187
187
&& let Some ( expr) = block. expr
188
188
&& expr_is_cmp ( cx, & expr. kind , impl_item, & mut needs_fully_qualified)
189
189
{
190
+ return ;
190
191
}
191
192
// Fix #12683, allow [`needless_return`] here
192
193
else if block. expr . is_none ( )
@@ -197,53 +198,53 @@ impl LateLintPass<'_> for NonCanonicalImpls {
197
198
} ) = stmt. kind
198
199
&& expr_is_cmp ( cx, ret_kind, impl_item, & mut needs_fully_qualified)
199
200
{
200
- } else {
201
- // If `Self` and `Rhs` are not the same type, bail. This makes creating a valid
202
- // suggestion tons more complex.
203
- if let [ lhs, rhs, ..] = trait_impl. args . as_slice ( )
204
- && lhs != rhs
205
- {
206
- return ;
207
- }
201
+ return ;
202
+ }
203
+ // If `Self` and `Rhs` are not the same type, bail. This makes creating a valid
204
+ // suggestion tons more complex.
205
+ else if let [ lhs, rhs, ..] = trait_impl. args . as_slice ( )
206
+ && lhs != rhs
207
+ {
208
+ return ;
209
+ }
208
210
209
- span_lint_and_then (
210
- cx,
211
- NON_CANONICAL_PARTIAL_ORD_IMPL ,
212
- item. span ,
213
- "non-canonical implementation of `partial_cmp` on an `Ord` type" ,
214
- |diag| {
215
- let [ _, other] = body. params else {
216
- return ;
217
- } ;
218
- let Some ( std_or_core) = std_or_core ( cx) else {
219
- return ;
220
- } ;
211
+ span_lint_and_then (
212
+ cx,
213
+ NON_CANONICAL_PARTIAL_ORD_IMPL ,
214
+ item. span ,
215
+ "non-canonical implementation of `partial_cmp` on an `Ord` type" ,
216
+ |diag| {
217
+ let [ _, other] = body. params else {
218
+ return ;
219
+ } ;
220
+ let Some ( std_or_core) = std_or_core ( cx) else {
221
+ return ;
222
+ } ;
221
223
222
- let suggs = match ( other. pat . simple_ident ( ) , needs_fully_qualified) {
223
- ( Some ( other_ident) , true ) => vec ! [ (
224
+ let suggs = match ( other. pat . simple_ident ( ) , needs_fully_qualified) {
225
+ ( Some ( other_ident) , true ) => vec ! [ (
226
+ block. span,
227
+ format!( "{{ Some({std_or_core}::cmp::Ord::cmp(self, {})) }}" , other_ident. name) ,
228
+ ) ] ,
229
+ ( Some ( other_ident) , false ) => {
230
+ vec ! [ ( block. span, format!( "{{ Some(self.cmp({})) }}" , other_ident. name) ) ]
231
+ } ,
232
+ ( None , true ) => vec ! [
233
+ (
224
234
block. span,
225
- format!( "{{ Some({std_or_core}::cmp::Ord::cmp(self, {})) }}" , other_ident. name) ,
226
- ) ] ,
227
- ( Some ( other_ident) , false ) => {
228
- vec ! [ ( block. span, format!( "{{ Some(self.cmp({})) }}" , other_ident. name) ) ]
229
- } ,
230
- ( None , true ) => vec ! [
231
- (
232
- block. span,
233
- format!( "{{ Some({std_or_core}::cmp::Ord::cmp(self, other)) }}" ) ,
234
- ) ,
235
- ( other. pat. span, "other" . to_owned( ) ) ,
236
- ] ,
237
- ( None , false ) => vec ! [
238
- ( block. span, "{ Some(self.cmp(other)) }" . to_owned( ) ) ,
239
- ( other. pat. span, "other" . to_owned( ) ) ,
240
- ] ,
241
- } ;
235
+ format!( "{{ Some({std_or_core}::cmp::Ord::cmp(self, other)) }}" ) ,
236
+ ) ,
237
+ ( other. pat. span, "other" . to_owned( ) ) ,
238
+ ] ,
239
+ ( None , false ) => vec ! [
240
+ ( block. span, "{ Some(self.cmp(other)) }" . to_owned( ) ) ,
241
+ ( other. pat. span, "other" . to_owned( ) ) ,
242
+ ] ,
243
+ } ;
242
244
243
- diag. multipart_suggestion ( "change this to" , suggs, Applicability :: Unspecified ) ;
244
- } ,
245
- ) ;
246
- }
245
+ diag. multipart_suggestion ( "change this to" , suggs, Applicability :: Unspecified ) ;
246
+ } ,
247
+ ) ;
247
248
}
248
249
}
249
250
}
0 commit comments