mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 09:27:27 +00:00
fix: visibility in impl items and pub(crate) to pub in extract_module
This commit is contained in:
parent
0247e50676
commit
192b6f5a78
1 changed files with 49 additions and 13 deletions
|
@ -779,7 +779,12 @@ fn get_replacements_for_visibilty_change(
|
||||||
ast::Item::Enum(it) => replacements.push((it.visibility(), it.syntax().clone())),
|
ast::Item::Enum(it) => replacements.push((it.visibility(), it.syntax().clone())),
|
||||||
ast::Item::ExternCrate(it) => replacements.push((it.visibility(), it.syntax().clone())),
|
ast::Item::ExternCrate(it) => replacements.push((it.visibility(), it.syntax().clone())),
|
||||||
ast::Item::Fn(it) => replacements.push((it.visibility(), it.syntax().clone())),
|
ast::Item::Fn(it) => replacements.push((it.visibility(), it.syntax().clone())),
|
||||||
ast::Item::Impl(it) => impls.push(it),
|
ast::Item::Impl(it) => {
|
||||||
|
//Associated item's visibility should not be changed
|
||||||
|
if let None = it.for_token() {
|
||||||
|
impls.push(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
ast::Item::MacroRules(it) => replacements.push((it.visibility(), it.syntax().clone())),
|
ast::Item::MacroRules(it) => replacements.push((it.visibility(), it.syntax().clone())),
|
||||||
ast::Item::MacroDef(it) => replacements.push((it.visibility(), it.syntax().clone())),
|
ast::Item::MacroDef(it) => replacements.push((it.visibility(), it.syntax().clone())),
|
||||||
ast::Item::Module(it) => replacements.push((it.visibility(), it.syntax().clone())),
|
ast::Item::Module(it) => replacements.push((it.visibility(), it.syntax().clone())),
|
||||||
|
@ -825,11 +830,7 @@ fn add_change_vis(
|
||||||
vis: Option<ast::Visibility>,
|
vis: Option<ast::Visibility>,
|
||||||
node_or_token_opt: Option<syntax::SyntaxElement>,
|
node_or_token_opt: Option<syntax::SyntaxElement>,
|
||||||
) -> Option<()> {
|
) -> Option<()> {
|
||||||
if let Some(vis) = vis {
|
if let None = vis {
|
||||||
if vis.syntax().text() == "pub" {
|
|
||||||
ted::replace(vis.syntax(), make::visibility_pub_crate().syntax().clone_for_update());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if let Some(node_or_token) = node_or_token_opt {
|
if let Some(node_or_token) = node_or_token_opt {
|
||||||
let pub_crate_vis = make::visibility_pub_crate().clone_for_update();
|
let pub_crate_vis = make::visibility_pub_crate().clone_for_update();
|
||||||
if let Some(node) = node_or_token.as_node() {
|
if let Some(node) = node_or_token.as_node() {
|
||||||
|
@ -962,8 +963,8 @@ mod modname {
|
||||||
pub(crate) inner: SomeType,
|
pub(crate) inner: SomeType,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct PrivateStruct1 {
|
pub struct PrivateStruct1 {
|
||||||
pub(crate) inner: i32,
|
pub inner: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PrivateStruct {
|
impl PrivateStruct {
|
||||||
|
@ -1033,7 +1034,7 @@ mod modname {
|
||||||
pub(crate) struct A {}
|
pub(crate) struct A {}
|
||||||
|
|
||||||
impl A {
|
impl A {
|
||||||
pub(crate) fn new_a() -> i32 {
|
pub fn new_a() -> i32 {
|
||||||
2
|
2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1203,7 +1204,7 @@ mod modname {
|
||||||
use super::A;
|
use super::A;
|
||||||
|
|
||||||
impl A {
|
impl A {
|
||||||
pub(crate) fn new_a() -> i32 {
|
pub fn new_a() -> i32 {
|
||||||
2
|
2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1251,7 +1252,7 @@ mod modname {
|
||||||
use super::super::foo::A;
|
use super::super::foo::A;
|
||||||
|
|
||||||
impl A {
|
impl A {
|
||||||
pub(crate) fn new_a() -> i32 {
|
pub fn new_a() -> i32 {
|
||||||
2
|
2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1378,4 +1379,39 @@ mod modname {
|
||||||
",
|
",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_do_not_apply_visibility_modifier_to_trait_impl_items() {
|
||||||
|
check_assist(
|
||||||
|
extract_module,
|
||||||
|
r"
|
||||||
|
trait ATrait {
|
||||||
|
fn function();
|
||||||
|
}
|
||||||
|
|
||||||
|
struct A {}
|
||||||
|
|
||||||
|
$0impl ATrait for A {
|
||||||
|
fn function() {}
|
||||||
|
}$0
|
||||||
|
",
|
||||||
|
r"
|
||||||
|
trait ATrait {
|
||||||
|
fn function();
|
||||||
|
}
|
||||||
|
|
||||||
|
struct A {}
|
||||||
|
|
||||||
|
mod modname {
|
||||||
|
use super::A;
|
||||||
|
|
||||||
|
use super::ATrait;
|
||||||
|
|
||||||
|
impl ATrait for A {
|
||||||
|
fn function() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
",
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue