rust/tests/ui/consts/const-trait-to-trait.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

25 lines
660 B
Rust
Raw Normal View History

// 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() {
2019-05-28 18:47:21 +00:00
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 {}
2019-05-28 18:47:21 +00:00
pub fn f() -> &'static dyn Encoding { UTF_8 as &'static dyn Encoding }
// Root of the problem: &Trait -> &Trait coercions:
2019-05-28 18:47:21 +00:00
const FOO: &'static dyn Trait = &Bar;
const BAR: &'static dyn Trait = FOO;
fn foo() { let _x = BAR; }