-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Lint casting signed integers smaller than isize
to raw pointers
#43641
Lint casting signed integers smaller than isize
to raw pointers
#43641
Conversation
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
Whoa whoa what is all this new code? I expected a trivial check to be used only for a cargobomb run. |
cc @rust-lang/compiler |
This code exists so we don't produce a suggestion like |
Ah, great! Would've been less surprising to see that in the PR description. However, I'd still start small, with an error-by-default lint with no interesting suggestions, for cargobomb. |
2bea2ab
to
84bed45
Compare
done |
src/test/run-pass/mir_misc_casts.rs
Outdated
@@ -120,7 +120,7 @@ fn from_1i8() | |||
let c10 = 1_i8 as u64; | |||
let c11 = 1_i8 as f32; | |||
let c12 = 1_i8 as f64; | |||
let c13 = 1_i8 as *const libc::FILE; | |||
let c13 = 1_i8 as isize as *const libc::FILE; |
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 correct cast btw is through usize
. Although... I'd leave the tests unchanged and just allow the lint in them.
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.
There is some overlap between this and #43339 btw.
src/librustc_lint/builtin.rs
Outdated
ty::TyInt(ast::IntTy::Is) => return, | ||
ty::TyInt(ast::IntTy::I128) | | ||
ty::TyInt(ast::IntTy::I64) => { | ||
if cx.tcx.data_layout.pointer_size.bytes() >= 8 { |
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.
This doesn't seem right. I think this should be <=
and the if
needs to be part of the match pattern to allow this to fall through:
ty::TyInt(ast::IntTy::I128) |
ty::TyInt(ast::IntTy::I64) if cx.tcx.data_layout.pointer_size.bytes() <= 8 => {
return;
},
ty::TyInt(ast::IntTy::I32) if cx.tcx.data_layout.pointer_size.bytes() <= 4 => {
return;
},
ty::TyInt(ast::IntTy::I16) if cx.tcx.data_layout.pointer_size.bytes() <= 2 => {
return;
},
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.
thanks! you're right of course, I got the logic reversed.
src/librustc_lint/builtin.rs
Outdated
// these we report | ||
ty::TyInt(_) => {}, | ||
// only int casts are relevant | ||
_ => {}, |
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 assume there's supposed to be a return
here.
@eddyb I assume you will be starting the cargobomb? |
Looks like there's an error in the book. I opened a PR upstream: rust-lang/book#866. |
Upstream PR has merged. Updating the in-tree book submodule now: #43688. |
Thanks for taking care of that! |
isize
/usize
to raw pointersisize
to raw pointers
Primarily to pick up this change: rust-lang/book#866 ...to move this PR forward: rust-lang#43641
Bump 'src/doc/book' git submodule. Primarily to pick up this change: rust-lang/book#866 ...to move this PR forward: #43641
@oli-obk the book should be good now, you should rebase or merge in master |
@frewsxcv Always rebase 😛! |
ca5681e
to
72c77e9
Compare
ping @eddyb |
@bors try |
…<try> Lint casting signed integers smaller than `isize` to raw pointers cc #43291 (keeping open as tracking issue)
☀️ Test successful - status-travis |
cc @rust-lang/infra Cargobomb crater requested. |
I'll get this cargobomb run going. |
Cargobomb run failed, the disk filled up because I failed to do due diligence on disk space beforehand - sorry! I'll prepare a new run now. |
Cargobomb complete: http://cargobomb-reports.s3.amazonaws.com/pr-43641/index.html |
I'll check the ones below once there's a PR against them
irrelevant failures
|
@oli-obk So the thing we were worried about was whether any of these would need the (buggy) zero-extension behavior, to know if we can just fix it right away. |
I have checked everything but |
Closing in favour of simply making the backwards incompatible fix |
cc #43291 (keeping open as tracking issue)