-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
some fixes for clashing_extern_declarations lint #130301
Conversation
rustbot has assigned @petrochenkov. Use |
795ee23
to
e842eec
Compare
b_layout, | ||
a_layout == b_layout | ||
); | ||
Ok(a_layout == b_layout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ended up removing this logic entirely. It is never sound to do this, and none of the tests relied on this, so the motivation is unclear.
If this warns for too many real-world cases, people will tell us. :)
e842eec
to
f362a59
Compare
@@ -311,9 +311,9 @@ fn structurally_same_type_impl<'tcx>( | |||
}, | |||
) | |||
} | |||
(Array(a_ty, a_const), Array(b_ty, b_const)) => { | |||
// For arrays, we also check the constness of the type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"the constness" 💀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah...
Thanks for fixing this and I agree with the changes, even if they cause the lint to fire more aggressively it's like... objectively more correct. @bors r+ |
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#129320 (Fix crash when labeling arguments for call_once and friends) - rust-lang#130266 (target: default to the medium code model on LoongArch targets) - rust-lang#130297 (Dataflow cleanups) - rust-lang#130299 (Add set_dcx to ParseSess) - rust-lang#130301 (some fixes for clashing_extern_declarations lint) - rust-lang#130305 (Clippy: consider msrv for const context for const_float_bits_conv) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#129320 (Fix crash when labeling arguments for call_once and friends) - rust-lang#130266 (target: default to the medium code model on LoongArch targets) - rust-lang#130297 (Dataflow cleanups) - rust-lang#130299 (Add set_dcx to ParseSess) - rust-lang#130301 (some fixes for clashing_extern_declarations lint) - rust-lang#130305 (Clippy: consider msrv for const context for const_float_bits_conv) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#130301 - RalfJung:clashing_extern_declarations, r=compiler-errors some fixes for clashing_extern_declarations lint There were two issues with the clashing_extern_declarations lint: - It would accept non-`repr(C)` structs as compatible with each other by comparing their fields in declaration order, but the fields could have different memory order (and with `-Zrandomize-layout`, this can really happen). - It would accept two types as compatible if `compare_layouts` returns `true`, but that function actually just compared the *ABI*, not the fully layout -- and all sized structs with more than 2 fields have the same ABI (`Abi::Aggregate`), so this missed a *lot* of cases. We don't currently have a clear spec for what we *want* to consider "clashing" and what is fine, so I otherwise kept the original logic. I hope to have a t-lang discussion about this at some point. But meanwhile, these changes seem like clear bugfixes.
There were two issues with the clashing_extern_declarations lint:
repr(C)
structs as compatible with each other by comparing their fields in declaration order, but the fields could have different memory order (and with-Zrandomize-layout
, this can really happen).compare_layouts
returnstrue
, but that function actually just compared the ABI, not the fully layout -- and all sized structs with more than 2 fields have the same ABI (Abi::Aggregate
), so this missed a lot of cases.We don't currently have a clear spec for what we want to consider "clashing" and what is fine, so I otherwise kept the original logic. I hope to have a t-lang discussion about this at some point. But meanwhile, these changes seem like clear bugfixes.