diff options
| author | Kivooeo <Kivooeo123@gmail.com> | 2025-07-18 22:06:07 +0500 |
|---|---|---|
| committer | Kivooeo <Kivooeo123@gmail.com> | 2025-07-25 20:38:54 +0500 |
| commit | e9959aa74e23eb340d6c9e9a4eab807be03b028f (patch) | |
| tree | 493df6b8c16382a44c1a8a51d5a1f5f7e416e5a7 /tests/ui/coercion/trait-object-arrays-11205.rs | |
| parent | 9f38ca97eab53ba2f431a48bec2343ef52335714 (diff) | |
| download | rust-e9959aa74e23eb340d6c9e9a4eab807be03b028f.tar.gz rust-e9959aa74e23eb340d6c9e9a4eab807be03b028f.zip | |
comments
Diffstat (limited to 'tests/ui/coercion/trait-object-arrays-11205.rs')
| -rw-r--r-- | tests/ui/coercion/trait-object-arrays-11205.rs | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/ui/coercion/trait-object-arrays-11205.rs b/tests/ui/coercion/trait-object-arrays-11205.rs new file mode 100644 index 00000000000..45d69dce323 --- /dev/null +++ b/tests/ui/coercion/trait-object-arrays-11205.rs @@ -0,0 +1,86 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/11205 + +//@ run-pass + +#![allow(dead_code)] + +trait Foo { fn dummy(&self) { } } +impl Foo for isize {} +fn foo(_: [&dyn Foo; 2]) {} +fn foos(_: &[&dyn Foo]) {} +fn foog<T>(_: &[T], _: &[T]) {} + +fn bar(_: [Box<dyn Foo>; 2]) {} +fn bars(_: &[Box<dyn Foo+'static>]) {} + +fn main() { + let x: [&dyn Foo; 2] = [&1, &2]; + foo(x); + foo([&1, &2]); + + let r = &1; + let x: [&dyn Foo; 2] = [r; 2]; + foo(x); + foo([&1; 2]); + + let x: &[&dyn Foo] = &[&1, &2]; + foos(x); + foos(&[&1, &2]); + + let x: &[&dyn Foo] = &[&1, &2]; + let r = &1; + foog(x, &[r]); + + let x: [Box<dyn Foo>; 2] = [Box::new(1), Box::new(2)]; + bar(x); + bar([Box::new(1), Box::new(2)]); + + let x: &[Box<dyn Foo+'static>] = &[Box::new(1), Box::new(2)]; + bars(x); + bars(&[Box::new(1), Box::new(2)]); + + let x: &[Box<dyn Foo+'static>] = &[Box::new(1), Box::new(2)]; + foog(x, &[Box::new(1)]); + + struct T<'a> { + t: [&'a (dyn Foo+'a); 2] + } + let _n = T { + t: [&1, &2] + }; + let r = &1; + let _n = T { + t: [r; 2] + }; + let x: [&dyn Foo; 2] = [&1, &2]; + let _n = T { + t: x + }; + + struct F<'b> { + t: &'b [&'b (dyn Foo+'b)] + } + let _n = F { + t: &[&1, &2] + }; + let r = &1; + let r: [&dyn Foo; 2] = [r; 2]; + let _n = F { + t: &r + }; + let x: [&dyn Foo; 2] = [&1, &2]; + let _n = F { + t: &x + }; + + struct M<'a> { + t: &'a [Box<dyn Foo+'static>] + } + let _n = M { + t: &[Box::new(1), Box::new(2)] + }; + let x: [Box<dyn Foo>; 2] = [Box::new(1), Box::new(2)]; + let _n = M { + t: &x + }; +} |
