]> git.lizzy.rs Git - rust.git/blobdiff - crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs
Merge #11481
[rust.git] / crates / ide_assists / src / handlers / extract_struct_from_enum_variant.rs
index 3bc347b1e2e6ca121acc306784ede1fc697df6af..82e0970cc4bf84cb6e8fb508c9fafe61035b5ef6 100644 (file)
@@ -15,8 +15,8 @@
 use rustc_hash::FxHashSet;
 use syntax::{
     ast::{
-        self, edit::IndentLevel, edit_in_place::Indent, make, AstNode, AttrsOwner,
-        GenericParamsOwner, NameOwner, TypeBoundsOwner, VisibilityOwner,
+        self, edit::IndentLevel, edit_in_place::Indent, make, AstNode, HasAttrs, HasGenericParams,
+        HasName, HasTypeBounds, HasVisibility,
     },
     match_ast,
     ted::{self, Position},
@@ -63,8 +63,7 @@ pub(crate) fn extract_struct_from_enum_variant(
         |builder| {
             let variant_hir_name = variant_hir.name(ctx.db());
             let enum_module_def = ModuleDef::from(enum_hir);
-            let usages =
-                Definition::ModuleDef(ModuleDef::Variant(variant_hir)).usages(&ctx.sema).all();
+            let usages = Definition::Variant(variant_hir).usages(&ctx.sema).all();
 
             let mut visited_modules_set = FxHashSet::default();
             let current_module = enum_hir.module(ctx.db());
@@ -72,7 +71,7 @@ pub(crate) fn extract_struct_from_enum_variant(
             // record file references of the file the def resides in, we only want to swap to the edited file in the builder once
             let mut def_file_references = None;
             for (file_id, references) in usages {
-                if file_id == ctx.frange.file_id {
+                if file_id == ctx.file_id() {
                     def_file_references = Some(references);
                     continue;
                 }
@@ -89,7 +88,7 @@ pub(crate) fn extract_struct_from_enum_variant(
                     apply_references(ctx.config.insert_use, path, node, import)
                 });
             }
-            builder.edit_file(ctx.frange.file_id);
+            builder.edit_file(ctx.file_id());
 
             let variant = builder.make_mut(variant.clone());
             if let Some(references) = def_file_references {
@@ -314,7 +313,7 @@ fn process_references(
                 if let Some(mut mod_path) = mod_path {
                     mod_path.pop_segment();
                     mod_path.push_segment(variant_hir_name.clone());
-                    let scope = ImportScope::find_insert_use_container(&scope_node)?;
+                    let scope = ImportScope::find_insert_use_container(&scope_node, &ctx.sema)?;
                     visited_modules.insert(module);
                     return Some((segment, scope_node, Some((scope, mod_path))));
                 }