diff options
| author | bors <bors@rust-lang.org> | 2015-03-17 13:29:48 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-03-17 13:29:48 +0000 |
| commit | c64d671671aea2e44ee7fc6eb00ee75fc30ed7b9 (patch) | |
| tree | 058ec26f2e5ae48d415b7730c5f2d51df9b369a0 /src/test | |
| parent | 31ba21228e0e539a665ce14ab3a176e30e57f822 (diff) | |
| parent | 277b4f035aa7e42330aabbc243a8fcb5cf4cc8bd (diff) | |
| download | rust-c64d671671aea2e44ee7fc6eb00ee75fc30ed7b9.tar.gz rust-c64d671671aea2e44ee7fc6eb00ee75fc30ed7b9.zip | |
Auto merge of #23423 - nikomatsakis:issue-18737-trait-subtyping, r=nrc
This upcast coercion currently never requires vtable changes. It should be generalized. This is a [breaking-change] -- if you have an impl on an object type like `impl SomeTrait`, then this will no longer be applicable to object types like `SomeTrait+Send`. In the standard library, this primarily affected `Any`, and this PR adds impls for `Any+Send` as to keep the API the same in practice. An alternate workaround is to use UFCS form or standalone fns. For more details, see <https://github.com/rust-lang/rust/issues/18737#issuecomment-78450798>. r? @nrc
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/compile-fail/borrowck-consume-unsize-vec.rs | 22 | ||||
| -rw-r--r-- | src/test/compile-fail/borrowck-consume-upcast-box.rs | 24 | ||||
| -rw-r--r-- | src/test/compile-fail/retslot-cast.rs | 14 |
3 files changed, 56 insertions, 4 deletions
diff --git a/src/test/compile-fail/borrowck-consume-unsize-vec.rs b/src/test/compile-fail/borrowck-consume-unsize-vec.rs new file mode 100644 index 00000000000..32490e0dc7d --- /dev/null +++ b/src/test/compile-fail/borrowck-consume-unsize-vec.rs @@ -0,0 +1,22 @@ +// Copyright 2015 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. + +// Check that we report an error if an upcast box is moved twice. + +fn consume(_: Box<[i32]>) { +} + +fn foo(b: Box<[i32;5]>) { + consume(b); + consume(b); //~ ERROR use of moved value +} + +fn main() { +} diff --git a/src/test/compile-fail/borrowck-consume-upcast-box.rs b/src/test/compile-fail/borrowck-consume-upcast-box.rs new file mode 100644 index 00000000000..5bcafa675c7 --- /dev/null +++ b/src/test/compile-fail/borrowck-consume-upcast-box.rs @@ -0,0 +1,24 @@ +// Copyright 2015 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. + +// Check that we report an error if an upcast box is moved twice. + +trait Foo { fn dummy(&self); } + +fn consume(_: Box<Foo>) { +} + +fn foo(b: Box<Foo+Send>) { + consume(b); + consume(b); //~ ERROR use of moved value +} + +fn main() { +} diff --git a/src/test/compile-fail/retslot-cast.rs b/src/test/compile-fail/retslot-cast.rs index fafae0cb705..4ef07ecb438 100644 --- a/src/test/compile-fail/retslot-cast.rs +++ b/src/test/compile-fail/retslot-cast.rs @@ -12,9 +12,15 @@ #![allow(warnings)] pub fn fail(x: Option<& (Iterator+Send)>) -> Option<&Iterator> { - // This call used to trigger an LLVM assertion because the return slot had type - // "Option<&Iterator>"* instead of "Option<&(Iterator+Send)>"* - inner(x) + // This call used to trigger an LLVM assertion because the return + // slot had type "Option<&Iterator>"* instead of + // "Option<&(Iterator+Send)>"* -- but this now yields a + // compilation error and I'm not sure how to create a comparable + // test. To ensure that this PARTICULAR failure doesn't occur + // again, though, I've left this test here, so if this ever starts + // to compile again, we can adjust the test appropriately (clearly + // it should never ICE...). -nmatsakis + inner(x) //~ ERROR mismatched types } pub fn inner(x: Option<& (Iterator+Send)>) -> Option<&(Iterator+Send)> { @@ -22,4 +28,4 @@ pub fn inner(x: Option<& (Iterator+Send)>) -> Option<&(Iterator+Send)> { } #[rustc_error] -fn main() {} //~ ERROR compilation successful +fn main() {} |
