]> git.lizzy.rs Git - rust.git/blobdiff - crates/ide_ssr/src/resolving.rs
Merge #11393
[rust.git] / crates / ide_ssr / src / resolving.rs
index af94c7bb1bee81785ada06c8ed016e09649a00ca..844b19779a8776ee2ac2ba252bba0a142f66c4f8 100644 (file)
@@ -47,10 +47,9 @@ pub(crate) fn new(
     ) -> Result<ResolvedRule, SsrError> {
         let resolver =
             Resolver { resolution_scope, placeholders_by_stand_in: rule.placeholders_by_stand_in };
-        let resolved_template = if let Some(template) = rule.template {
-            Some(resolver.resolve_pattern_tree(template)?)
-        } else {
-            None
+        let resolved_template = match rule.template {
+            Some(template) => Some(resolver.resolve_pattern_tree(template)?),
+            None => None,
         };
         Ok(ResolvedRule {
             pattern: resolver.resolve_pattern_tree(rule.pattern)?,
@@ -150,7 +149,7 @@ fn resolve(
     fn path_contains_placeholder(&self, path: &ast::Path) -> bool {
         if let Some(segment) = path.segment() {
             if let Some(name_ref) = segment.name_ref() {
-                if self.placeholders_by_stand_in.contains_key(name_ref.text()) {
+                if self.placeholders_by_stand_in.contains_key(name_ref.text().as_str()) {
                     return true;
                 }
             }
@@ -195,7 +194,7 @@ pub(crate) fn new(
             .syntax()
             .token_at_offset(resolve_context.offset)
             .left_biased()
-            .map(|token| token.parent())
+            .and_then(|token| token.parent())
             .unwrap_or_else(|| file.syntax().clone());
         let node = pick_node_for_resolution(node);
         let scope = sema.scope(&node);
@@ -211,7 +210,7 @@ fn resolve_path(&self, path: &ast::Path) -> Option<hir::PathResolution> {
         // First try resolving the whole path. This will work for things like
         // `std::collections::HashMap`, but will fail for things like
         // `std::collections::HashMap::new`.
-        if let Some(resolution) = self.scope.speculative_resolve(&path) {
+        if let Some(resolution) = self.scope.speculative_resolve(path) {
             return Some(resolution);
         }
         // Resolution failed, try resolving the qualifier (e.g. `std::collections::HashMap` and if
@@ -220,14 +219,16 @@ fn resolve_path(&self, path: &ast::Path) -> Option<hir::PathResolution> {
         let resolved_qualifier = self.scope.speculative_resolve(&path.qualifier()?)?;
         if let hir::PathResolution::Def(hir::ModuleDef::Adt(adt)) = resolved_qualifier {
             let name = path.segment()?.name_ref()?;
+            let module = self.scope.module()?;
             adt.ty(self.scope.db).iterate_path_candidates(
                 self.scope.db,
-                self.scope.module()?.krate(),
-                &self.scope.traits_in_scope(),
+                module.krate(),
+                &self.scope.visible_traits(),
+                Some(module),
                 None,
                 |_ty, assoc_item| {
                     let item_name = assoc_item.name(self.scope.db)?;
-                    if item_name.to_string().as_str() == name.text() {
+                    if item_name.to_smol_str().as_str() == name.text() {
                         Some(hir::PathResolution::AssocItem(assoc_item))
                     } else {
                         None
@@ -243,10 +244,10 @@ fn qualifier_type(&self, path: &SyntaxNode) -> Option<hir::Type> {
         use syntax::ast::AstNode;
         if let Some(path) = ast::Path::cast(path.clone()) {
             if let Some(qualifier) = path.qualifier() {
-                if let Some(resolved_qualifier) = self.resolve_path(&qualifier) {
-                    if let hir::PathResolution::Def(hir::ModuleDef::Adt(adt)) = resolved_qualifier {
-                        return Some(adt.ty(self.scope.db));
-                    }
+                if let Some(hir::PathResolution::Def(hir::ModuleDef::Adt(adt))) =
+                    self.resolve_path(&qualifier)
+                {
+                    return Some(adt.ty(self.scope.db));
                 }
             }
         }