summaryrefslogtreecommitdiffstats
path: root/tests/ui/consts/const-trait-to-trait.rs
blob: 12a2999d79d479ca00f93e9bcdcc3c0f1e93d8e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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; }