Skip to content
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

Add more array references to raw pointer casts. #31418

Closed
wants to merge 20 commits into from
Closed
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
7 changes: 4 additions & 3 deletions src/librustc_typeck/check/cast.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
@@ -20,7 +20,8 @@
//! * `e` is a C-like enum and `U` is an integer type; *enum-cast*
//! * `e` has type `bool` or `char` and `U` is an integer; *prim-int-cast*
//! * `e` has type `u8` and `U` is `char`; *u8-char-cast*
//! * `e` has type `&[T; n]` and `U` is `*const T`; *array-ptr-cast*
//! * `e` has type `&.[T; n]` and `U` is `*T`,
//! while if `e` is `&[T; n]` then `U` is `*const T`; *array-ptr-cast*
//! * `e` is a function pointer type and `U` has type `*T`,
//! while `T: Sized`; *fptr-ptr-cast*
//! * `e` is a function pointer type and `U` is an integer; *fptr-addr-cast*
@@ -345,7 +346,7 @@ impl<'tcx> CastCheck<'tcx> {
{
// array-ptr-cast.

if m_expr.mutbl == hir::MutImmutable && m_cast.mutbl == hir::MutImmutable {
if !(m_expr.mutbl == hir::MutImmutable && m_cast.mutbl == hir::MutMutable) {
if let ty::TyArray(ety, _) = m_expr.ty.sty {
// Due to the limitations of LLVM global constants,
// region pointers end up pointing at copies of
14 changes: 14 additions & 0 deletions src/test/compile-fail/cast-mut-ref-to-const-ptr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn main() {
let my_num = &[10, 20] as *mut i32;
//~ error: casting `&[i32; 2]` as `*mut i32` is invalid
}
34 changes: 0 additions & 34 deletions src/test/compile-fail/vector-cast-weirdness.rs

This file was deleted.

7 changes: 5 additions & 2 deletions src/test/run-pass/cast.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
@@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.


pub fn main() {
let i: isize = 'Q' as isize;
assert_eq!(i, 0x51);
@@ -19,4 +18,8 @@ pub fn main() {
assert_eq!(i as u8 as i8, 'Q' as u8 as i8);
assert_eq!(0x51 as char, 'Q');
assert_eq!(0 as u32, false as u32);

let x = &[10, 20] as *const i32;
let y = &mut [10, 20] as *mut i32;
let z = &mut [10, 20] as *const i32;
}