Skip to content

Commit a50c1cc

Browse files
authored
Merge pull request #21221 from A4-Tacks/no-pub-in-variant-field
Fix pub in enum variant field for no_such_field
2 parents a071c5c + fcc307a commit a50c1cc

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

crates/ide-diagnostics/src/handlers/no_such_field.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ fn missing_record_expr_field_fixes(
102102
let indent = IndentLevel::from_node(last_field_syntax);
103103

104104
let mut new_field = new_field.to_string();
105-
if usage_file_id != def_file_id {
105+
// FIXME: check submodule instead of FileId
106+
if usage_file_id != def_file_id && !matches!(def_id, hir::VariantDef::Variant(_)) {
106107
new_field = format!("pub(crate) {new_field}");
107108
}
108109
new_field = format!("\n{indent}{new_field}");
@@ -357,6 +358,34 @@ pub struct Foo {
357358
)
358359
}
359360

361+
#[test]
362+
fn test_add_enum_variant_field_in_other_file_from_usage() {
363+
check_fix(
364+
r#"
365+
//- /main.rs
366+
mod foo;
367+
368+
fn main() {
369+
foo::Foo::Variant { bar: 3, $0baz: false};
370+
}
371+
//- /foo.rs
372+
pub enum Foo {
373+
Variant {
374+
bar: i32
375+
}
376+
}
377+
"#,
378+
r#"
379+
pub enum Foo {
380+
Variant {
381+
bar: i32,
382+
baz: bool
383+
}
384+
}
385+
"#,
386+
)
387+
}
388+
360389
#[test]
361390
fn test_tuple_field_on_record_struct() {
362391
check_no_fix(

0 commit comments

Comments
 (0)