- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 89
Closed
Labels
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.
Metadata
Metadata
Assignees
Labels
Projects
Milestone
Relationships
Development
Select code repository
Activity
dtolnay commentedon Jan 31, 2020
This is a compiler bug. Based on adding the following to the macro,
rustc is passing in:
dtolnay commentedon Feb 2, 2020
Fixed in rust-lang/rust#68737.