Email me

Rust errors / Attributes, macros and features

Rust compiler error · checked with rustc 1.99.0

Rust error E0517: #### Note: this error code is no longer emitted by the compiler. This error code was replaced with the `attribute cannot be used on...` diagnostic that does not have an error code

What it means#### Note: this error code is no longer emitted by the compiler. This error code was replaced with the attribute cannot be used on... diagnostic that does not have an error code.

Retired: rustc no longer emits this error code. You may still see it in old answers, books and CI logs from older toolchains; the explanation below is kept for reference.

E0517Attributes, macros and features
Retiredin rustc 1.99.0
5related errors linked below

The compiler team's explanation

Note: this error code is no longer emitted by the compiler.

This error code was replaced with the attribute cannot be used on... diagnostic that does not have an error code.

A #[repr(..)] attribute was placed on an unsupported item.

Examples of erroneous code:

#[repr(C)]
type Foo = u8;

#[repr(packed)]
enum Foo {Bar, Baz}

#[repr(u8)]
struct Foo {bar: bool, baz: bool}

#[repr(C)]
impl Foo {
    // ...
}
  • The #[repr(C)] attribute can only be placed on structs and enums.
  • The #[repr(packed)] and #[repr(simd)] attributes only work on structs.
  • The #[repr(u8)], #[repr(i16)], etc attributes only work on enums.

These attributes do not work on typedefs, since typedefs are just aliases.

Representations like #[repr(u8)], #[repr(i64)] are for selecting the discriminant size for enums. For enums with no data fields on any of the variants, e.g. enum Color {Red, Blue, Green}, this effectively sets the size of the enum to the size of the provided type. Such an enum can be cast to a value of the same type as well. In short, #[repr(u8)] makes a field-less enum behave like an integer with a constrained set of allowed values.

For a description of how #[repr(C)] and representations like #[repr(u8)] affect the layout of enums with data fields, see RFC 2195.

Only field-less enums can be cast to numerical primitives. Representations like #[repr(u8)] will not apply to structs.

#[repr(packed)] reduces padding to make the struct size smaller. The representation of enums isn't strictly defined in Rust, and this attribute won't work on enums.

#[repr(simd)] will give a struct consisting of a homogeneous series of machine types (i.e., u8, i32, etc) a representation that permits vectorization via SIMD. This doesn't make much sense for enums since they don't consist of a single list of data.

From rustc --explain E0517 (1.99.0), part of the Rust project, MIT or Apache-2.0. Official page.

Related errors

All 518 Rust error codes · Rust crate data · Glossary

Up next

Often hit nextE0658: is unstableA related error from the same family.Read it next →

Did this answer your question?

Get the receipts by email.

What my AI agents tried this week, with the real numbers: what worked, what flopped, what made money. One email when there is something worth reading.

No spam, never sold. Every email has a one-click unsubscribe.

Popular in the shop

All 124 tools →

Browse: Bundles and kitsHome, family and schoolMoney and businessAI toolsSports and fitnessMaking and hobbiesFood and drinkIndie dev and launchTrading and quant

Free: Landing page teardown iPhone app cost calculator LLM API cost calculator Paid online: $49 Launch Check App builds Articles FAQ