Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upFix cast-related ICEs #24158
Conversation
sanxiyn
added some commits
Apr 7, 2015
rust-highfive
assigned
Aatch
Apr 7, 2015
This comment has been minimized.
This comment has been minimized.
|
r? @Aatch (rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
|
cc @nrc |
This comment has been minimized.
This comment has been minimized.
nrc
commented on src/librustc_typeck/check/cast.rs in f4c2228
Apr 7, 2015
|
nit: put the !( on the same line as the clause |
This comment has been minimized.
This comment has been minimized.
nrc
commented on src/librustc_typeck/check/mod.rs in d18b405
Apr 7, 2015
|
need to check ty_uniq too |
This comment has been minimized.
This comment has been minimized.
nrc
replied
Apr 7, 2015
|
in fact, better to use ty::deref than to do the manual match |
This comment has been minimized.
This comment has been minimized.
|
I am not sure about using |
This comment has been minimized.
This comment has been minimized.
nrc
replied
Apr 8, 2015
|
The option part is pretty simple - if it returns None, then its not a pointer, so you can return false. You do throw away mutability, but you save code dup - you wouldn't have missed ty_uniq if you'd used it here and if we add another pointer type in the future, we might miss this function. |
This comment has been minimized.
This comment has been minimized.
|
That's convincing. Done. |
This comment has been minimized.
This comment has been minimized.
nrc
commented on src/test/compile-fail/fat-ptr-cast.rs in d18b405
Apr 7, 2015
|
should make each cast a separate statement so that we make sure the error is on the correct cast. Also, please add tests for the & and Box cases |
nrc
assigned
nrc
and unassigned
Aatch
Apr 7, 2015
This comment has been minimized.
This comment has been minimized.
|
lgtm, r=me with the comments addressed |
This comment has been minimized.
This comment has been minimized.
|
Addressed review comments. |
sanxiyn
force-pushed the
sanxiyn:cast
branch
from
a1b6923
to
e2ff188
Apr 8, 2015
This comment has been minimized.
This comment has been minimized.
|
I would also add a test for cast from a fn nullptr<T: ?Sized>() -> *const T {
0 as *const _
}
fn main() {
nullptr::<[();3]>();
nullptr::<[()]>();
}Also, |
This comment has been minimized.
This comment has been minimized.
|
There are more interesting cases: use std::fmt;
use std::iter::IntoIterator;
fn ptr_cast<U: ?Sized, V: ?Sized>(u: *const U) -> *const V
{
u as *const _
}
fn main() {
let i0 = [5u32];
let i1 = i0.into_iter();
let i2 : &Iterator<Item=&u32> = &i1;
let i3 = i2 as *const Iterator<Item=&u32>;
let p: *const fmt::Display = ptr_cast::<_, fmt::Display>(i3);
}I guess this needs a separate issue. |
sanxiyn commentedApr 7, 2015
Fix #13993.
Fix #17167.