[OPT] Don't call .to_string() on MonoItem's
This commit is contained in:
parent
856079bcaa
commit
ad1f885002
@ -307,7 +307,7 @@ fn codegen_mono_items<'tcx>(
|
||||
}
|
||||
|
||||
for (mono_item, (linkage, visibility)) in mono_items {
|
||||
crate::unimpl::try_unimpl(tcx, mono_item.to_string(tcx, true), || {
|
||||
crate::unimpl::try_unimpl(tcx, || {
|
||||
let linkage = crate::linkage::get_clif_linkage(mono_item, linkage, visibility);
|
||||
trans_mono_item(&mut cx, mono_item, linkage);
|
||||
});
|
||||
|
@ -1,14 +1,8 @@
|
||||
//! The unimpl! macro is defined here. It is used to generate
|
||||
//! a non-fatal error on not yet implemented things.
|
||||
|
||||
use std::cell::RefCell;
|
||||
|
||||
use rustc::ty::TyCtxt;
|
||||
|
||||
thread_local! {
|
||||
static CURRENT_MSG: RefCell<String> = RefCell::new(String::new());
|
||||
}
|
||||
|
||||
// Just public, because of the unimpl macro
|
||||
#[doc(hidden)]
|
||||
pub struct NonFatal(pub String);
|
||||
@ -20,21 +14,15 @@
|
||||
panic!(NonFatal(format!($($tt)*)));
|
||||
}
|
||||
|
||||
pub fn try_unimpl(tcx: TyCtxt, msg: String, f: impl FnOnce()) {
|
||||
CURRENT_MSG.with(|current_msg| {
|
||||
let old = std::mem::replace(&mut *current_msg.borrow_mut(), msg);
|
||||
pub fn try_unimpl(tcx: TyCtxt, f: impl FnOnce()) {
|
||||
let res = ::std::panic::catch_unwind(::std::panic::AssertUnwindSafe(|| f()));
|
||||
|
||||
let res = ::std::panic::catch_unwind(::std::panic::AssertUnwindSafe(|| f()));
|
||||
|
||||
if let Err(err) = res {
|
||||
match err.downcast::<NonFatal>() {
|
||||
Ok(non_fatal) => {
|
||||
tcx.sess.err(&format!("at {}: {}", current_msg.borrow(), non_fatal.0));
|
||||
}
|
||||
Err(err) => ::std::panic::resume_unwind(err),
|
||||
if let Err(err) = res {
|
||||
match err.downcast::<NonFatal>() {
|
||||
Ok(non_fatal) => {
|
||||
tcx.sess.err(&non_fatal.0);
|
||||
}
|
||||
Err(err) => ::std::panic::resume_unwind(err),
|
||||
}
|
||||
|
||||
*current_msg.borrow_mut() = old;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user