Skip to content

Commit b0c8a2b

Browse files
committed
Remove AsName import
1 parent a6d3c77 commit b0c8a2b

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ use ra_syntax::{
99

1010
use crate::{
1111
assist_context::{AssistBuilder, AssistDirector},
12-
utils::insert_use_statement,
12+
utils::insert_use::insert_use_statement_with_string_path,
1313
AssistContext, AssistId, Assists,
1414
};
1515
use ast::{ArgListOwner, VisibilityOwner};
16-
use hir::{AsName, EnumVariant, Module, ModuleDef};
16+
use hir::{EnumVariant, Module, ModuleDef};
1717
use ra_db::FileId;
1818
use ra_fmt::leading_indent;
1919
use rustc_hash::FxHashSet;
@@ -109,8 +109,13 @@ fn insert_import(
109109
let mod_path = module.find_use_path(db, module_def.clone());
110110
if let Some(mut mod_path) = mod_path {
111111
mod_path.segments.pop();
112-
mod_path.segments.push(path_segment.as_name());
113-
insert_use_statement(path.syntax(), &mod_path, ctx, builder.text_edit_builder());
112+
let use_path = format!("{}::{}", mod_path.to_string(), path_segment.to_string());
113+
insert_use_statement_with_string_path(
114+
path.syntax(),
115+
&use_path,
116+
ctx,
117+
builder.text_edit_builder(),
118+
);
114119
}
115120
Some(())
116121
}

crates/ra_assists/src/utils/insert_use.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@ pub(crate) fn insert_use_statement(
2323
ctx: &AssistContext,
2424
builder: &mut TextEditBuilder,
2525
) {
26-
let target = path_to_import.to_string().split("::").map(SmolStr::new).collect::<Vec<_>>();
26+
insert_use_statement_with_string_path(position, &path_to_import.to_string(), ctx, builder);
27+
}
28+
29+
pub(crate) fn insert_use_statement_with_string_path(
30+
position: &SyntaxNode,
31+
path_to_import: &str,
32+
ctx: &AssistContext,
33+
builder: &mut TextEditBuilder,
34+
) {
35+
let target = path_to_import.split("::").map(SmolStr::new).collect::<Vec<_>>();
2736
let container = ctx.sema.ancestors_with_macros(position.clone()).find_map(|n| {
2837
if let Some(module) = ast::Module::cast(n.clone()) {
2938
return module.item_list().map(|it| it.syntax().clone());

crates/ra_hir/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ pub use hir_def::{
7171
type_ref::Mutability,
7272
};
7373
pub use hir_expand::{
74-
hygiene::Hygiene,
75-
name::{AsName, Name},
76-
HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, Origin,
74+
hygiene::Hygiene, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId,
75+
MacroFile, Origin,
7776
};
7877
pub use hir_ty::{display::HirDisplay, CallableDef};

0 commit comments

Comments
 (0)