Check attributes on struct expression fields.

Attributes on struct expression fields were not being checked for
validity. This adds the fields as HIR nodes so that `CheckAttrVisitor`
can visit those nodes to check their attributes.
This commit is contained in:
Eric Huss 2022-05-03 13:23:03 -07:00
parent 1b464c73b7
commit b651c1cebe
10 changed files with 47 additions and 18 deletions

View file

@ -126,6 +126,6 @@ fn main() {
struct PatternField {
foo: i32,
}
let s = PatternField { foo: 123 };
let s = PatternField { #[must_use] foo: 123 }; //~ ERROR `#[must_use]` has no effect
let PatternField { #[must_use] foo } = s; //~ ERROR `#[must_use]` has no effect
}

View file

@ -105,6 +105,12 @@ error: `#[must_use]` has no effect when applied to an match arm
LL | #[must_use]
| ^^^^^^^^^^^
error: `#[must_use]` has no effect when applied to a pattern field
--> $DIR/unused_attributes-must_use.rs:129:28
|
LL | let s = PatternField { #[must_use] foo: 123 };
| ^^^^^^^^^^^
error: `#[must_use]` has no effect when applied to a pattern field
--> $DIR/unused_attributes-must_use.rs:130:24
|
@ -177,5 +183,5 @@ error: unused return value of `Use::get_four` that must be used
LL | ().get_four();
| ^^^^^^^^^^^^^^
error: aborting due to 27 previous errors
error: aborting due to 28 previous errors