File: by-value-trait-object-safety.rs

package info (click to toggle)
rustc-web 1.70.0%2Bdfsg1-7~deb12u2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,517,048 kB
  • sloc: xml: 147,962; javascript: 10,210; sh: 8,590; python: 8,220; ansic: 5,901; cpp: 4,635; makefile: 4,006; asm: 2,856
file content (22 lines) | stat: -rw-r--r-- 388 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#![feature(unsized_locals)]
//~^ WARN the feature `unsized_locals` is incomplete

pub trait Foo {
    fn foo(self) -> String
    where
        Self: Sized;
}

struct A;

impl Foo for A {
    fn foo(self) -> String {
        format!("hello")
    }
}

fn main() {
    let x = *(Box::new(A) as Box<dyn Foo>);
    x.foo();
    //~^ERROR the `foo` method cannot be invoked on a trait object
}