Skip to content

Commit eefd598

Browse files
committed
correct template for #[align]
it should not suggest just `#[align]`
1 parent 8a65ee0 commit eefd598

File tree

6 files changed

+36
-34
lines changed

6 files changed

+36
-34
lines changed

compiler/rustc_attr_parsing/src/attributes/repr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ pub(crate) struct AlignParser(Option<(Align, Span)>);
273273

274274
impl AlignParser {
275275
const PATH: &'static [Symbol] = &[sym::align];
276-
const TEMPLATE: AttributeTemplate = template!(Word, List: "<alignment in bytes>");
276+
const TEMPLATE: AttributeTemplate = template!(List: "<alignment in bytes>");
277277

278278
fn parse<'c, S: Stage>(
279279
&mut self,

compiler/rustc_feature/src/unstable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ declare_features! (
510510
(unstable, ffi_pure, "1.45.0", Some(58329)),
511511
/// Controlling the behavior of fmt::Debug
512512
(unstable, fmt_debug, "1.82.0", Some(129709)),
513-
/// Allows using `#[repr(align(...))]` on function items
513+
/// Allows using `#[align(...)]` on function items
514514
(unstable, fn_align, "1.53.0", Some(82232)),
515515
/// Support delegating implementation of functions to other already implemented functions.
516516
(incomplete, fn_delegation, "1.76.0", Some(118212)),

src/doc/unstable-book/src/compiler-flags/min-function-alignment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This flag is equivalent to:
1515
- `-fmin-function-alignment` for [GCC](https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-fmin-function-alignment_003dn)
1616
- `-falign-functions` for [Clang](https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang1-falign-functions)
1717

18-
The specified alignment is a minimum. A higher alignment can be specified for specific functions by using the [`repr(align(...))`](https://github.com/rust-lang/rust/issues/82232) feature and annotating the function with a `#[repr(align(<align>))]` attribute. The attribute's value is ignored when it is lower than the value passed to `min-function-alignment`.
18+
The specified alignment is a minimum. A higher alignment can be specified for specific functions by using the [`align(...)`](https://github.com/rust-lang/rust/issues/82232) feature and annotating the function with a `#[align(<align>)]` attribute. The attribute's value is ignored when it is lower than the value passed to `min-function-alignment`.
1919

2020
There are two additional edge cases for this flag:
2121

tests/ui/attributes/malformed-fn-align.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33

44
trait MyTrait {
55
#[align] //~ ERROR malformed `align` attribute input
6-
fn myfun();
6+
fn myfun1();
7+
8+
#[align(1, 2)] //~ ERROR malformed `align` attribute input
9+
fn myfun2();
710
}
811

912
#[align = 16] //~ ERROR malformed `align` attribute input

tests/ui/attributes/malformed-fn-align.stderr

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,55 @@ error[E0539]: malformed `align` attribute input
22
--> $DIR/malformed-fn-align.rs:5:5
33
|
44
LL | #[align]
5-
| ^^^^^^^^ expected this to be a list
6-
|
7-
help: try changing it to one of the following valid forms of the attribute
8-
|
9-
LL | #[align(<alignment in bytes>)]
10-
| ++++++++++++++++++++++
5+
| ^^^^^^^^
6+
| |
7+
| expected this to be a list
8+
| help: must be of the form: `#[align(<alignment in bytes>)]`
9+
10+
error[E0805]: malformed `align` attribute input
11+
--> $DIR/malformed-fn-align.rs:8:5
12+
|
13+
LL | #[align(1, 2)]
14+
| ^^^^^^^------^
15+
| | |
16+
| | expected a single argument here
17+
| help: must be of the form: `#[align(<alignment in bytes>)]`
1118

1219
error[E0539]: malformed `align` attribute input
13-
--> $DIR/malformed-fn-align.rs:9:1
20+
--> $DIR/malformed-fn-align.rs:12:1
1421
|
1522
LL | #[align = 16]
16-
| ^^^^^^^^^^^^^ expected this to be a list
17-
|
18-
help: try changing it to one of the following valid forms of the attribute
19-
|
20-
LL - #[align = 16]
21-
LL + #[align(<alignment in bytes>)]
22-
|
23-
LL - #[align = 16]
24-
LL + #[align]
25-
|
23+
| ^^^^^^^^^^^^^
24+
| |
25+
| expected this to be a list
26+
| help: must be of the form: `#[align(<alignment in bytes>)]`
2627

2728
error[E0589]: invalid alignment value: not an unsuffixed integer
28-
--> $DIR/malformed-fn-align.rs:12:9
29+
--> $DIR/malformed-fn-align.rs:15:9
2930
|
3031
LL | #[align("hello")]
3132
| ^^^^^^^
3233

3334
error[E0589]: invalid alignment value: not a power of two
34-
--> $DIR/malformed-fn-align.rs:15:9
35+
--> $DIR/malformed-fn-align.rs:18:9
3536
|
3637
LL | #[align(0)]
3738
| ^
3839

3940
error: `#[repr(align(...))]` is not supported on function items
40-
--> $DIR/malformed-fn-align.rs:18:8
41+
--> $DIR/malformed-fn-align.rs:21:8
4142
|
4243
LL | #[repr(align(16))]
4344
| ^^^^^^^^^
4445
|
4546
help: use `#[align(...)]` instead
46-
--> $DIR/malformed-fn-align.rs:18:8
47+
--> $DIR/malformed-fn-align.rs:21:8
4748
|
4849
LL | #[repr(align(16))]
4950
| ^^^^^^^^^
5051

5152
error: `#[align(...)]` is not supported on struct items
52-
--> $DIR/malformed-fn-align.rs:21:1
53+
--> $DIR/malformed-fn-align.rs:24:1
5354
|
5455
LL | #[align(16)]
5556
| ^^^^^^^^^^^^
@@ -60,7 +61,7 @@ LL - #[align(16)]
6061
LL + #[repr(align(16))]
6162
|
6263

63-
error: aborting due to 6 previous errors
64+
error: aborting due to 7 previous errors
6465

65-
Some errors have detailed explanations: E0539, E0589.
66+
Some errors have detailed explanations: E0539, E0589, E0805.
6667
For more information about an error, try `rustc --explain E0539`.

tests/ui/feature-gates/feature-gate-fn_align.stderr

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ error[E0539]: malformed `align` attribute input
2222
--> $DIR/feature-gate-fn_align.rs:8:5
2323
|
2424
LL | #[align]
25-
| ^^^^^^^^ expected this to be a list
26-
|
27-
help: try changing it to one of the following valid forms of the attribute
28-
|
29-
LL | #[align(<alignment in bytes>)]
30-
| ++++++++++++++++++++++
25+
| ^^^^^^^^
26+
| |
27+
| expected this to be a list
28+
| help: must be of the form: `#[align(<alignment in bytes>)]`
3129

3230
error: aborting due to 3 previous errors
3331

0 commit comments

Comments
 (0)