rust/tests/ui/traits/safety-trait-impl.rs

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

19 lines
405 B
Rust
Raw Normal View History

2014-12-10 15:59:20 +00:00
// Check that unsafe traits require unsafe impls and that inherent
// impls cannot be unsafe.
trait SafeTrait {
2015-12-11 07:59:11 +00:00
fn foo(&self) { }
2014-12-10 15:59:20 +00:00
}
unsafe trait UnsafeTrait {
2015-12-11 07:59:11 +00:00
fn foo(&self) { }
2014-12-10 15:59:20 +00:00
}
unsafe impl UnsafeTrait for u8 { } // OK
impl UnsafeTrait for u16 { } //~ ERROR requires an `unsafe impl` declaration
unsafe impl SafeTrait for u32 { } //~ ERROR the trait `SafeTrait` is not unsafe
fn main() { }