Using the rust leveling function (question 33626)

RFC 1358 proposed an alignment attribute #[repr(align="N")]

and it was accepted. Rust issue 33626 included this feature in the nightly release.

I cannot use this function with rustc 1.19.0-nightly (777ee2079 2017-05-01)

. If I compile without a function element ( #![feature(repr_align)]

):

#[repr(align="16")]
struct Foo {
    bar: u32,
}

      

I am getting the following error:

error: the struct `#[repr(align(u16))]` attribute is experimental (see issue #33626)
 --> foo.rs:3:1
  |
3 | / struct Foo {
4 | |     bar: u32,
5 | | }
  | |_^
  |
  = help: add #![feature(repr_align)] to the crate attributes to enable

      

When I compile with a function element, the error message says:

error[E0552]: unrecognized representation hint
 --> foo.rs:3:8
  |
3 | #[repr(align="16")]
  |        ^^^^^^^^^^

      

I also tried the version suggested by the first error message (even if it doesn't match this issue) but still with no success. What is the correct way to use the align function?

+3


source to share


1 answer


You can use this function in conjunction with   attribute literals ( Playground ):

#![feature(repr_align)]
#![feature(attr_literals)]

#[repr(align(16))]
struct Foo {
    bar: u32,
}

      



It is known to work in the latest development release ( PR # 41673 ). Searching for "repr align" in the Rust compiler codebase, all occurrences rely on attribute literals, so it seems likely that the documented form repr(align="N")

is not supported yet.

+7


source







All Articles