Skip to content

Empty attributes not parsing as expected #24

@lthoerner

Description

@lthoerner

When deriving ExtractAttributes on an attribute struct with no fields, such as in the following examples:

#[derive(ExtractAttributes)]
#[deluxe(attributes(my_attribute_1)]
struct MyStruct1;

#[derive(ExtractAttributes)]
#[deluxe(attributes(my_attribute_2)]
struct MyStruct2();

#[derive(ExtractAttributes)]
#[deluxe(attributes(my_attribute_3)]
struct MyStruct3 {}

extract_attributes() does not work as it would be expected to. Instead of returning Err(_) it returns Ok(_) whether or not there is an attribute with the correct name on the type.

#[derive(MyTrait)]
#[my_attribute_1]
struct MyStructWithAttribute {
    my_field: MyType,
}

#[derive(MyTrait)]
struct MyStructWithoutAttribute {
    my_field: MyType,
}

// In the derive for `MyStructWithAttribute`:
let attribute: Option<MyAttribute> = extract_attributes(&mut ast); // Evaluates to Some(_)

// In the derive for `MyStructWithoutAttribute`:
let attribute: Option<MyAttribute> = extract_attributes(&mut ast); // Evaluates to Some(_)

The expected behavior would be that MyStructWithoutAttribute's derive would return an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions