This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +34
-5
lines changed
crates/ide-assists/src/handlers Expand file tree Collapse file tree 1 file changed +34
-5
lines changed Original file line number Diff line number Diff line change @@ -405,13 +405,12 @@ fn find_record_expr_usage(
405
405
let record_field = ast:: RecordExprField :: for_field_name ( name_ref) ?;
406
406
let initializer = record_field. expr ( ) ?;
407
407
408
- if let Definition :: Field ( expected_field ) = target_definition {
409
- if got_field != expected_field {
410
- return None ;
408
+ match target_definition {
409
+ Definition :: Field ( expected_field ) if got_field == expected_field => {
410
+ Some ( ( record_field , initializer ) )
411
411
}
412
+ _ => None ,
412
413
}
413
-
414
- Some ( ( record_field, initializer) )
415
414
}
416
415
417
416
fn find_record_pat_field_usage ( name : & ast:: NameLike ) -> Option < ast:: Pat > {
@@ -800,6 +799,36 @@ fn main() {
800
799
)
801
800
}
802
801
802
+ #[ test]
803
+ fn local_var_init_struct_usage ( ) {
804
+ check_assist (
805
+ bool_to_enum,
806
+ r#"
807
+ struct Foo {
808
+ foo: bool,
809
+ }
810
+
811
+ fn main() {
812
+ let $0foo = true;
813
+ let s = Foo { foo };
814
+ }
815
+ "# ,
816
+ r#"
817
+ struct Foo {
818
+ foo: bool,
819
+ }
820
+
821
+ #[derive(PartialEq, Eq)]
822
+ enum Bool { True, False }
823
+
824
+ fn main() {
825
+ let foo = Bool::True;
826
+ let s = Foo { foo: foo == Bool::True };
827
+ }
828
+ "# ,
829
+ )
830
+ }
831
+
803
832
#[ test]
804
833
fn field_struct_basic ( ) {
805
834
cov_mark:: check!( replaces_record_expr) ;
You can’t perform that action at this time.
0 commit comments