ImportScope::Module(it) => ImportScope::Module(builder.make_mut(it)),
ImportScope::Block(it) => ImportScope::Block(builder.make_mut(it)),
};
+ shorten_paths(scope.as_syntax_node(), &path.clone_for_update());
// stick the found import in front of the to be replaced path
let path = match path_to_qualifier.and_then(|it| mod_path_to_ast(&it).qualifier()) {
Some(qualifier) => make::path_concat(qualifier, path),
None => path,
};
- shorten_paths(scope.as_syntax_node(), &path.clone_for_update());
insert_use(&scope, path, &ctx.config.insert_use);
},
)
match child {
// Don't modify `use` items, as this can break the `use` item when injecting a new
// import into the use tree.
- ast::Use(_it) => continue,
+ ast::Use(_) => continue,
// Don't descend into submodules, they don't have the same `use` items in scope.
// FIXME: This isn't true due to `super::*` imports?
- ast::Module(_it) => continue,
+ ast::Module(_) => continue,
ast::Path(p) => if maybe_replace_path(p.clone(), path.clone()).is_none() {
shorten_paths(p.syntax(), path);
},
",
);
}
- #[test]
+
#[test]
fn dont_import_trivial_paths() {
cov_mark::check!(dont_import_trivial_paths);
fn main() {
Foo;
}
+",
+ );
+ }
+
+ #[test]
+ fn replace_does_not_always_try_to_replace_by_full_item_path() {
+ check_assist(
+ replace_qualified_name_with_use,
+ r"
+use std::mem;
+
+mod std {
+ pub mod mem {
+ pub fn drop<T>(_: T) {}
+ }
+}
+
+fn main() {
+ mem::drop$0(0);
+}
+",
+ r"
+use std::mem::{self, drop};
+
+mod std {
+ pub mod mem {
+ pub fn drop<T>(_: T) {}
+ }
+}
+
+fn main() {
+ drop(0);
+}
",
);
}