2014-08-29 15:21:28 +12:00
|
|
|
// Test that cross-borrowing (implicitly converting from `Box<T>` to `&T`) is
|
|
|
|
// forbidden when `T` is a trait.
|
|
|
|
|
|
|
|
struct Foo;
|
2015-02-18 15:58:07 -08:00
|
|
|
trait Trait { fn foo(&self) {} }
|
2014-08-29 15:21:28 +12:00
|
|
|
impl Trait for Foo {}
|
|
|
|
|
|
|
|
pub fn main() {
|
2019-05-28 14:46:13 -04:00
|
|
|
let x: Box<dyn Trait> = Box::new(Foo);
|
|
|
|
let _y: &dyn Trait = x; //~ ERROR E0308
|
2019-11-13 14:16:56 -08:00
|
|
|
//~| expected reference `&dyn Trait`
|
2020-09-02 10:40:56 +03:00
|
|
|
//~| found struct `Box<dyn Trait>`
|
2014-08-29 15:21:28 +12:00
|
|
|
}
|