Skip to content
Myr

Merge pull request #166 from stepancheg/cold

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Mark error constructors cold

authored by David Tolnay · committed by GitHub · parents b3c5e25, fa9bcc0 · Browse files · 4 files+18 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+18 added−0 removed

  • other:+18 added−0 removed

4 files+18 added−0 removed

modified:src/chain.rs+1 added
22 unmodified lines
23 },24}2526impl<'a> Chain<'a> {27 #[cold]28 pub fn new(head: &'a (dyn StdError + 'static)) -> Self {29 Chain {30 state: ChainState::Linked { next: Some(head) },31 }
71 unmodified lines
modified:src/error.rs+13 added
23 unmodified lines
24 /// If the error type does not provide a backtrace, a backtrace will be25 /// created here to ensure that a backtrace exists.26 #[cfg(feature = "std")]27 #[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]28 #[cold]29 pub fn new<E>(error: E) -> Self30 where31 E: StdError + Send + Sync + 'static,32 {
37 unmodified lines
70 /// .try_collect()71 /// .await72 /// }73 /// ```74 #[cold]75 pub fn msg<M>(message: M) -> Self76 where77 M: Display + Debug + Send + Sync + 'static,78 {79 Error::from_adhoc(message, backtrace!())80 }8182 #[cfg(feature = "std")]83 #[cold]84 pub(crate) fn from_std<E>(error: E, backtrace: Option<Backtrace>) -> Self85 where86 E: StdError + Send + Sync + 'static,87 {
14 unmodified lines
102 // Safety: passing vtable that operates on the right type E.103 unsafe { Error::construct(error, vtable, backtrace) }104 }105106 #[cold]107 pub(crate) fn from_adhoc<M>(message: M, backtrace: Option<Backtrace>) -> Self108 where109 M: Display + Debug + Send + Sync + 'static,110 {
17 unmodified lines
128 // vtable to allow casting the MessageError<M> to M.129 unsafe { Error::construct(error, vtable, backtrace) }130 }131132 #[cold]133 pub(crate) fn from_display<M>(message: M, backtrace: Option<Backtrace>) -> Self134 where135 M: Display + Send + Sync + 'static,136 {
18 unmodified lines
155 unsafe { Error::construct(error, vtable, backtrace) }156 }157158 #[cfg(feature = "std")]159 #[cold]160 pub(crate) fn from_context<C, E>(context: C, error: E, backtrace: Option<Backtrace>) -> Self161 where162 C: Display + Send + Sync + 'static,163 E: StdError + Send + Sync + 'static,
18 unmodified lines
182 unsafe { Error::construct(error, vtable, backtrace) }183 }184185 #[cfg(feature = "std")]186 #[cold]187 pub(crate) fn from_boxed(188 error: Box<dyn StdError + Send + Sync>,189 backtrace: Option<Backtrace>,190 ) -> Self {
22 unmodified lines
213 // user sees one fewer layer of wrapping noise in the backtrace.214 //215 // Unsafe because the given vtable must have sensible behavior on the error216 // value of type E.217 #[cold]218 unsafe fn construct<E>(219 error: E,220 vtable: &'static ErrorVTable,221 backtrace: Option<Backtrace>,
69 unmodified lines
291 /// anyhow::Error::new(error).context(context)292 /// })293 /// }294 /// ```295 #[cold]296 pub fn context<C>(self, context: C) -> Self297 where298 C: Display + Send + Sync + 'static,299 {
81 unmodified lines
381 /// }382 /// ```383 #[cfg(feature = "std")]384 #[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]385 #[cold]386 pub fn chain(&self) -> Chain {387 unsafe { ErrorImpl::chain(self.inner.by_ref()) }388 }389
134 unmodified lines
524impl<E> From<E> for Error525where526 E: StdError + Send + Sync + 'static,527{528 #[cold]529 fn from(error: E) -> Self {530 let backtrace = backtrace_if_absent!(error);531 Error::from_std(error, backtrace)532 }
356 unmodified lines
889 })890 .expect("backtrace capture failed")891 }892893 #[cold]894 pub(crate) unsafe fn chain(this: Ref<Self>) -> Chain {895 Chain::new(Self::error(this))896 }897}
30 unmodified lines
928 }929}930931impl From<Error> for Box<dyn StdError + Send + Sync + 'static> {932 #[cold]933 fn from(error: Error) -> Self {934 let outer = ManuallyDrop::new(error);935 unsafe {936 // Use vtable to attach ErrorImpl<E>'s native StdError vtable for
31 unmodified lines
modified:src/kind.rs+3 added
60 unmodified lines
6162impl<T> AdhocKind for &T where T: ?Sized + Display + Debug + Send + Sync + 'static {}6364impl Adhoc {65 #[cold]66 pub fn new<M>(self, message: M) -> Error67 where68 M: Display + Debug + Send + Sync + 'static,69 {
12 unmodified lines
8283impl<E> TraitKind for E where E: Into<Error> {}8485impl Trait {86 #[cold]87 pub fn new<E>(self, error: E) -> Error88 where89 E: Into<Error>,90 {
16 unmodified lines
107impl BoxedKind for Box<dyn StdError + Send + Sync> {}108109#[cfg(feature = "std")]110impl Boxed {111 #[cold]112 pub fn new(self, error: Box<dyn StdError + Send + Sync>) -> Error {113 let backtrace = backtrace_if_absent!(error);114 Error::from_boxed(error, backtrace)115 }
1 unmodified line
modified:src/lib.rs+1 added
624 unmodified lines
625 #[cfg(feature = "std")]626 pub use crate::kind::BoxedKind;627 }628629 #[cold]630 pub fn new_adhoc<M>(message: M) -> Error631 where632 M: Display + Debug + Send + Sync + 'static,633 {
26 unmodified lines