Skip to content

Commit 53dba7f

Browse files
committed
fix spans of arguments in diagnostic
1 parent 5a5c6df commit 53dba7f

File tree

7 files changed

+45
-38
lines changed

7 files changed

+45
-38
lines changed

compiler/rustc_attr/messages.ftl

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ attr_incorrect_repr_format_align_one_arg =
2828
incorrect `repr(align)` attribute format: `align` takes exactly one argument in parentheses
2929
3030
attr_incorrect_repr_format_expect_literal_integer =
31-
incorrect `repr(align)` attribute format: `align` expect a literal integer as argument
31+
incorrect `repr(align)` attribute format: `align` expects a literal integer as argument
3232
3333
attr_incorrect_repr_format_generic =
3434
incorrect `repr({$repr_arg})` attribute format
3535
.suggestion = use parentheses instead
3636
3737
attr_incorrect_repr_format_packed_expect_integer =
38-
incorrect `repr(packed)` attribute format: `packed` expect a literal integer as argument
38+
incorrect `repr(packed)` attribute format: `packed` expects a literal integer as argument
3939
4040
attr_incorrect_repr_format_packed_one_or_zero_arg =
4141
incorrect `repr(packed)` attribute format: `packed` takes exactly one parenthesized argument, or no parentheses at all

compiler/rustc_attr/src/builtin.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -984,17 +984,24 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
984984
}
985985
} else if let Some((name, value)) = item.name_value_literal() {
986986
let mut literal_error = None;
987+
let mut err_span = item.span();
987988
if name == sym::align {
988989
recognised = true;
989990
match parse_alignment(&value.kind) {
990991
Ok(literal) => acc.push(ReprAlign(literal)),
991-
Err(message) => literal_error = Some(message),
992+
Err(message) => {
993+
err_span = value.span;
994+
literal_error = Some(message)
995+
}
992996
};
993997
} else if name == sym::packed {
994998
recognised = true;
995999
match parse_alignment(&value.kind) {
9961000
Ok(literal) => acc.push(ReprPacked(literal)),
997-
Err(message) => literal_error = Some(message),
1001+
Err(message) => {
1002+
err_span = value.span;
1003+
literal_error = Some(message)
1004+
}
9981005
};
9991006
} else if matches!(name, sym::Rust | sym::C | sym::simd | sym::transparent)
10001007
|| int_type_of_word(name).is_some()
@@ -1007,7 +1014,7 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
10071014
}
10081015
if let Some(literal_error) = literal_error {
10091016
sess.dcx().emit_err(session_diagnostics::InvalidReprGeneric {
1010-
span: item.span(),
1017+
span: err_span,
10111018
repr_arg: name.to_ident_string(),
10121019
error_part: literal_error,
10131020
});

tests/ui/attributes/arg-error-issue-121425.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct X;
1919

2020
const P: usize = 8;
2121
#[repr(packed(P))]
22-
//~^ ERROR: attribute format: `packed` expect a literal integer as argument
22+
//~^ ERROR: attribute format: `packed` expects a literal integer as argument
2323
struct A;
2424

2525
#[repr(packed())]

tests/ui/attributes/arg-error-issue-121425.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
error[E0693]: incorrect `repr(align)` attribute format: `align` expect a literal integer as argument
1+
error[E0693]: incorrect `repr(align)` attribute format: `align` expects a literal integer as argument
22
--> $DIR/arg-error-issue-121425.rs:4:14
33
|
44
LL | #[repr(align(N))]
55
| ^
66

77
error[E0589]: invalid `repr(align)` attribute: not an unsuffixed integer
8-
--> $DIR/arg-error-issue-121425.rs:8:8
8+
--> $DIR/arg-error-issue-121425.rs:8:14
99
|
1010
LL | #[repr(align('a'))]
11-
| ^^^^^^^^^^
11+
| ^^^
1212

1313
error[E0589]: invalid `repr(align)` attribute: not an unsuffixed integer
14-
--> $DIR/arg-error-issue-121425.rs:12:8
14+
--> $DIR/arg-error-issue-121425.rs:12:14
1515
|
1616
LL | #[repr(align("str"))]
17-
| ^^^^^^^^^^^^
17+
| ^^^^^
1818

1919
error[E0693]: incorrect `repr(align)` attribute format: `align` takes exactly one argument in parentheses
2020
--> $DIR/arg-error-issue-121425.rs:16:8
2121
|
2222
LL | #[repr(align())]
2323
| ^^^^^^^
2424

25-
error[E0552]: incorrect `repr(packed)` attribute format: `packed` expect a literal integer as argument
25+
error[E0552]: incorrect `repr(packed)` attribute format: `packed` expects a literal integer as argument
2626
--> $DIR/arg-error-issue-121425.rs:21:15
2727
|
2828
LL | #[repr(packed(P))]

tests/ui/attributes/nonterminal-expansion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ macro_rules! n {
1515
}
1616

1717
pass_nonterminal!(n!());
18-
//~^ ERROR incorrect `repr(align)` attribute format: `align` expect a literal integer as argument [E0693]
18+
//~^ ERROR incorrect `repr(align)` attribute format: `align` expects a literal integer as argument [E0693]
1919

2020
fn main() {}

tests/ui/attributes/nonterminal-expansion.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | pass_nonterminal!(n!());
99
|
1010
= note: this error originates in the macro `pass_nonterminal` (in Nightly builds, run with -Z macro-backtrace for more info)
1111

12-
error[E0693]: incorrect `repr(align)` attribute format: `align` expect a literal integer as argument
12+
error[E0693]: incorrect `repr(align)` attribute format: `align` expects a literal integer as argument
1313
--> $DIR/nonterminal-expansion.rs:17:19
1414
|
1515
LL | pass_nonterminal!(n!());

tests/ui/repr/repr-align.stderr

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,84 @@
11
error[E0589]: invalid `repr(align)` attribute: not an unsuffixed integer
2-
--> $DIR/repr-align.rs:3:8
2+
--> $DIR/repr-align.rs:3:14
33
|
44
LL | #[repr(align(16.0))]
5-
| ^^^^^^^^^^^
5+
| ^^^^
66

77
error[E0589]: invalid `repr(align)` attribute: not a power of two
8-
--> $DIR/repr-align.rs:7:8
8+
--> $DIR/repr-align.rs:7:14
99
|
1010
LL | #[repr(align(15))]
11-
| ^^^^^^^^^
11+
| ^^
1212

1313
error[E0589]: invalid `repr(align)` attribute: larger than 2^29
14-
--> $DIR/repr-align.rs:11:8
14+
--> $DIR/repr-align.rs:11:14
1515
|
1616
LL | #[repr(align(4294967296))]
17-
| ^^^^^^^^^^^^^^^^^
17+
| ^^^^^^^^^^
1818

1919
error[E0589]: invalid `repr(align)` attribute: not an unsuffixed integer
20-
--> $DIR/repr-align.rs:18:8
20+
--> $DIR/repr-align.rs:18:14
2121
|
2222
LL | #[repr(align(16.0))]
23-
| ^^^^^^^^^^^
23+
| ^^^^
2424

2525
error[E0589]: invalid `repr(align)` attribute: not a power of two
26-
--> $DIR/repr-align.rs:22:8
26+
--> $DIR/repr-align.rs:22:14
2727
|
2828
LL | #[repr(align(15))]
29-
| ^^^^^^^^^
29+
| ^^
3030

3131
error[E0589]: invalid `repr(align)` attribute: larger than 2^29
32-
--> $DIR/repr-align.rs:26:8
32+
--> $DIR/repr-align.rs:26:14
3333
|
3434
LL | #[repr(align(4294967296))]
35-
| ^^^^^^^^^^^^^^^^^
35+
| ^^^^^^^^^^
3636

3737
error[E0589]: invalid `repr(align)` attribute: not an unsuffixed integer
38-
--> $DIR/repr-align.rs:3:8
38+
--> $DIR/repr-align.rs:3:14
3939
|
4040
LL | #[repr(align(16.0))]
41-
| ^^^^^^^^^^^
41+
| ^^^^
4242
|
4343
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
4444

4545
error[E0589]: invalid `repr(align)` attribute: not a power of two
46-
--> $DIR/repr-align.rs:7:8
46+
--> $DIR/repr-align.rs:7:14
4747
|
4848
LL | #[repr(align(15))]
49-
| ^^^^^^^^^
49+
| ^^
5050
|
5151
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
5252

5353
error[E0589]: invalid `repr(align)` attribute: larger than 2^29
54-
--> $DIR/repr-align.rs:11:8
54+
--> $DIR/repr-align.rs:11:14
5555
|
5656
LL | #[repr(align(4294967296))]
57-
| ^^^^^^^^^^^^^^^^^
57+
| ^^^^^^^^^^
5858
|
5959
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
6060

6161
error[E0589]: invalid `repr(align)` attribute: not an unsuffixed integer
62-
--> $DIR/repr-align.rs:18:8
62+
--> $DIR/repr-align.rs:18:14
6363
|
6464
LL | #[repr(align(16.0))]
65-
| ^^^^^^^^^^^
65+
| ^^^^
6666
|
6767
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
6868

6969
error[E0589]: invalid `repr(align)` attribute: not a power of two
70-
--> $DIR/repr-align.rs:22:8
70+
--> $DIR/repr-align.rs:22:14
7171
|
7272
LL | #[repr(align(15))]
73-
| ^^^^^^^^^
73+
| ^^
7474
|
7575
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
7676

7777
error[E0589]: invalid `repr(align)` attribute: larger than 2^29
78-
--> $DIR/repr-align.rs:26:8
78+
--> $DIR/repr-align.rs:26:14
7979
|
8080
LL | #[repr(align(4294967296))]
81-
| ^^^^^^^^^^^^^^^^^
81+
| ^^^^^^^^^^
8282
|
8383
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
8484

0 commit comments

Comments
 (0)