about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authoryukang <moorekang@gmail.com>2024-03-02 23:18:06 +0800
committeryukang <moorekang@gmail.com>2024-03-03 10:48:40 +0800
commit53dba7fb5546f5a0d450bbef6995a2d5425e72e5 (patch)
tree0ae2efd233858e09333a7c031d80747821d35402 /compiler
parent5a5c6dfb33ec9f17416ac96ca66554a033ecd387 (diff)
fix spans of arguments in diagnostic
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_attr/messages.ftl4
-rw-r--r--compiler/rustc_attr/src/builtin.rs13
2 files changed, 12 insertions, 5 deletions
diff --git a/compiler/rustc_attr/messages.ftl b/compiler/rustc_attr/messages.ftl
index 9c01e6a9d2c..eb51e568f81 100644
--- a/compiler/rustc_attr/messages.ftl
+++ b/compiler/rustc_attr/messages.ftl
@@ -28,14 +28,14 @@ attr_incorrect_repr_format_align_one_arg =
     incorrect `repr(align)` attribute format: `align` takes exactly one argument in parentheses
 
 attr_incorrect_repr_format_expect_literal_integer =
-    incorrect `repr(align)` attribute format: `align` expect a literal integer as argument
+    incorrect `repr(align)` attribute format: `align` expects a literal integer as argument
 
 attr_incorrect_repr_format_generic =
     incorrect `repr({$repr_arg})` attribute format
     .suggestion = use parentheses instead
 
 attr_incorrect_repr_format_packed_expect_integer =
-    incorrect `repr(packed)` attribute format: `packed` expect a literal integer as argument
+    incorrect `repr(packed)` attribute format: `packed` expects a literal integer as argument
 
 attr_incorrect_repr_format_packed_one_or_zero_arg =
     incorrect `repr(packed)` attribute format: `packed` takes exactly one parenthesized argument, or no parentheses at all
diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs
index 6b6eefc64f8..3d2cf25e98b 100644
--- a/compiler/rustc_attr/src/builtin.rs
+++ b/compiler/rustc_attr/src/builtin.rs
@@ -984,17 +984,24 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
                 }
             } else if let Some((name, value)) = item.name_value_literal() {
                 let mut literal_error = None;
+                let mut err_span = item.span();
                 if name == sym::align {
                     recognised = true;
                     match parse_alignment(&value.kind) {
                         Ok(literal) => acc.push(ReprAlign(literal)),
-                        Err(message) => literal_error = Some(message),
+                        Err(message) => {
+                            err_span = value.span;
+                            literal_error = Some(message)
+                        }
                     };
                 } else if name == sym::packed {
                     recognised = true;
                     match parse_alignment(&value.kind) {
                         Ok(literal) => acc.push(ReprPacked(literal)),
-                        Err(message) => literal_error = Some(message),
+                        Err(message) => {
+                            err_span = value.span;
+                            literal_error = Some(message)
+                        }
                     };
                 } else if matches!(name, sym::Rust | sym::C | sym::simd | sym::transparent)
                     || int_type_of_word(name).is_some()
@@ -1007,7 +1014,7 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
                 }
                 if let Some(literal_error) = literal_error {
                     sess.dcx().emit_err(session_diagnostics::InvalidReprGeneric {
-                        span: item.span(),
+                        span: err_span,
                         repr_arg: name.to_ident_string(),
                         error_part: literal_error,
                     });