]> git.lizzy.rs Git - rust.git/blob - src/test/ui/cross/cross-borrow-trait.rs
Auto merge of #93718 - thomcc:used-macho, r=pnkfelix
[rust.git] / src / test / ui / cross / cross-borrow-trait.rs
1 // Test that cross-borrowing (implicitly converting from `Box<T>` to `&T`) is
2 // forbidden when `T` is a trait.
3
4 struct Foo;
5 trait Trait { fn foo(&self) {} }
6 impl Trait for Foo {}
7
8 pub fn main() {
9     let x: Box<dyn Trait> = Box::new(Foo);
10     let _y: &dyn Trait = x; //~ ERROR E0308
11                             //~| expected reference `&dyn Trait`
12                             //~| found struct `Box<dyn Trait>`
13 }