Skip to content

Commit 2268a56

Browse files
authored
Merge pull request #20682 from A4-Tacks/fix-change-vis-applicable-on-variant
Fix applicable on variant field for change_visibility
2 parents 5b68439 + 5b5c50e commit 2268a56

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

crates/ide-assists/src/handlers/change_visibility.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ fn add_vis(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
6565
if field.visibility().is_some() {
6666
return None;
6767
}
68+
check_is_not_variant(&field)?;
6869
(vis_offset(field.syntax()), field_name.syntax().text_range())
6970
} else if let Some(field) = ctx.find_node_at_offset::<ast::TupleField>() {
7071
if field.visibility().is_some() {
7172
return None;
7273
}
74+
check_is_not_variant(&field)?;
7375
(vis_offset(field.syntax()), field.syntax().text_range())
7476
} else {
7577
return None;
@@ -134,6 +136,11 @@ fn change_vis(acc: &mut Assists, vis: ast::Visibility) -> Option<()> {
134136
None
135137
}
136138

139+
fn check_is_not_variant(field: &impl AstNode) -> Option<()> {
140+
let kind = field.syntax().parent()?.parent()?.kind();
141+
(kind != SyntaxKind::VARIANT).then_some(())
142+
}
143+
137144
#[cfg(test)]
138145
mod tests {
139146
use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target};
@@ -239,6 +246,13 @@ mod tests {
239246
);
240247
}
241248

249+
#[test]
250+
fn not_applicable_for_enum_variant_fields() {
251+
check_assist_not_applicable(change_visibility, r"pub enum Foo { Foo1($0i32) }");
252+
253+
check_assist_not_applicable(change_visibility, r"pub enum Foo { Foo1 { $0n: i32 } }");
254+
}
255+
242256
#[test]
243257
fn change_visibility_target() {
244258
check_assist_target(change_visibility, "$0fn foo() {}", "fn");

0 commit comments

Comments
 (0)