1
Fork 0

fix spans of arguments in diagnostic

This commit is contained in:
yukang 2024-03-02 23:18:06 +08:00
parent 5a5c6dfb33
commit 53dba7fb55
7 changed files with 45 additions and 38 deletions

View file

@ -28,14 +28,14 @@ attr_incorrect_repr_format_align_one_arg =
incorrect `repr(align)` attribute format: `align` takes exactly one argument in parentheses incorrect `repr(align)` attribute format: `align` takes exactly one argument in parentheses
attr_incorrect_repr_format_expect_literal_integer = 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 = attr_incorrect_repr_format_generic =
incorrect `repr({$repr_arg})` attribute format incorrect `repr({$repr_arg})` attribute format
.suggestion = use parentheses instead .suggestion = use parentheses instead
attr_incorrect_repr_format_packed_expect_integer = 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 = 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 incorrect `repr(packed)` attribute format: `packed` takes exactly one parenthesized argument, or no parentheses at all

View file

@ -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() { } else if let Some((name, value)) = item.name_value_literal() {
let mut literal_error = None; let mut literal_error = None;
let mut err_span = item.span();
if name == sym::align { if name == sym::align {
recognised = true; recognised = true;
match parse_alignment(&value.kind) { match parse_alignment(&value.kind) {
Ok(literal) => acc.push(ReprAlign(literal)), 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 { } else if name == sym::packed {
recognised = true; recognised = true;
match parse_alignment(&value.kind) { match parse_alignment(&value.kind) {
Ok(literal) => acc.push(ReprPacked(literal)), 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) } else if matches!(name, sym::Rust | sym::C | sym::simd | sym::transparent)
|| int_type_of_word(name).is_some() || 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 { if let Some(literal_error) = literal_error {
sess.dcx().emit_err(session_diagnostics::InvalidReprGeneric { sess.dcx().emit_err(session_diagnostics::InvalidReprGeneric {
span: item.span(), span: err_span,
repr_arg: name.to_ident_string(), repr_arg: name.to_ident_string(),
error_part: literal_error, error_part: literal_error,
}); });

View file

@ -19,7 +19,7 @@ struct X;
const P: usize = 8; const P: usize = 8;
#[repr(packed(P))] #[repr(packed(P))]
//~^ ERROR: attribute format: `packed` expect a literal integer as argument //~^ ERROR: attribute format: `packed` expects a literal integer as argument
struct A; struct A;
#[repr(packed())] #[repr(packed())]

View file

@ -1,20 +1,20 @@
error[E0693]: incorrect `repr(align)` attribute format: `align` expect a literal integer as argument error[E0693]: incorrect `repr(align)` attribute format: `align` expects a literal integer as argument
--> $DIR/arg-error-issue-121425.rs:4:14 --> $DIR/arg-error-issue-121425.rs:4:14
| |
LL | #[repr(align(N))] LL | #[repr(align(N))]
| ^ | ^
error[E0589]: invalid `repr(align)` attribute: not an unsuffixed integer error[E0589]: invalid `repr(align)` attribute: not an unsuffixed integer
--> $DIR/arg-error-issue-121425.rs:8:8 --> $DIR/arg-error-issue-121425.rs:8:14
| |
LL | #[repr(align('a'))] LL | #[repr(align('a'))]
| ^^^^^^^^^^ | ^^^
error[E0589]: invalid `repr(align)` attribute: not an unsuffixed integer error[E0589]: invalid `repr(align)` attribute: not an unsuffixed integer
--> $DIR/arg-error-issue-121425.rs:12:8 --> $DIR/arg-error-issue-121425.rs:12:14
| |
LL | #[repr(align("str"))] LL | #[repr(align("str"))]
| ^^^^^^^^^^^^ | ^^^^^
error[E0693]: incorrect `repr(align)` attribute format: `align` takes exactly one argument in parentheses error[E0693]: incorrect `repr(align)` attribute format: `align` takes exactly one argument in parentheses
--> $DIR/arg-error-issue-121425.rs:16:8 --> $DIR/arg-error-issue-121425.rs:16:8
@ -22,7 +22,7 @@ error[E0693]: incorrect `repr(align)` attribute format: `align` takes exactly on
LL | #[repr(align())] LL | #[repr(align())]
| ^^^^^^^ | ^^^^^^^
error[E0552]: incorrect `repr(packed)` attribute format: `packed` expect a literal integer as argument error[E0552]: incorrect `repr(packed)` attribute format: `packed` expects a literal integer as argument
--> $DIR/arg-error-issue-121425.rs:21:15 --> $DIR/arg-error-issue-121425.rs:21:15
| |
LL | #[repr(packed(P))] LL | #[repr(packed(P))]

View file

@ -15,6 +15,6 @@ macro_rules! n {
} }
pass_nonterminal!(n!()); pass_nonterminal!(n!());
//~^ ERROR incorrect `repr(align)` attribute format: `align` expect a literal integer as argument [E0693] //~^ ERROR incorrect `repr(align)` attribute format: `align` expects a literal integer as argument [E0693]
fn main() {} fn main() {}

View file

@ -9,7 +9,7 @@ LL | pass_nonterminal!(n!());
| |
= note: this error originates in the macro `pass_nonterminal` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `pass_nonterminal` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0693]: incorrect `repr(align)` attribute format: `align` expect a literal integer as argument error[E0693]: incorrect `repr(align)` attribute format: `align` expects a literal integer as argument
--> $DIR/nonterminal-expansion.rs:17:19 --> $DIR/nonterminal-expansion.rs:17:19
| |
LL | pass_nonterminal!(n!()); LL | pass_nonterminal!(n!());

View file

@ -1,84 +1,84 @@
error[E0589]: invalid `repr(align)` attribute: not an unsuffixed integer error[E0589]: invalid `repr(align)` attribute: not an unsuffixed integer
--> $DIR/repr-align.rs:3:8 --> $DIR/repr-align.rs:3:14
| |
LL | #[repr(align(16.0))] LL | #[repr(align(16.0))]
| ^^^^^^^^^^^ | ^^^^
error[E0589]: invalid `repr(align)` attribute: not a power of two error[E0589]: invalid `repr(align)` attribute: not a power of two
--> $DIR/repr-align.rs:7:8 --> $DIR/repr-align.rs:7:14
| |
LL | #[repr(align(15))] LL | #[repr(align(15))]
| ^^^^^^^^^ | ^^
error[E0589]: invalid `repr(align)` attribute: larger than 2^29 error[E0589]: invalid `repr(align)` attribute: larger than 2^29
--> $DIR/repr-align.rs:11:8 --> $DIR/repr-align.rs:11:14
| |
LL | #[repr(align(4294967296))] LL | #[repr(align(4294967296))]
| ^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^
error[E0589]: invalid `repr(align)` attribute: not an unsuffixed integer error[E0589]: invalid `repr(align)` attribute: not an unsuffixed integer
--> $DIR/repr-align.rs:18:8 --> $DIR/repr-align.rs:18:14
| |
LL | #[repr(align(16.0))] LL | #[repr(align(16.0))]
| ^^^^^^^^^^^ | ^^^^
error[E0589]: invalid `repr(align)` attribute: not a power of two error[E0589]: invalid `repr(align)` attribute: not a power of two
--> $DIR/repr-align.rs:22:8 --> $DIR/repr-align.rs:22:14
| |
LL | #[repr(align(15))] LL | #[repr(align(15))]
| ^^^^^^^^^ | ^^
error[E0589]: invalid `repr(align)` attribute: larger than 2^29 error[E0589]: invalid `repr(align)` attribute: larger than 2^29
--> $DIR/repr-align.rs:26:8 --> $DIR/repr-align.rs:26:14
| |
LL | #[repr(align(4294967296))] LL | #[repr(align(4294967296))]
| ^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^
error[E0589]: invalid `repr(align)` attribute: not an unsuffixed integer error[E0589]: invalid `repr(align)` attribute: not an unsuffixed integer
--> $DIR/repr-align.rs:3:8 --> $DIR/repr-align.rs:3:14
| |
LL | #[repr(align(16.0))] LL | #[repr(align(16.0))]
| ^^^^^^^^^^^ | ^^^^
| |
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0589]: invalid `repr(align)` attribute: not a power of two error[E0589]: invalid `repr(align)` attribute: not a power of two
--> $DIR/repr-align.rs:7:8 --> $DIR/repr-align.rs:7:14
| |
LL | #[repr(align(15))] LL | #[repr(align(15))]
| ^^^^^^^^^ | ^^
| |
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0589]: invalid `repr(align)` attribute: larger than 2^29 error[E0589]: invalid `repr(align)` attribute: larger than 2^29
--> $DIR/repr-align.rs:11:8 --> $DIR/repr-align.rs:11:14
| |
LL | #[repr(align(4294967296))] LL | #[repr(align(4294967296))]
| ^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^
| |
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0589]: invalid `repr(align)` attribute: not an unsuffixed integer error[E0589]: invalid `repr(align)` attribute: not an unsuffixed integer
--> $DIR/repr-align.rs:18:8 --> $DIR/repr-align.rs:18:14
| |
LL | #[repr(align(16.0))] LL | #[repr(align(16.0))]
| ^^^^^^^^^^^ | ^^^^
| |
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0589]: invalid `repr(align)` attribute: not a power of two error[E0589]: invalid `repr(align)` attribute: not a power of two
--> $DIR/repr-align.rs:22:8 --> $DIR/repr-align.rs:22:14
| |
LL | #[repr(align(15))] LL | #[repr(align(15))]
| ^^^^^^^^^ | ^^
| |
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error[E0589]: invalid `repr(align)` attribute: larger than 2^29 error[E0589]: invalid `repr(align)` attribute: larger than 2^29
--> $DIR/repr-align.rs:26:8 --> $DIR/repr-align.rs:26:14
| |
LL | #[repr(align(4294967296))] LL | #[repr(align(4294967296))]
| ^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^
| |
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`