about summary refs log tree commit diff
path: root/tests/ui/cross/cross-borrow-trait.rs
blob: 88ea78e44b3a4353187154d1ccfa955dbb3ba643 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Test that cross-borrowing (implicitly converting from `Box<T>` to `&T`) is
// forbidden when `T` is a trait.

//@ dont-require-annotations: NOTE

struct Foo;
trait Trait { fn foo(&self) {} }
impl Trait for Foo {}

pub fn main() {
    let x: Box<dyn Trait> = Box::new(Foo);
    let _y: &dyn Trait = x; //~ ERROR E0308
                            //~| NOTE expected reference `&dyn Trait`
                            //~| NOTE found struct `Box<dyn Trait>`
}