Repository navigation
Closed
rust-lang/rust
#164816Labels
C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveT-macrosType: Issues with macros and macro expansiongood first issueThese issues are a good way to get started with Clippy
Description
Summary
This lint should not be triggered on code generated by macros, but right now it is
Lint Name
redundant_field_names
Reproducer
I tried this code:
#[derive(Debug, thiserror::Error)]
pub enum SegmentDownloadingError {
// ...
/// Segment reconstruction error
#[error("Segment reconstruction error: {source}")]
SegmentReconstruction {
#[from]
source: ReconstructorError,
},
}Internally it is expanded to things like this:
#[allow(deprecated, unused_qualifications, )]
#[automatically_derived]
impl ::core::convert::From<ReconstructorError> for SegmentDownloadingError {
fn from(source: ReconstructorError) -> Self {
SegmentDownloadingError::SegmentReconstruction {
source: source,
}
}
}I saw this happen:
warning: redundant field names in struct initialization
--> crates/shared/ab-data-retrieval/src/segment_downloading.rs:48:9
|
48 | / #[from]
49 | | source: ReconstructorError,
| |______________^ help: replace it with: `source`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names
I expected to see this happen:
No lint should be triggered since it is outside of developer's control and generated by proc macro.
Version
rustc 1.99.0-nightly (1a98b1e13 2026-08-07)
binary: rustc
commit-hash: 1a98b1e135b254f209c67d447b6d8bcd56a859e0
commit-date: 2026-08-07
host: x86_64-unknown-linux-gnu
release: 1.99.0-nightly
LLVM version: 23.1.0
Additional Labels
No response
Reacted by yahvk, Jascha and wojciech-graj
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveT-macrosType: Issues with macros and macro expansiongood first issueThese issues are a good way to get started with Clippy
Activity
nazar-pc commentedon Aug 8, 2026
This was addressed by
thiserrorin dtolnay/thiserror#454, but I think it is still beneficial to resolve in clippy itselfchore(wire): allow Clippy lint in derived code
chore(wire): allow Clippy lint in derived code
nightcityblade commentedon Aug 10, 2026
Hi, I'd like to work on this. I'll submit a PR shortly.
nightcityblade commentedon Aug 10, 2026
@rustbot claim
chore(wire): allow Clippy lint in derived code
Merge #1263: chore(wire): allow Clippy lint in derived code
azdle commentedon Aug 12, 2026
I believe this is a bug introduced by @Jarcho's change in #17294, here:
https://github.com/rust-lang/rust-clippy/pull/17294/changes#diff-93cf0002fc1d8e941310800dda2bf3ff1c9cc7aa1a2f7437b38abe05b3132128
They replaced an early return check on
expr.span.in_external_macro(cx.sess().source_map())with a per-field check onfield.span.in_external_macro(cx.sess().source_map()).In my testing, the
expr.spanpoints at the#[derive(...)]line, but thefield.spans point at the original struct definition field line. So theexpras a whole isin_external_macro, but each individual field isn't. I'm not sure exactly why, but suspect the derive macro's output AST keeps the original span info when anIdentis used to construct theStructExpr's fields.I believe the solution is to just revert to doing the early return on
expr.span.in_external_macro(cx.sess().source_map()), but I don't really understand why that particular change was made in the first place.An example showing the misplaced spans.
For this `lib.rs`:And with a
dbg!(field);anddbg!(expr)added just beforespan_lint_and_suggthis is the log showing both the unintentional warning in the derive and the intentional warning in theext_new_sfunction.:add failing test for issue rust-lang#17525
kiana1kaslana commentedon Sep 7, 2026
I also want to work on it. @rustbot claim
build: fix clippy warning in derived code
Allow clippy::redundant_field_names in crates using derive_more::Cons…
chore(lint): Pass clippy and rustdoc on Rust 1.99, and deflake an Alp…
chore(clippy): "allow" new lint until false positive issue is fixed
chore(clippy): "allow" new lint until false positive issue is fixed
chore: cargo clippy fixes to prepare for the rustc upgrade: 1.98.1 ->…
chore: keep clippy clean on current stable
chore: fix new clippy errors from Rust v1.99.0
feat: support the secp256r1 ECDSA curve; release ic-cdk-management-ca…
Rollup merge of rust-lang#164816 - Jarcho:struct-init-span, r=Kivooeo
Unrolled build for #164816 in rollup 164894
Jarcho commentedon Oct 25, 2026
Fixed upstream: rust-lang/rust#164816
Rollup merge of #164816 - Jarcho:struct-init-span, r=Kivooeo
Rollup merge of #164816 - Jarcho:struct-init-span, r=Kivooeo