From 4f9fe856a25ab29345b90e7725509e9ee38a37be Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:41 +0200 Subject: Adding upstream version 1.69.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/anyhow/src/context.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'vendor/anyhow/src/context.rs') diff --git a/vendor/anyhow/src/context.rs b/vendor/anyhow/src/context.rs index 238473e5c..9df86937b 100644 --- a/vendor/anyhow/src/context.rs +++ b/vendor/anyhow/src/context.rs @@ -4,7 +4,7 @@ use core::convert::Infallible; use core::fmt::{self, Debug, Display, Write}; #[cfg(backtrace)] -use std::any::Demand; +use std::any::{Demand, Provider}; mod ext { use super::*; @@ -92,7 +92,12 @@ impl Context for Option { where C: Display + Send + Sync + 'static, { - self.ok_or_else(|| Error::from_display(context, backtrace!())) + // Not using ok_or_else to save 2 useless frames off the captured + // backtrace. + match self { + Some(ok) => Ok(ok), + None => Err(Error::from_display(context, backtrace!())), + } } fn with_context(self, context: F) -> Result @@ -100,7 +105,10 @@ impl Context for Option { C: Display + Send + Sync + 'static, F: FnOnce() -> C, { - self.ok_or_else(|| Error::from_display(context(), backtrace!())) + match self { + Some(ok) => Ok(ok), + None => Err(Error::from_display(context(), backtrace!())), + } } } @@ -137,7 +145,7 @@ where #[cfg(backtrace)] fn provide<'a>(&'a self, demand: &mut Demand<'a>) { - self.error.provide(demand); + StdError::provide(&self.error, demand); } } @@ -151,8 +159,7 @@ where #[cfg(backtrace)] fn provide<'a>(&'a self, demand: &mut Demand<'a>) { - demand.provide_ref(self.error.backtrace()); - self.error.provide(demand); + Provider::provide(&self.error, demand); } } -- cgit v1.2.3