rust/tests/ui/traits/impl.rs

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

42 lines
593 B
Rust
Raw Normal View History

// run-pass
2014-10-30 02:41:07 +00:00
// Test calling methods on an impl for a bare trait.
// aux-build:traitimpl.rs
extern crate traitimpl;
use traitimpl::Bar;
static mut COUNT: usize = 1;
2014-10-30 02:41:07 +00:00
2015-02-18 23:58:07 +00:00
trait T {
fn t(&self) {}
}
2014-10-30 02:41:07 +00:00
2019-05-28 18:47:21 +00:00
impl<'a> dyn T+'a {
2014-10-30 02:41:07 +00:00
fn foo(&self) {
unsafe { COUNT *= 2; }
}
fn bar() {
unsafe { COUNT *= 3; }
}
}
impl T for isize {}
2014-10-30 02:41:07 +00:00
struct Foo;
impl<'a> Bar<'a> for Foo {}
2014-10-30 02:41:07 +00:00
fn main() {
2019-05-28 18:47:21 +00:00
let x: &dyn T = &42;
2014-10-30 02:41:07 +00:00
x.foo();
<dyn T>::foo(x);
<dyn T>::bar();
2014-10-30 02:41:07 +00:00
unsafe { assert_eq!(COUNT, 12); }
// Cross-crait case
2019-05-28 18:47:21 +00:00
let x: &dyn Bar = &Foo;
x.bar();
2014-10-30 02:41:07 +00:00
}