rustc: remove unnecessary unsafe blocks/methods
This commit is contained in:
parent
52445129fd
commit
72c24e20a9
6 changed files with 155 additions and 177 deletions
|
@ -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 {
|
||||
unsafe {
|
||||
symbol_hasher.result_str()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// This calculates STH for a symbol, as defined above
|
||||
|
|
|
@ -369,7 +369,7 @@ pub impl<'self> LanguageItemCollector<'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_item: |item| {
|
||||
for item.attrs.each |attribute| {
|
||||
|
|
|
@ -19,7 +19,7 @@ use metadata::csearch::get_type_name_if_impl;
|
|||
use metadata::cstore::find_extern_mod_stmt_cnum;
|
||||
use metadata::decoder::{def_like, dl_def, dl_field, dl_impl};
|
||||
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::pat_util::pat_bindings;
|
||||
|
||||
|
|
|
@ -91,13 +91,11 @@ pub struct icx_popper {
|
|||
#[unsafe_destructor]
|
||||
impl Drop for icx_popper {
|
||||
fn finalize(&self) {
|
||||
unsafe {
|
||||
if self.ccx.sess.count_llvm_insns() {
|
||||
self.ccx.stats.llvm_insn_ctxt.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn icx_popper(ccx: @CrateContext) -> 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)
|
||||
}
|
||||
});
|
||||
unsafe {
|
||||
lib::llvm::SetFunctionCallConv(llfn, cc);
|
||||
}
|
||||
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,
|
||||
lhs: ValueRef, rhs: ValueRef) -> ValueRef {
|
||||
unsafe {
|
||||
cast_shift_rhs(op, lhs, rhs,
|
||||
|a, b| unsafe { llvm::LLVMConstTrunc(a, b) },
|
||||
|a, b| unsafe { llvm::LLVMConstZExt(a, b) })
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cast_shift_rhs(op: ast::binop,
|
||||
lhs: ValueRef, rhs: ValueRef,
|
||||
|
@ -2865,9 +2859,7 @@ pub fn create_module_map(ccx: @CrateContext) -> ValueRef {
|
|||
llvm::LLVMAddGlobal(ccx.llmod, maptype, buf)
|
||||
}
|
||||
});
|
||||
unsafe {
|
||||
lib::llvm::SetLinkage(map, lib::llvm::InternalLinkage);
|
||||
}
|
||||
let mut elts: ~[ValueRef] = ~[];
|
||||
for ccx.module_data.each |key, &val| {
|
||||
let elt = C_struct(~[p2i(ccx, C_cstr(ccx, @/*bad*/ copy *key)),
|
||||
|
|
|
@ -27,10 +27,8 @@ use core::str;
|
|||
use core::vec;
|
||||
|
||||
pub fn terminate(cx: block, _: &str) {
|
||||
unsafe {
|
||||
cx.terminated = true;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn check_not_terminated(cx: block) {
|
||||
if cx.terminated {
|
||||
|
|
|
@ -172,7 +172,6 @@ fn cast_safely<T:Copy,U>(val: T) -> U {
|
|||
}
|
||||
|
||||
fn md_from_metadata<T>(val: debug_metadata) -> T {
|
||||
unsafe {
|
||||
match val {
|
||||
file_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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn cached_metadata<T:Copy>(cache: metadata_cache,
|
||||
mdtag: int,
|
||||
eq_fn: &fn(md: T) -> bool)
|
||||
-> Option<T> {
|
||||
unsafe {
|
||||
if cache.contains_key(&mdtag) {
|
||||
let items = cache.get(&mdtag);
|
||||
for items.each |item| {
|
||||
|
@ -202,10 +199,8 @@ fn cached_metadata<T:Copy>(cache: metadata_cache,
|
|||
}
|
||||
return option::None;
|
||||
}
|
||||
}
|
||||
|
||||
fn create_compile_unit(cx: @CrateContext) -> @Metadata<CompileUnitMetadata> {
|
||||
unsafe {
|
||||
let cache = get_cache(cx);
|
||||
let crate_name = /*bad*/copy (/*bad*/copy cx.dbg_cx).get().crate_file;
|
||||
let tg = CompileUnitTag;
|
||||
|
@ -240,7 +235,6 @@ fn create_compile_unit(cx: @CrateContext) -> @Metadata<CompileUnitMetadata> {
|
|||
|
||||
return mdval;
|
||||
}
|
||||
}
|
||||
|
||||
fn get_cache(cx: @CrateContext) -> metadata_cache {
|
||||
(/*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)
|
||||
-> @Metadata<LocalVarMetadata> {
|
||||
unsafe {
|
||||
let cx = bcx.ccx();
|
||||
let cache = get_cache(cx);
|
||||
let tg = AutoVariableTag;
|
||||
|
@ -762,11 +755,9 @@ pub fn create_local_var(bcx: block, local: @ast::local)
|
|||
declargs);
|
||||
return mdval;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_arg(bcx: block, arg: ast::arg, sp: span)
|
||||
-> Option<@Metadata<ArgumentMetadata>> {
|
||||
unsafe {
|
||||
let fcx = bcx.fcx, cx = *fcx.ccx;
|
||||
let cache = get_cache(cx);
|
||||
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) {
|
||||
if !cx.sess().opts.debuginfo {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue