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(
405405 let record_field = ast:: RecordExprField :: for_field_name ( name_ref) ?;
406406 let initializer = record_field. expr ( ) ?;
407407
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 ) )
411411 }
412+ _ => None ,
412413 }
413-
414- Some ( ( record_field, initializer) )
415414}
416415
417416fn find_record_pat_field_usage ( name : & ast:: NameLike ) -> Option < ast:: Pat > {
@@ -800,6 +799,36 @@ fn main() {
800799 )
801800 }
802801
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+
803832 #[ test]
804833 fn field_struct_basic ( ) {
805834 cov_mark:: check!( replaces_record_expr) ;
You can’t perform that action at this time.
0 commit comments