mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
14 lines
414 B
Rust
14 lines
414 B
Rust
// Test that cross-borrowing (implicitly converting from `Box<T>` to `&T`) is
|
|
// forbidden when `T` is a trait.
|
|
|
|
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
|
|
//~| expected reference `&dyn Trait`
|
|
//~| found struct `Box<dyn Trait>`
|
|
}
|