diff options
| author | bors <bors@rust-lang.org> | 2017-12-25 23:00:39 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-12-25 23:00:39 +0000 |
| commit | ebddfcb0b19471d2277e05cfbc2ad8caa81637b7 (patch) | |
| tree | bc185614ad147bb147c3c8cec167850384d1d7d2 /src/test | |
| parent | 4a7c072fa61b42f96d8b75c37fc1edfd71172695 (diff) | |
| parent | 6aca3301491bc11bf403b9abeedcfbd63c2a43fd (diff) | |
Auto merge of #46973 - arielb1:tuple-casting, r=estebank
Update check::cast::pointer_kind logic to new rustc Make the match exhaustive, adding handling for anonymous types and tuple coercions on the way. Also, exit early when type errors are detected, to avoid error cascades and the like. Fixes #33690. Fixes #46365. Fixes #46880.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/run-pass/cast-rfc0401-vtable-kinds.rs | 17 | ||||
| -rw-r--r-- | src/test/ui/cast-errors-issue-43825.rs | 17 | ||||
| -rw-r--r-- | src/test/ui/cast-errors-issue-43825.stderr | 8 | ||||
| -rw-r--r-- | src/test/ui/casts-differing-anon.rs | 34 | ||||
| -rw-r--r-- | src/test/ui/casts-differing-anon.stderr | 10 | ||||
| -rw-r--r-- | src/test/ui/casts-issue-46365.rs | 17 | ||||
| -rw-r--r-- | src/test/ui/casts-issue-46365.stderr | 8 |
7 files changed, 111 insertions, 0 deletions
diff --git a/src/test/run-pass/cast-rfc0401-vtable-kinds.rs b/src/test/run-pass/cast-rfc0401-vtable-kinds.rs index 3a9f24ad4cc..32a155c13e6 100644 --- a/src/test/run-pass/cast-rfc0401-vtable-kinds.rs +++ b/src/test/run-pass/cast-rfc0401-vtable-kinds.rs @@ -11,6 +11,8 @@ // Check that you can cast between different pointers to trait objects // whose vtable have the same kind (both lengths, or both trait pointers). +#![feature(unsized_tuple_coercion)] + trait Foo<T> { fn foo(&self, _: T) -> u32 { 42 } } @@ -39,6 +41,11 @@ fn foo_to_bar<T:?Sized>(u: *const FooS<T>) -> *const BarS<T> { u as *const BarS<T> } +fn tuple_i32_to_u32<T:?Sized>(u: *const (i32, T)) -> *const (u32, T) { + u as *const (u32, T) +} + + fn main() { let x = 4u32; let y : &Foo<u32> = &x; @@ -51,4 +58,14 @@ fn main() { let bar_ref : *const BarS<[u32]> = foo_to_bar(u); let z : &BarS<[u32]> = unsafe{&*bar_ref}; assert_eq!(&z.0, &[0,1,2]); + + // this assumes that tuple reprs for (i32, _) and (u32, _) are + // the same. + let s = (0i32, [0, 1, 2]); + let u: &(i32, [u8]) = &s; + let u: *const (i32, [u8]) = u; + let u_u32 : *const (u32, [u8]) = tuple_i32_to_u32(u); + unsafe { + assert_eq!(&(*u_u32).1, &[0, 1, 2]); + } } diff --git a/src/test/ui/cast-errors-issue-43825.rs b/src/test/ui/cast-errors-issue-43825.rs new file mode 100644 index 00000000000..65b391205e3 --- /dev/null +++ b/src/test/ui/cast-errors-issue-43825.rs @@ -0,0 +1,17 @@ +// Copyright 2017 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 error = error; //~ ERROR cannot find value `error` + + // These used to cause errors. + 0 as f32; + 0.0 as u32; +} diff --git a/src/test/ui/cast-errors-issue-43825.stderr b/src/test/ui/cast-errors-issue-43825.stderr new file mode 100644 index 00000000000..db0a33e927f --- /dev/null +++ b/src/test/ui/cast-errors-issue-43825.stderr @@ -0,0 +1,8 @@ +error[E0425]: cannot find value `error` in this scope + --> $DIR/cast-errors-issue-43825.rs:12:17 + | +12 | let error = error; //~ ERROR cannot find value `error` + | ^^^^^ not found in this scope + +error: aborting due to previous error + diff --git a/src/test/ui/casts-differing-anon.rs b/src/test/ui/casts-differing-anon.rs new file mode 100644 index 00000000000..74c8ff370f9 --- /dev/null +++ b/src/test/ui/casts-differing-anon.rs @@ -0,0 +1,34 @@ +// Copyright 2017 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. + +#![feature(conservative_impl_trait)] + +use std::fmt; + +fn foo() -> Box<impl fmt::Debug+?Sized> { + let x : Box<[u8]> = Box::new([0]); + x +} +fn bar() -> Box<impl fmt::Debug+?Sized> { + let y: Box<fmt::Debug> = Box::new([0]); + y +} + +fn main() { + let f = foo(); + let b = bar(); + + // this is an `*mut [u8]` in practice + let f_raw : *mut _ = Box::into_raw(f); + // this is an `*mut fmt::Debug` in practice + let mut b_raw = Box::into_raw(b); + // ... and they should not be mixable + b_raw = f_raw as *mut _; //~ ERROR is invalid +} diff --git a/src/test/ui/casts-differing-anon.stderr b/src/test/ui/casts-differing-anon.stderr new file mode 100644 index 00000000000..8db6854dba9 --- /dev/null +++ b/src/test/ui/casts-differing-anon.stderr @@ -0,0 +1,10 @@ +error[E0606]: casting `*mut impl std::fmt::Debug+?Sized` as `*mut impl std::fmt::Debug+?Sized` is invalid + --> $DIR/casts-differing-anon.rs:33:13 + | +33 | b_raw = f_raw as *mut _; //~ ERROR is invalid + | ^^^^^^^^^^^^^^^ + | + = note: vtable kinds may not match + +error: aborting due to previous error + diff --git a/src/test/ui/casts-issue-46365.rs b/src/test/ui/casts-issue-46365.rs new file mode 100644 index 00000000000..79f636e413f --- /dev/null +++ b/src/test/ui/casts-issue-46365.rs @@ -0,0 +1,17 @@ +// Copyright 2017 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. + +struct Lorem { + ipsum: Ipsum //~ ERROR cannot find type `Ipsum` +} + +fn main() { + let _foo: *mut Lorem = 0 as *mut _; // no error here +} diff --git a/src/test/ui/casts-issue-46365.stderr b/src/test/ui/casts-issue-46365.stderr new file mode 100644 index 00000000000..ce3c8593a97 --- /dev/null +++ b/src/test/ui/casts-issue-46365.stderr @@ -0,0 +1,8 @@ +error[E0412]: cannot find type `Ipsum` in this scope + --> $DIR/casts-issue-46365.rs:12:12 + | +12 | ipsum: Ipsum //~ ERROR cannot find type `Ipsum` + | ^^^^^ not found in this scope + +error: aborting due to previous error + |
