diff options
| author | yukang <moorekang@gmail.com> | 2024-03-02 22:42:13 +0800 |
|---|---|---|
| committer | yukang <moorekang@gmail.com> | 2024-03-02 23:15:39 +0800 |
| commit | 5a5c6dfb33ec9f17416ac96ca66554a033ecd387 (patch) | |
| tree | 78cef499e2ae9fff0c4921b7fb137142a2c6b7e8 /compiler/rustc_attr/src/builtin.rs | |
| parent | e612d079a1102803fd2cae5dcd7f7f277e493b8e (diff) | |
| download | rust-5a5c6dfb33ec9f17416ac96ca66554a033ecd387.tar.gz rust-5a5c6dfb33ec9f17416ac96ca66554a033ecd387.zip | |
Fix misleading message when using a named constant as a struct alignment/pack
Diffstat (limited to 'compiler/rustc_attr/src/builtin.rs')
| -rw-r--r-- | compiler/rustc_attr/src/builtin.rs | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs index f414ff746bb..6b6eefc64f8 100644 --- a/compiler/rustc_attr/src/builtin.rs +++ b/compiler/rustc_attr/src/builtin.rs @@ -1039,21 +1039,37 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> { }); } } - MetaItemKind::List(_) => { + MetaItemKind::List(nested_items) => { if meta_item.has_name(sym::align) { recognised = true; - sess.dcx().emit_err( - session_diagnostics::IncorrectReprFormatAlignOneArg { - span: meta_item.span, - }, - ); + if nested_items.len() == 1 { + sess.dcx().emit_err( + session_diagnostics::IncorrectReprFormatExpectInteger { + span: nested_items[0].span(), + }, + ); + } else { + sess.dcx().emit_err( + session_diagnostics::IncorrectReprFormatAlignOneArg { + span: meta_item.span, + }, + ); + } } else if meta_item.has_name(sym::packed) { recognised = true; - sess.dcx().emit_err( - session_diagnostics::IncorrectReprFormatPackedOneOrZeroArg { - span: meta_item.span, - }, - ); + if nested_items.len() == 1 { + sess.dcx().emit_err( + session_diagnostics::IncorrectReprFormatPackedExpectInteger { + span: nested_items[0].span(), + }, + ); + } else { + sess.dcx().emit_err( + session_diagnostics::IncorrectReprFormatPackedOneOrZeroArg { + span: meta_item.span, + }, + ); + } } else if matches!( meta_item.name_or_empty(), sym::Rust | sym::C | sym::simd | sym::transparent |
