rust/tests/ui/cross/cross-borrow-trait.rs

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

14 lines
414 B
Rust
Raw Normal View History

// Test that cross-borrowing (implicitly converting from `Box<T>` to `&T`) is
// forbidden when `T` is a trait.
struct Foo;
2015-02-18 23:58:07 +00:00
trait Trait { fn foo(&self) {} }
impl Trait for Foo {}
pub fn main() {
2019-05-28 18:46:13 +00:00
let x: Box<dyn Trait> = Box::new(Foo);
let _y: &dyn Trait = x; //~ ERROR E0308
//~| expected reference `&dyn Trait`
//~| found struct `Box<dyn Trait>`
}