2015-02-19 12:04:56 -06:00
|
|
|
// Copyright 2013-2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
#![allow(unused_unsafe)]
|
|
|
|
#![allow(dead_code)]
|
|
|
|
#![deny(unsafe_code)]
|
|
|
|
|
2015-02-20 23:11:52 -06:00
|
|
|
use std::marker::PhantomFn;
|
|
|
|
|
2015-02-19 12:04:56 -06:00
|
|
|
struct Bar;
|
2015-02-24 00:27:27 -06:00
|
|
|
struct Bar2;
|
|
|
|
struct Bar3;
|
2015-02-19 12:04:56 -06:00
|
|
|
|
|
|
|
#[allow(unsafe_code)]
|
|
|
|
mod allowed_unsafe {
|
2015-02-20 23:11:52 -06:00
|
|
|
use std::marker::PhantomFn;
|
2015-02-19 12:04:56 -06:00
|
|
|
fn allowed() { unsafe {} }
|
|
|
|
unsafe fn also_allowed() {}
|
2015-02-20 23:11:52 -06:00
|
|
|
unsafe trait AllowedUnsafe : PhantomFn<Self> {}
|
2015-02-19 12:04:56 -06:00
|
|
|
unsafe impl AllowedUnsafe for super::Bar {}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! unsafe_in_macro {
|
|
|
|
() => {
|
|
|
|
unsafe {} //~ ERROR: usage of an `unsafe` block
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn baz() {} //~ ERROR: declaration of an `unsafe` function
|
2015-02-20 23:11:52 -06:00
|
|
|
unsafe trait Foo : PhantomFn<Self> {} //~ ERROR: declaration of an `unsafe` trait
|
2015-02-19 12:04:56 -06:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2015-02-24 00:27:27 -06:00
|
|
|
|
|
|
|
#[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 {}
|
|
|
|
|
2015-02-19 12:04:56 -06:00
|
|
|
fn main() {
|
|
|
|
unsafe {} //~ ERROR: usage of an `unsafe` block
|
|
|
|
|
|
|
|
unsafe_in_macro!()
|
|
|
|
}
|