Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion crates/ide-diagnostics/src/handlers/no_such_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ fn missing_record_expr_field_fixes(
let indent = IndentLevel::from_node(last_field_syntax);

let mut new_field = new_field.to_string();
if usage_file_id != def_file_id {
// FIXME: check submodule instead of FileId
if usage_file_id != def_file_id && !matches!(def_id, hir::VariantDef::Variant(_)) {
new_field = format!("pub(crate) {new_field}");
}
new_field = format!("\n{indent}{new_field}");
Expand Down Expand Up @@ -357,6 +358,34 @@ pub struct Foo {
)
}

#[test]
fn test_add_enum_variant_field_in_other_file_from_usage() {
check_fix(
r#"
//- /main.rs
mod foo;
fn main() {
foo::Foo::Variant { bar: 3, $0baz: false};
}
//- /foo.rs
pub enum Foo {
Variant {
bar: i32
}
}
"#,
r#"
pub enum Foo {
Variant {
bar: i32,
baz: bool
}
}
"#,
)
}

#[test]
fn test_tuple_field_on_record_struct() {
check_no_fix(
Expand Down