Skip to content

Lints while expanding builtin derives are not attributed to the correct AST nodes #121171

@clubby789

Description

@clubby789

I tried this code:

#[deny(byte_slice_in_packed_struct_with_derive)]
#[repr(packed)]
#[derive(Hash)]
struct FlexZeroSlice {
    width: u8,
    data: [u8],
}

I expected to see this happen: The code does not compile, as the lint is triggered on the struct.

Instead, this happened: The code compiles with a warning, as the lint uses the crate-root NodeId for reporting.

(This lint specifically uses ast::CRATE_NODE_ID rather than ecx.current_expansion.lint_node_id, but the value of lint_node_id during builtin derive expansion is always ast::CRATE_NODE_ID)

Found while implementing a lint for #121053.

I had a brief go at fixing this but it looks like AST nodes are all still using dummy IDs at the point of builtin derive expansion and I'm unfamiliar with the AST renumbering

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions