about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJacob Rothstein <hi@jbr.me>2020-08-03 12:17:05 -0700
committerJacob Rothstein <hi@jbr.me>2020-08-03 12:17:05 -0700
commit03a61134f22fae8574766313f6ffd39d1007c7fe (patch)
tree22ec28220c7145ba924735c77bcb55e1c342392e
parent33e53d472158746c6a0150538bea348ce0e5a22d (diff)
downloadrust-03a61134f22fae8574766313f6ffd39d1007c7fe.tar.gz
rust-03a61134f22fae8574766313f6ffd39d1007c7fe.zip
do not add to `pub use` statements
-rw-r--r--crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs42
-rw-r--r--crates/ra_assists/src/utils/insert_use.rs3
2 files changed, 44 insertions, 1 deletions
diff --git a/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs b/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs
index 53496ede150..da0a860c599 100644
--- a/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs
+++ b/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs
@@ -643,4 +643,46 @@ fn main() {
     ",
         );
     }
+
+    #[test]
+    fn does_not_replace_pub_use() {
+        check_assist(
+            replace_qualified_name_with_use,
+            r"
+pub use std::fmt;
+
+impl std::io<|> for Foo {
+}
+    ",
+            r"
+use std::io;
+
+pub use std::fmt;
+
+impl io for Foo {
+}
+    ",
+        );
+    }
+
+    #[test]
+    fn does_not_replace_pub_crate_use() {
+        check_assist(
+            replace_qualified_name_with_use,
+            r"
+pub(crate) use std::fmt;
+
+impl std::io<|> for Foo {
+}
+    ",
+            r"
+use std::io;
+
+pub(crate) use std::fmt;
+
+impl io for Foo {
+}
+    ",
+        );
+    }
 }
diff --git a/crates/ra_assists/src/utils/insert_use.rs b/crates/ra_assists/src/utils/insert_use.rs
index 617afe2e945..32780fceb59 100644
--- a/crates/ra_assists/src/utils/insert_use.rs
+++ b/crates/ra_assists/src/utils/insert_use.rs
@@ -4,7 +4,7 @@
 
 use hir::{self, ModPath};
 use ra_syntax::{
-    ast::{self, NameOwner},
+    ast::{self, NameOwner, VisibilityOwner},
     AstNode, Direction, SmolStr,
     SyntaxKind::{PATH, PATH_SEGMENT},
     SyntaxNode, T,
@@ -378,6 +378,7 @@ fn best_action_for_target(
     let best_action = container
         .children()
         .filter_map(ast::Use::cast)
+        .filter(|u| u.visibility().is_none())
         .filter_map(|it| it.use_tree())
         .map(|u| walk_use_tree_for_best_action(&mut storage, None, u, target))
         .fold(None, |best, a| match best {