Skip to content

Commit af6e9a7

Browse files
bors[bot]jbr
andauthored
Merge #5658
5658: do not add to `pub use` in assists that insert a use statement r=jonas-schievink a=jbr closes #5657 , see issue for rationale Initially I wrote a version of this that changed the signature of `insert_use_statement` to take an `Option<VisibilityKind>` and only add to use statements with the same visibility, but that didn't make sense for any of the current uses of `insert_use_statement` (they all expected private visibility). Co-authored-by: Jacob Rothstein <[email protected]>
2 parents 2b0c2f6 + 03a6113 commit af6e9a7

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,48 @@ use std::fmt::{self, Display};
639639
640640
fn main() {
641641
fmt;
642+
}
643+
",
644+
);
645+
}
646+
647+
#[test]
648+
fn does_not_replace_pub_use() {
649+
check_assist(
650+
replace_qualified_name_with_use,
651+
r"
652+
pub use std::fmt;
653+
654+
impl std::io<|> for Foo {
655+
}
656+
",
657+
r"
658+
use std::io;
659+
660+
pub use std::fmt;
661+
662+
impl io for Foo {
663+
}
664+
",
665+
);
666+
}
667+
668+
#[test]
669+
fn does_not_replace_pub_crate_use() {
670+
check_assist(
671+
replace_qualified_name_with_use,
672+
r"
673+
pub(crate) use std::fmt;
674+
675+
impl std::io<|> for Foo {
676+
}
677+
",
678+
r"
679+
use std::io;
680+
681+
pub(crate) use std::fmt;
682+
683+
impl io for Foo {
642684
}
643685
",
644686
);

crates/ra_assists/src/utils/insert_use.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use hir::{self, ModPath};
66
use ra_syntax::{
7-
ast::{self, NameOwner},
7+
ast::{self, NameOwner, VisibilityOwner},
88
AstNode, Direction, SmolStr,
99
SyntaxKind::{PATH, PATH_SEGMENT},
1010
SyntaxNode, T,
@@ -378,6 +378,7 @@ fn best_action_for_target(
378378
let best_action = container
379379
.children()
380380
.filter_map(ast::Use::cast)
381+
.filter(|u| u.visibility().is_none())
381382
.filter_map(|it| it.use_tree())
382383
.map(|u| walk_use_tree_for_best_action(&mut storage, None, u, target))
383384
.fold(None, |best, a| match best {

0 commit comments

Comments
 (0)