File tree Expand file tree Collapse file tree
ide-diagnostics/src/handlers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1185,7 +1185,10 @@ https://doc.rust-lang.org/reference/types.html#trait-objects";
11851185 for ( field_idx, field) in fields. iter ( ) . enumerate ( ) {
11861186 match used_fields. entry ( field. name . clone ( ) ) {
11871187 Occupied ( _occupied) => {
1188- // FIXME: Emit an error, field specified twice.
1188+ self . push_diagnostic ( InferenceDiagnostic :: DuplicateField {
1189+ field : field. pat . into ( ) ,
1190+ variant,
1191+ } ) ;
11891192 }
11901193 Vacant ( vacant) => {
11911194 vacant. insert ( field_idx) ;
Original file line number Diff line number Diff line change @@ -78,6 +78,45 @@ fn main() {
7878 //^^^^^^ 💡 error: no such field
7979 };
8080}
81+ "# ,
82+ ) ;
83+ }
84+
85+ #[ test]
86+ fn duplicate_field_in_struct_pattern ( ) {
87+ check_diagnostics (
88+ r#"
89+ struct S { foo: i32, bar: i32 }
90+ fn f(s: S) {
91+ let S {
92+ foo,
93+ bar,
94+ foo,
95+ //^^^ error: field specified more than once
96+ ..
97+ } = s;
98+ let _ = (foo, bar);
99+ }
100+ "# ,
101+ ) ;
102+ }
103+
104+ #[ test]
105+ fn duplicate_field_in_enum_variant_pattern ( ) {
106+ check_diagnostics (
107+ r#"
108+ enum E { V { foo: i32, bar: i32 } }
109+ fn f(e: E) {
110+ match e {
111+ E::V {
112+ foo,
113+ bar,
114+ foo,
115+ //^^^ error: field specified more than once
116+ ..
117+ } => { let _ = (foo, bar); }
118+ }
119+ }
81120"# ,
82121 ) ;
83122 }
You can’t perform that action at this time.
0 commit comments