aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_assists/src/utils.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_assists/src/utils.rs')
-rw-r--r--crates/ide_assists/src/utils.rs27
1 files changed, 11 insertions, 16 deletions
diff --git a/crates/ide_assists/src/utils.rs b/crates/ide_assists/src/utils.rs
index 38ed74673..276792bc1 100644
--- a/crates/ide_assists/src/utils.rs
+++ b/crates/ide_assists/src/utils.rs
@@ -267,24 +267,19 @@ fn invert_special_case(sema: &Semantics<RootDatabase>, expr: &ast::Expr) -> Opti
267} 267}
268 268
269fn bin_impls_ord(sema: &Semantics<RootDatabase>, bin: &ast::BinExpr) -> bool { 269fn bin_impls_ord(sema: &Semantics<RootDatabase>, bin: &ast::BinExpr) -> bool {
270 if let (Some(lhs), Some(rhs)) = (bin.lhs(), bin.rhs()) { 270 match (
271 return sema.type_of_expr(&lhs) == sema.type_of_expr(&rhs) 271 bin.lhs().and_then(|lhs| sema.type_of_expr(&lhs)),
272 && impls_ord(sema, &lhs) 272 bin.rhs().and_then(|rhs| sema.type_of_expr(&rhs)),
273 && impls_ord(sema, &rhs); 273 ) {
274 } 274 (Some(lhs_ty), Some(rhs_ty)) if lhs_ty == rhs_ty => {
275 false 275 let krate = sema.scope(bin.syntax()).module().map(|it| it.krate());
276} 276 let ord_trait = FamousDefs(sema, krate).core_cmp_Ord();
277 277 ord_trait.map_or(false, |ord_trait| {
278fn impls_ord(sema: &Semantics<RootDatabase>, expr: &ast::Expr) -> bool { 278 lhs_ty.autoderef(sema.db).any(|ty| ty.impls_trait(sema.db, ord_trait, &[]))
279 let krate = sema.scope(expr.syntax()).module().map(|it| it.krate()); 279 })
280 let famous_defs = FamousDefs(&sema, krate);
281
282 if let Some(ty) = sema.type_of_expr(expr) {
283 if let Some(ord_trait) = famous_defs.core_cmp_Ord() {
284 return ty.autoderef(sema.db).any(|ty| ty.impls_trait(sema.db, ord_trait, &[]));
285 } 280 }
281 _ => false,
286 } 282 }
287 false
288} 283}
289 284
290pub(crate) fn next_prev() -> impl Iterator<Item = Direction> { 285pub(crate) fn next_prev() -> impl Iterator<Item = Direction> {