2013-04-09 00:31:10 -05:00
|
|
|
// Copyright 2013 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.
|
|
|
|
|
|
|
|
// Exercise the unused_unsafe attribute in some positive and negative cases
|
|
|
|
|
|
|
|
#[deny(unused_unsafe)];
|
|
|
|
|
|
|
|
use core::libc;
|
|
|
|
|
|
|
|
fn callback<T>(_f: &fn() -> T) -> T { fail!() }
|
|
|
|
|
2013-04-23 01:06:47 -05:00
|
|
|
fn bad1() { unsafe {} } //~ ERROR: unnecessary `unsafe` block
|
|
|
|
fn bad2() { unsafe { bad1() } } //~ ERROR: unnecessary `unsafe` block
|
|
|
|
unsafe fn bad4() { unsafe {} } //~ ERROR: unnecessary `unsafe` block
|
|
|
|
fn bad5() { unsafe { do callback {} } } //~ ERROR: unnecessary `unsafe` block
|
2013-04-09 00:31:10 -05:00
|
|
|
|
|
|
|
unsafe fn good0() { libc::exit(1) }
|
|
|
|
fn good1() { unsafe { libc::exit(1) } }
|
|
|
|
fn good2() {
|
|
|
|
/* bug uncovered when implementing warning about unused unsafe blocks. Be
|
|
|
|
sure that when purity is inherited that the source of the unsafe-ness
|
|
|
|
is tracked correctly */
|
|
|
|
unsafe {
|
|
|
|
unsafe fn what() -> ~[~str] { libc::exit(2) }
|
|
|
|
|
|
|
|
do callback {
|
|
|
|
what();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-20 14:51:29 -05:00
|
|
|
#[allow(unused_unsafe)] fn allowed() { unsafe {} }
|
2013-04-09 00:31:10 -05:00
|
|
|
|
|
|
|
fn main() { }
|