summaryrefslogtreecommitdiffstats
path: root/tests/ui/consts/const-trait-to-trait.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/consts/const-trait-to-trait.rs')
-rw-r--r--tests/ui/consts/const-trait-to-trait.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/ui/consts/const-trait-to-trait.rs b/tests/ui/consts/const-trait-to-trait.rs
new file mode 100644
index 000000000..12a2999d7
--- /dev/null
+++ b/tests/ui/consts/const-trait-to-trait.rs
@@ -0,0 +1,24 @@
+// run-pass
+#![allow(dead_code)]
+#![allow(unused_variables)]
+// Issue #24644 - block causes a &Trait -> &Trait coercion:
+trait Trait {}
+
+struct Bar;
+impl Trait for Bar {}
+
+fn main() {
+ let x: &[&dyn Trait] = &[{ &Bar }];
+}
+
+// Issue #25748 - the cast causes an &Encoding -> &Encoding coercion:
+pub struct UTF8Encoding;
+pub const UTF_8: &'static UTF8Encoding = &UTF8Encoding;
+pub trait Encoding {}
+impl Encoding for UTF8Encoding {}
+pub fn f() -> &'static dyn Encoding { UTF_8 as &'static dyn Encoding }
+
+// Root of the problem: &Trait -> &Trait coercions:
+const FOO: &'static dyn Trait = &Bar;
+const BAR: &'static dyn Trait = FOO;
+fn foo() { let _x = BAR; }