Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
clubby789 opened this issue Feb 16, 2024 · 0 comments
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@clubby789
Copy link
Contributor

clubby789 commented Feb 16, 2024

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

@clubby789 clubby789 added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. labels Feb 16, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 16, 2024
@clubby789 clubby789 changed the title Lints in builtin derives are not attributed to the correct AST nodes Lints while expanding builtin derives are not attributed to the correct AST nodes Feb 16, 2024
@jieyouxu jieyouxu added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants