Skip to content

librustc: Enum nullable pointer opt should not apply to raw pointers. #17182

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/librustc/middle/trans/adt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,8 @@ impl Case {

for (i, &ty) in self.tys.iter().enumerate() {
match ty::get(ty).sty {
// &T/&mut T/*T could either be a thin or fat pointer depending on T
ty::ty_rptr(_, ty::mt { ty, .. })
| ty::ty_ptr(ty::mt { ty, .. }) => match ty::get(ty).sty {
// &T/&mut T could either be a thin or fat pointer depending on T
ty::ty_rptr(_, ty::mt { ty, .. }) => match ty::get(ty).sty {
// &[T] and &str are a pointer and length pair
ty::ty_vec(_, None) | ty::ty_str => return Some(FatPointer(i, slice_elt_base)),

Expand Down
5 changes: 5 additions & 0 deletions src/test/run-pass/enum-null-pointer-opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ fn main() {
assert_eq!(size_of::<Box<int>>(), size_of::<Option<Box<int>>>());
assert_eq!(size_of::<Gc<int>>(), size_of::<Option<Gc<int>>>());


// The optimization can't apply to raw pointers
assert!(size_of::<Option<*const int>>() != size_of::<*const int>());
assert!(Some(0 as *const int).is_some()); // Can't collapse None to null

}