about summary refs log tree commit diff
path: root/compiler/rustc_parse/src
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2024-11-26 17:53:00 +0000
committerEsteban Küber <esteban@kuber.com.ar>2024-12-09 21:55:12 +0000
commit550bcae8aa7859abace52c20b8b9149ae6cb37f1 (patch)
tree0ac51fba8bb64e7dcfedc78876c01df1a8f574e7 /compiler/rustc_parse/src
parent9ac95c10c09faf50cc22eb97b6e1c59d64053c28 (diff)
downloadrust-550bcae8aa7859abace52c20b8b9149ae6cb37f1.tar.gz
rust-550bcae8aa7859abace52c20b8b9149ae6cb37f1.zip
Detect `struct S(ty = val);`
Emit a specific error for unsupported default field value syntax in tuple structs.
Diffstat (limited to 'compiler/rustc_parse/src')
-rw-r--r--compiler/rustc_parse/src/parser/item.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs
index f12b4ca249d..58b4bf8980b 100644
--- a/compiler/rustc_parse/src/parser/item.rs
+++ b/compiler/rustc_parse/src/parser/item.rs
@@ -1836,6 +1836,22 @@ impl<'a> Parser<'a> {
                         return Err(err);
                     }
                 };
+                let mut default = None;
+                if p.token == token::Eq {
+                    let mut snapshot = p.create_snapshot_for_diagnostic();
+                    snapshot.bump();
+                    match snapshot.parse_expr_anon_const() {
+                        Ok(const_expr) => {
+                            let sp = ty.span.shrink_to_hi().to(const_expr.value.span);
+                            p.psess.gated_spans.gate(sym::default_field_values, sp);
+                            p.restore_snapshot(snapshot);
+                            default = Some(const_expr);
+                        }
+                        Err(err) => {
+                            err.cancel();
+                        }
+                    }
+                }
 
                 Ok((
                     FieldDef {
@@ -1845,7 +1861,7 @@ impl<'a> Parser<'a> {
                         ident: None,
                         id: DUMMY_NODE_ID,
                         ty,
-                        default: None,
+                        default,
                         attrs,
                         is_placeholder: false,
                     },