Detect struct S(ty = val);
Emit a specific error for unsupported default field value syntax in tuple structs.
This commit is contained in:
parent
9ac95c10c0
commit
550bcae8aa
6 changed files with 63 additions and 11 deletions
|
@ -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,
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue