From: Mazdak Farrokhzad Date: Wed, 8 May 2019 22:58:28 +0000 (+0200) Subject: Rollup merge of #60627 - matklad:test, r=estebank X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=d20b6927569a308baf41ad58b854775961b49bf7;hp=b04f87fedee0eddca91b12666153dfb62f105715;p=rust.git Rollup merge of #60627 - matklad:test, r=estebank test for #50518 It was fixed somewhere between 1.28.0 and 1.31.1 closes #50518 r? @estebank Where's the best place to add this test? I *think* we want "compile-pass" for this test (no need to run a binary, and not running saves us a millisecond of process creation) , but there's no compile-pass anymore. Should this be UI test with empty stdout, stderr and zero return code? --- diff --git a/src/test/ui/issues/issue-50518.rs b/src/test/ui/issues/issue-50518.rs new file mode 100644 index 00000000000..d776d181b62 --- /dev/null +++ b/src/test/ui/issues/issue-50518.rs @@ -0,0 +1,40 @@ +// compile-pass +use std::marker::PhantomData; + +struct Meta { + value: i32, + type_: PhantomData +} + +trait MetaTrait { + fn get_value(&self) -> i32; +} + +impl MetaTrait for Meta { + fn get_value(&self) -> i32 { self.value } +} + +trait Bar { + fn get_const(&self) -> &dyn MetaTrait; +} + +struct Foo { + _value: A +} + +impl Foo { + const CONST: &'static dyn MetaTrait = &Meta:: { + value: 10, + type_: PhantomData + }; +} + +impl Bar for Foo { + fn get_const(&self) -> &dyn MetaTrait { Self::CONST } +} + +fn main() { + let foo = Foo:: { _value: 10 }; + let bar: &dyn Bar = &foo; + println!("const {}", bar.get_const().get_value()); +}