rustc: remove unnecessary unsafe blocks/methods

This commit is contained in:
Alex Crichton 2013-04-09 02:07:50 -04:00
parent 52445129fd
commit 72c24e20a9
6 changed files with 155 additions and 177 deletions

View file

@ -615,10 +615,8 @@ pub fn build_link_meta(sess: Session, c: &ast::crate, output: &Path,
} }
pub fn truncated_hash_result(symbol_hasher: &hash::State) -> ~str { pub fn truncated_hash_result(symbol_hasher: &hash::State) -> ~str {
unsafe {
symbol_hasher.result_str() symbol_hasher.result_str()
} }
}
// This calculates STH for a symbol, as defined above // This calculates STH for a symbol, as defined above

View file

@ -369,7 +369,7 @@ pub impl<'self> LanguageItemCollector<'self> {
} }
fn collect_local_language_items(&self) { fn collect_local_language_items(&self) {
let this = unsafe { ptr::addr_of(&self) }; let this = ptr::addr_of(&self);
visit_crate(*self.crate, (), mk_simple_visitor(@SimpleVisitor { visit_crate(*self.crate, (), mk_simple_visitor(@SimpleVisitor {
visit_item: |item| { visit_item: |item| {
for item.attrs.each |attribute| { for item.attrs.each |attribute| {

View file

@ -19,7 +19,7 @@ use metadata::csearch::get_type_name_if_impl;
use metadata::cstore::find_extern_mod_stmt_cnum; use metadata::cstore::find_extern_mod_stmt_cnum;
use metadata::decoder::{def_like, dl_def, dl_field, dl_impl}; use metadata::decoder::{def_like, dl_def, dl_field, dl_impl};
use middle::lang_items::LanguageItems; use middle::lang_items::LanguageItems;
use middle::lint::{deny, allow, forbid, level, unused_imports, warn}; use middle::lint::{allow, level, unused_imports};
use middle::lint::{get_lint_level, get_lint_settings_level}; use middle::lint::{get_lint_level, get_lint_settings_level};
use middle::pat_util::pat_bindings; use middle::pat_util::pat_bindings;

View file

@ -91,13 +91,11 @@ pub struct icx_popper {
#[unsafe_destructor] #[unsafe_destructor]
impl Drop for icx_popper { impl Drop for icx_popper {
fn finalize(&self) { fn finalize(&self) {
unsafe {
if self.ccx.sess.count_llvm_insns() { if self.ccx.sess.count_llvm_insns() {
self.ccx.stats.llvm_insn_ctxt.pop(); self.ccx.stats.llvm_insn_ctxt.pop();
} }
} }
} }
}
pub fn icx_popper(ccx: @CrateContext) -> icx_popper { pub fn icx_popper(ccx: @CrateContext) -> icx_popper {
icx_popper { icx_popper {
@ -145,9 +143,7 @@ pub fn decl_fn(llmod: ModuleRef, name: &str, cc: lib::llvm::CallConv,
llvm::LLVMGetOrInsertFunction(llmod, buf, llty) llvm::LLVMGetOrInsertFunction(llmod, buf, llty)
} }
}); });
unsafe {
lib::llvm::SetFunctionCallConv(llfn, cc); lib::llvm::SetFunctionCallConv(llfn, cc);
}
return llfn; return llfn;
} }
@ -730,12 +726,10 @@ pub fn cast_shift_expr_rhs(cx: block, op: ast::binop,
pub fn cast_shift_const_rhs(op: ast::binop, pub fn cast_shift_const_rhs(op: ast::binop,
lhs: ValueRef, rhs: ValueRef) -> ValueRef { lhs: ValueRef, rhs: ValueRef) -> ValueRef {
unsafe {
cast_shift_rhs(op, lhs, rhs, cast_shift_rhs(op, lhs, rhs,
|a, b| unsafe { llvm::LLVMConstTrunc(a, b) }, |a, b| unsafe { llvm::LLVMConstTrunc(a, b) },
|a, b| unsafe { llvm::LLVMConstZExt(a, b) }) |a, b| unsafe { llvm::LLVMConstZExt(a, b) })
} }
}
pub fn cast_shift_rhs(op: ast::binop, pub fn cast_shift_rhs(op: ast::binop,
lhs: ValueRef, rhs: ValueRef, lhs: ValueRef, rhs: ValueRef,
@ -2865,9 +2859,7 @@ pub fn create_module_map(ccx: @CrateContext) -> ValueRef {
llvm::LLVMAddGlobal(ccx.llmod, maptype, buf) llvm::LLVMAddGlobal(ccx.llmod, maptype, buf)
} }
}); });
unsafe {
lib::llvm::SetLinkage(map, lib::llvm::InternalLinkage); lib::llvm::SetLinkage(map, lib::llvm::InternalLinkage);
}
let mut elts: ~[ValueRef] = ~[]; let mut elts: ~[ValueRef] = ~[];
for ccx.module_data.each |key, &val| { for ccx.module_data.each |key, &val| {
let elt = C_struct(~[p2i(ccx, C_cstr(ccx, @/*bad*/ copy *key)), let elt = C_struct(~[p2i(ccx, C_cstr(ccx, @/*bad*/ copy *key)),

View file

@ -27,10 +27,8 @@ use core::str;
use core::vec; use core::vec;
pub fn terminate(cx: block, _: &str) { pub fn terminate(cx: block, _: &str) {
unsafe {
cx.terminated = true; cx.terminated = true;
} }
}
pub fn check_not_terminated(cx: block) { pub fn check_not_terminated(cx: block) {
if cx.terminated { if cx.terminated {

View file

@ -172,7 +172,6 @@ fn cast_safely<T:Copy,U>(val: T) -> U {
} }
fn md_from_metadata<T>(val: debug_metadata) -> T { fn md_from_metadata<T>(val: debug_metadata) -> T {
unsafe {
match val { match val {
file_metadata(md) => cast_safely(md), file_metadata(md) => cast_safely(md),
compile_unit_metadata(md) => cast_safely(md), compile_unit_metadata(md) => cast_safely(md),
@ -184,13 +183,11 @@ fn md_from_metadata<T>(val: debug_metadata) -> T {
retval_metadata(md) => cast_safely(md) retval_metadata(md) => cast_safely(md)
} }
} }
}
fn cached_metadata<T:Copy>(cache: metadata_cache, fn cached_metadata<T:Copy>(cache: metadata_cache,
mdtag: int, mdtag: int,
eq_fn: &fn(md: T) -> bool) eq_fn: &fn(md: T) -> bool)
-> Option<T> { -> Option<T> {
unsafe {
if cache.contains_key(&mdtag) { if cache.contains_key(&mdtag) {
let items = cache.get(&mdtag); let items = cache.get(&mdtag);
for items.each |item| { for items.each |item| {
@ -202,10 +199,8 @@ fn cached_metadata<T:Copy>(cache: metadata_cache,
} }
return option::None; return option::None;
} }
}
fn create_compile_unit(cx: @CrateContext) -> @Metadata<CompileUnitMetadata> { fn create_compile_unit(cx: @CrateContext) -> @Metadata<CompileUnitMetadata> {
unsafe {
let cache = get_cache(cx); let cache = get_cache(cx);
let crate_name = /*bad*/copy (/*bad*/copy cx.dbg_cx).get().crate_file; let crate_name = /*bad*/copy (/*bad*/copy cx.dbg_cx).get().crate_file;
let tg = CompileUnitTag; let tg = CompileUnitTag;
@ -240,7 +235,6 @@ fn create_compile_unit(cx: @CrateContext) -> @Metadata<CompileUnitMetadata> {
return mdval; return mdval;
} }
}
fn get_cache(cx: @CrateContext) -> metadata_cache { fn get_cache(cx: @CrateContext) -> metadata_cache {
(/*bad*/copy cx.dbg_cx).get().llmetadata (/*bad*/copy cx.dbg_cx).get().llmetadata
@ -710,7 +704,6 @@ fn create_var(type_tag: int, context: ValueRef, name: &str, file: ValueRef,
pub fn create_local_var(bcx: block, local: @ast::local) pub fn create_local_var(bcx: block, local: @ast::local)
-> @Metadata<LocalVarMetadata> { -> @Metadata<LocalVarMetadata> {
unsafe {
let cx = bcx.ccx(); let cx = bcx.ccx();
let cache = get_cache(cx); let cache = get_cache(cx);
let tg = AutoVariableTag; let tg = AutoVariableTag;
@ -762,11 +755,9 @@ pub fn create_local_var(bcx: block, local: @ast::local)
declargs); declargs);
return mdval; return mdval;
} }
}
pub fn create_arg(bcx: block, arg: ast::arg, sp: span) pub fn create_arg(bcx: block, arg: ast::arg, sp: span)
-> Option<@Metadata<ArgumentMetadata>> { -> Option<@Metadata<ArgumentMetadata>> {
unsafe {
let fcx = bcx.fcx, cx = *fcx.ccx; let fcx = bcx.fcx, cx = *fcx.ccx;
let cache = get_cache(cx); let cache = get_cache(cx);
let tg = ArgVariableTag; let tg = ArgVariableTag;
@ -819,7 +810,6 @@ pub fn create_arg(bcx: block, arg: ast::arg, sp: span)
} }
} }
} }
}
pub fn update_source_pos(cx: block, s: span) { pub fn update_source_pos(cx: block, s: span) {
if !cx.sess().opts.debuginfo { if !cx.sess().opts.debuginfo {