-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[DO NOT MERGE] [crater experiment] make unaligned_referenced deny-by-default #72644
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
@bors try |
⌛ Trying commit 8c413c3 with merge 1a399c10897767c36d147199696c96f193034e49... |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
☀️ Try build successful - checks-azure |
@craterbot check |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
Lint from #72270 Does this lint also catch method calls, where |
It works on the MIR level, so it definitely should. Do you have a testcase? |
I haven't tried, so it probably works. Based on the PR, the test can be this? #![deny(unaligned_references)]
#[repr(packed)]
pub struct Good {
data: &'static u32,
data2: [&'static u32; 2],
data3: u64,
aligned: [u8; 32],
}
fn main() {
unsafe {
let good = Good { data: &0, data2: [&0, &0], data3: 0, aligned: [0; 32] };
let _ = good.data2.first(); //~ ERROR reference to packed field
let _ = good.data3.clone(); //~ ERROR reference to packed field
let _ = &good.data; //~ ERROR reference to packed field
let _ = &good.data as *const _; //~ ERROR reference to packed field
let _: *const _ = &good.data; //~ ERROR reference to packed field
let _ = &good.data2[0]; //~ ERROR reference to packed field
let _ = &*good.data; // ok, behind a pointer
let _ = &good.aligned; // ok, has align 1
let _ = &good.aligned[2]; // ok, has align 1
}
} I don't know if you are using references to have it be portable - I used d'oh I suppose it's better to just define the required methods in the test case. |
I copied that |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
I'd like to point out that the results of this crater run will very likely significantly underestimate the rate of violations as |
🎉 Experiment
|
Discussion of the results happens at #27060 (comment). |
@joshtriplett suggested we make a crater experiment to figure out how much code out there is creating bad references to packed fields.