diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2016-05-20 15:49:53 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2016-05-20 15:49:53 +0200 |
| commit | 4913e88c006533f211f7d3c8a6bf9a3de17c8d89 (patch) | |
| tree | 76a630f8357216b98b175e24c416f822b5cb6efb /src/test | |
| parent | 5dc8dfa86ff0862c8fa93f794f12c03007023b2e (diff) | |
| parent | 94f0918c19a6f4f260535620cf66b6c4589d7a67 (diff) | |
| download | rust-4913e88c006533f211f7d3c8a6bf9a3de17c8d89.tar.gz rust-4913e88c006533f211f7d3c8a6bf9a3de17c8d89.zip | |
Rollup merge of #33734 - luqmana:33387-mir_fat_ptr_coerce, r=arielb1
[MIR] Add PointerCast for Unsize casts of fat pointers. Fixes #33387. r? @eddyb
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/run-pass/issue-33387.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/test/run-pass/issue-33387.rs b/src/test/run-pass/issue-33387.rs new file mode 100644 index 00000000000..a4b85bc7a09 --- /dev/null +++ b/src/test/run-pass/issue-33387.rs @@ -0,0 +1,44 @@ +// 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. + +#![feature(rustc_attrs)] + +use std::sync::Arc; + +trait Foo { + fn get(&self) -> [u8; 2]; +} + +impl Foo for [u8; 2] { + fn get(&self) -> [u8; 2] { + *self + } +} + +struct Bar<T: ?Sized>(T); + +#[rustc_mir] +fn unsize_fat_ptr<'a>(x: &'a Bar<Foo + Send + 'a>) -> &'a Bar<Foo + 'a> { + x +} + +#[rustc_mir] +fn unsize_nested_fat_ptr(x: Arc<Foo + Send>) -> Arc<Foo> { + x +} + +#[rustc_mir] +fn main() { + let x: Box<Bar<Foo + Send>> = Box::new(Bar([1,2])); + assert_eq!(unsize_fat_ptr(&*x).0.get(), [1, 2]); + + let x: Arc<Foo + Send> = Arc::new([3, 4]); + assert_eq!(unsize_nested_fat_ptr(x).get(), [3, 4]); +} |
