Closed
Description
When attributes appear inside of a function in a trait implementation decorated with #[async_trait]
, those attributes can be dropped depending on what they're decorating. In particular, attributes decorating fields are dropped entirely.
Consider the following example:
#[async_trait::async_trait]
trait Foo: Sized {
fn g(&self);
}
struct K { field: usize }
#[async_trait::async_trait]
impl Foo for K {
fn g(&self) {
let _ = K {
#[cfg(debug_assertions)]
field: 0,
#[cfg(not(debug_assertions))]
field: 1,
};
}
}
This impl
expand to:
impl Foo for K {
fn g(&self) {
let _ = K { field: 0, field: 1, };
}
}
Which results in the (incorrect) compile-time error:
error[E0062]: field `field` specified more than once
error: aborting due to previous error
Note that span information appears to be lost as well.