diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-01-05 22:47:30 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-05 22:47:30 +0000 |
| commit | 2e33bf23c94e7053eb657d1a318bd1b66cabec95 (patch) | |
| tree | 5a5fe42e3d1366cf90655f54f2e1487cb7570b61 | |
| parent | ada51f2ac499b9746d619a98afbccdec0212b5d6 (diff) | |
| parent | 2d33cdf1882940e4b04620323dfafef9f85126c8 (diff) | |
| download | rust-2e33bf23c94e7053eb657d1a318bd1b66cabec95.tar.gz rust-2e33bf23c94e7053eb657d1a318bd1b66cabec95.zip | |
Merge #11204
11204: fix: `replace_qualified_name_with_use` does not use full item path for replacements r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
| -rw-r--r-- | crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs b/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs index 2c540dc80d2..b0b9ad440c4 100644 --- a/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs +++ b/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs @@ -84,12 +84,12 @@ pub(crate) fn replace_qualified_name_with_use( 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); }, ) @@ -359,4 +359,37 @@ fn main() { ", ); } + + #[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); +} +", + ); + } } |
