rust/src/test/ui/lint/lint-unsafe-code.rs

96 lines
2.4 KiB
Rust
Raw Normal View History

#![allow(unused_unsafe)]
#![allow(dead_code)]
#![deny(unsafe_code)]
struct Bar;
struct Bar2;
struct Bar3;
#[allow(unsafe_code)]
mod allowed_unsafe {
fn allowed() { unsafe {} }
unsafe fn also_allowed() {}
2015-03-31 19:58:01 -04:00
unsafe trait AllowedUnsafe { }
unsafe impl AllowedUnsafe for super::Bar {}
#[no_mangle] fn allowed2() {}
}
macro_rules! unsafe_in_macro {
() => {{
#[no_mangle] fn foo() {} //~ ERROR: declaration of a `no_mangle` function
#[no_mangle] static FOO: u32 = 5; //~ ERROR: declaration of a `no_mangle` static
unsafe {} //~ ERROR: usage of an `unsafe` block
}}
}
#[no_mangle] fn foo() {} //~ ERROR: declaration of a `no_mangle` function
#[no_mangle] static FOO: u32 = 5; //~ ERROR: declaration of a `no_mangle` static
unsafe fn baz() {} //~ ERROR: declaration of an `unsafe` function
2015-03-31 19:58:01 -04:00
unsafe trait Foo {} //~ ERROR: declaration of an `unsafe` trait
unsafe impl Foo for Bar {} //~ ERROR: implementation of an `unsafe` trait
trait Baz {
unsafe fn baz(&self); //~ ERROR: declaration of an `unsafe` method
unsafe fn provided(&self) {} //~ ERROR: implementation of an `unsafe` method
unsafe fn provided_override(&self) {} //~ ERROR: implementation of an `unsafe` method
}
impl Baz for Bar {
unsafe fn baz(&self) {} //~ ERROR: implementation of an `unsafe` method
unsafe fn provided_override(&self) {} //~ ERROR: implementation of an `unsafe` method
}
#[allow(unsafe_code)]
trait A {
unsafe fn allowed_unsafe(&self);
unsafe fn allowed_unsafe_provided(&self) {}
}
#[allow(unsafe_code)]
impl Baz for Bar2 {
unsafe fn baz(&self) {}
unsafe fn provided_override(&self) {}
}
impl Baz for Bar3 {
#[allow(unsafe_code)]
unsafe fn baz(&self) {}
unsafe fn provided_override(&self) {} //~ ERROR: implementation of an `unsafe` method
}
#[allow(unsafe_code)]
unsafe trait B {
fn dummy(&self) {}
}
trait C {
#[allow(unsafe_code)]
unsafe fn baz(&self);
unsafe fn provided(&self) {} //~ ERROR: implementation of an `unsafe` method
}
impl C for Bar {
#[allow(unsafe_code)]
unsafe fn baz(&self) {}
unsafe fn provided(&self) {} //~ ERROR: implementation of an `unsafe` method
}
impl C for Bar2 {
unsafe fn baz(&self) {} //~ ERROR: implementation of an `unsafe` method
}
trait D {
#[allow(unsafe_code)]
unsafe fn unsafe_provided(&self) {}
}
impl D for Bar {}
fn main() {
unsafe {} //~ ERROR: usage of an `unsafe` block
unsafe_in_macro!()
}