Skip to content
Myr

lib.rs

This file

Path

src/lib.rs

682 lines · 19.9 KiB · Rust

Last changed by

Ignore let_underscore_untyped pedantic clippy lintDavid Tolnaybefore adoptiond30b027

History of this file

Take it

The walk stopped after 200 commits: lines older than f3fe8bd point at it.

Restore compatibility with rustc pre-1.38David Tolnaybefore adoptionf3fe8bd

lines 1–4why, one step back
1//! [![github]](https://github.com/dtolnay/anyhow) [![crates-io]](https://crates.io/crates/anyhow) [![docs-rs]](https://docs.rs/anyhow)
2//!3//! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github4//! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust

Use upstreamed docs.rs icon in docs.rs badgeDavid Tolnaybefore adoptiond8c2388

line 5why, one step back
5//! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs

Restore compatibility with rustc pre-1.38David Tolnaybefore adoptionf3fe8bd

lines 6–130why, one step back
6//!
7//! <br>8//!9//! This library provides [`anyhow::Error`][Error], a trait object based error10//! type for easy idiomatic error handling in Rust applications.11//!12//! <br>13//!14//! # Details15//!16//! - Use `Result<T, anyhow::Error>`, or equivalently `anyhow::Result<T>`, as17//! the return type of any fallible function.18//!19//! Within the function, use `?` to easily propagate any error that implements20//! the `std::error::Error` trait.21//!22//! ```23//! # pub trait Deserialize {}24//! #25//! # mod serde_json {26//! # use super::Deserialize;27//! # use std::io;28//! #29//! # pub fn from_str<T: Deserialize>(json: &str) -> io::Result<T> {30//! # unimplemented!()31//! # }32//! # }33//! #34//! # struct ClusterMap;35//! #36//! # impl Deserialize for ClusterMap {}37//! #38//! use anyhow::Result;39//!40//! fn get_cluster_info() -> Result<ClusterMap> {41//! let config = std::fs::read_to_string("cluster.json")?;42//! let map: ClusterMap = serde_json::from_str(&config)?;43//! Ok(map)44//! }45//! #46//! # fn main() {}47//! ```48//!49//! - Attach context to help the person troubleshooting the error understand50//! where things went wrong. A low-level error like "No such file or51//! directory" can be annoying to debug without more context about what higher52//! level step the application was in the middle of.53//!54//! ```55//! # struct It;56//! #57//! # impl It {58//! # fn detach(&self) -> Result<()> {59//! # unimplemented!()60//! # }61//! # }62//! #63//! use anyhow::{Context, Result};64//!65//! fn main() -> Result<()> {66//! # return Ok(());67//! #68//! # const _: &str = stringify! {69//! ...70//! # };71//! #72//! # let it = It;73//! # let path = "./path/to/instrs.json";74//! #75//! it.detach().context("Failed to detach the important thing")?;76//!77//! let content = std::fs::read(path)78//! .with_context(|| format!("Failed to read instrs from {}", path))?;79//! #80//! # const _: &str = stringify! {81//! ...82//! # };83//! #84//! # Ok(())85//! }86//! ```87//!88//! ```console89//! Error: Failed to read instrs from ./path/to/instrs.json90//!91//! Caused by:92//! No such file or directory (os error 2)93//! ```94//!95//! - Downcasting is supported and can be by value, by shared reference, or by96//! mutable reference as needed.97//!98//! ```99//! # use anyhow::anyhow;100//! # use std::fmt::{self, Display};101//! # use std::task::Poll;102//! #103//! # #[derive(Debug)]104//! # enum DataStoreError {105//! # Censored(()),106//! # }107//! #108//! # impl Display for DataStoreError {109//! # fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {110//! # unimplemented!()111//! # }112//! # }113//! #114//! # impl std::error::Error for DataStoreError {}115//! #116//! # const REDACTED_CONTENT: () = ();117//! #118//! # let error = anyhow!("...");119//! # let root_cause = &error;120//! #121//! # let ret =122//! // If the error was caused by redaction, then return a123//! // tombstone instead of the content.124//! match root_cause.downcast_ref::<DataStoreError>() {125//! Some(DataStoreError::Censored(_)) => Ok(Poll::Ready(REDACTED_CONTENT)),126//! None => Err(error),127//! }128//! # ;129//! ```130//!

Mirror PR 162 from readme to rustdocDavid Tolnaybefore adoptionb3c5e25

lines 131–135why, one step back
131//! - If using the nightly channel, or stable with `features = ["backtrace"]`, a
132//! backtrace is captured and printed with the error if the underlying error133//! type does not already provide its own. In order to see backtraces, they134//! must be enabled through the environment variables described in135//! [`std::backtrace`]:

Restore compatibility with rustc pre-1.38David Tolnaybefore adoptionf3fe8bd

lines 136–212why, one step back
136//!
137//! - If you want panics and errors to both have backtraces, set138//! `RUST_BACKTRACE=1`;139//! - If you want only errors to have backtraces, set `RUST_LIB_BACKTRACE=1`;140//! - If you want only panics to have backtraces, set `RUST_BACKTRACE=1` and141//! `RUST_LIB_BACKTRACE=0`.142//!143//! The tracking issue for this feature is [rust-lang/rust#53487].144//!145//! [`std::backtrace`]: https://doc.rust-lang.org/std/backtrace/index.html#environment-variables146//! [rust-lang/rust#53487]: https://github.com/rust-lang/rust/issues/53487147//!148//! - Anyhow works with any error type that has an impl of `std::error::Error`,149//! including ones defined in your crate. We do not bundle a `derive(Error)`150//! macro but you can write the impls yourself or use a standalone macro like151//! [thiserror].152//!153//! [thiserror]: https://github.com/dtolnay/thiserror154//!155//! ```156//! use thiserror::Error;157//!158//! #[derive(Error, Debug)]159//! pub enum FormatError {160//! #[error("Invalid header (expected {expected:?}, got {found:?})")]161//! InvalidHeader {162//! expected: String,163//! found: String,164//! },165//! #[error("Missing attribute: {0}")]166//! MissingAttribute(String),167//! }168//! ```169//!170//! - One-off error messages can be constructed using the `anyhow!` macro, which171//! supports string interpolation and produces an `anyhow::Error`.172//!173//! ```174//! # use anyhow::{anyhow, Result};175//! #176//! # fn demo() -> Result<()> {177//! # let missing = "...";178//! return Err(anyhow!("Missing attribute: {}", missing));179//! # Ok(())180//! # }181//! ```182//!183//! A `bail!` macro is provided as a shorthand for the same early return.184//!185//! ```186//! # use anyhow::{bail, Result};187//! #188//! # fn demo() -> Result<()> {189//! # let missing = "...";190//! bail!("Missing attribute: {}", missing);191//! # Ok(())192//! # }193//! ```194//!195//! <br>196//!197//! # No-std support198//!199//! In no_std mode, the same API is almost all available and works the same way.200//! To depend on Anyhow in no_std mode, disable our default enabled "std"201//! feature in Cargo.toml. A global allocator is required.202//!203//! ```toml204//! [dependencies]205//! anyhow = { version = "1.0", default-features = false }206//! ```207//!208//! Since the `?`-based error conversions would normally rely on the209//! `std::error::Error` trait which is only available through std, no_std mode210//! will require an explicit `.map_err(Error::msg)` when working with a211//! non-Anyhow error type inside a function that returns Anyhow's error type.212

Release 1.0.69David Tolnaybefore adoption58377ab

line 213why, one step back
213#![doc(html_root_url = "https://docs.rs/anyhow/1.0.69")]

Merge pull request #266 from dtolnay/providerDavid Tolnaybefore adoption546342c

line 214why, one step back
214#![cfg_attr(backtrace, feature(error_generic_member_access, provide_any))]

Restore compatibility with rustc pre-1.38David Tolnaybefore adoptionf3fe8bd

lines 215–216why, one step back
215#![cfg_attr(doc_cfg, feature(doc_cfg))]
216#![cfg_attr(not(feature = "std"), no_std)]

Catch some warnings in addr_of-related codepathsDavid Tolnaybefore adoption827bb9d

line 217why, one step back
217#![deny(dead_code, unused_imports, unused_mut)]

Restore compatibility with rustc pre-1.38David Tolnaybefore adoptionf3fe8bd

lines 218–220why, one step back
218#![allow(
219 clippy::doc_markdown,220 clippy::enum_glob_use,

Ignore explicit_auto_deref clippy lintDavid Tolnaybefore adoption38c883b

line 221why, one step back
221 clippy::explicit_auto_deref,

Ignore extra_unused_type_parameters clippy lint in testDavid Tolnaybefore adoptione0292fe

line 222why, one step back
222 clippy::extra_unused_type_parameters,

Ignore let_underscore_untyped pedantic clippy lintDavid Tolnaybefore adoptiond30b027

line 223why, one step back
223 clippy::let_underscore_untyped,

Restore compatibility with rustc pre-1.38David Tolnaybefore adoptionf3fe8bd

line 224why, one step back
224 clippy::missing_errors_doc,

Ignore new missing_panics_doc pedantic clippy lintDavid Tolnaybefore adoption1631007

line 225why, one step back
225 clippy::missing_panics_doc,

Restore compatibility with rustc pre-1.38David Tolnaybefore adoptionf3fe8bd

lines 226–229why, one step back
226 clippy::module_name_repetitions,
227 clippy::must_use_candidate,228 clippy::needless_doctest_main,229 clippy::new_ret_no_self,

Ignore redundant_else pedantic clippy lintDavid Tolnaybefore adoption2987c9b

line 230why, one step back
230 clippy::redundant_else,

Ignore return_self_not_must_use clippy lintDavid Tolnaybefore adoptiona3f7160

line 231why, one step back
231 clippy::return_self_not_must_use,

Restore compatibility with rustc pre-1.38David Tolnaybefore adoptionf3fe8bd

lines 232–237why, one step back
232 clippy::unused_self,
233 clippy::used_underscore_binding,234 clippy::wildcard_imports,235 clippy::wrong_self_convention236)]237

Merge pull request #178 from dtolnay/upDavid Tolnaybefore adoption3c586dd

line 238why, one step back
238extern crate alloc;

Restore compatibility with rustc pre-1.38David Tolnaybefore adoptionf3fe8bd

lines 239–243why, one step back
239
240#[macro_use]241mod backtrace;242mod chain;243mod context;

Merge pull request #193 from dtolnay/ensureDavid Tolnaybefore adoptione05df5f

line 244why, one step back
244mod ensure;

Restore compatibility with rustc pre-1.38David Tolnaybefore adoptionf3fe8bd

lines 245–371why, one step back
245mod error;
246mod fmt;247mod kind;248mod macros;249mod ptr;250mod wrapper;251252use crate::error::ErrorImpl;253use crate::ptr::Own;254use core::fmt::Display;255256#[cfg(not(feature = "std"))]257use core::fmt::Debug;258259#[cfg(feature = "std")]260use std::error::Error as StdError;261262#[cfg(not(feature = "std"))]263trait StdError: Debug + Display {264 fn source(&self) -> Option<&(dyn StdError + 'static)> {265 None266 }267}268269pub use anyhow as format_err;270271/// The `Error` type, a wrapper around a dynamic error type.272///273/// `Error` works a lot like `Box<dyn std::error::Error>`, but with these274/// differences:275///276/// - `Error` requires that the error is `Send`, `Sync`, and `'static`.277/// - `Error` guarantees that a backtrace is available, even if the underlying278/// error type does not provide one.279/// - `Error` is represented as a narrow pointer &mdash; exactly one word in280/// size instead of two.281///282/// <br>283///284/// # Display representations285///286/// When you print an error object using "{}" or to_string(), only the outermost287/// underlying error or context is printed, not any of the lower level causes.288/// This is exactly as if you had called the Display impl of the error from289/// which you constructed your anyhow::Error.290///291/// ```console292/// Failed to read instrs from ./path/to/instrs.json293/// ```294///295/// To print causes as well using anyhow's default formatting of causes, use the296/// alternate selector "{:#}".297///298/// ```console299/// Failed to read instrs from ./path/to/instrs.json: No such file or directory (os error 2)300/// ```301///302/// The Debug format "{:?}" includes your backtrace if one was captured. Note303/// that this is the representation you get by default if you return an error304/// from `fn main` instead of printing it explicitly yourself.305///306/// ```console307/// Error: Failed to read instrs from ./path/to/instrs.json308///309/// Caused by:310/// No such file or directory (os error 2)311/// ```312///313/// and if there is a backtrace available:314///315/// ```console316/// Error: Failed to read instrs from ./path/to/instrs.json317///318/// Caused by:319/// No such file or directory (os error 2)320///321/// Stack backtrace:322/// 0: <E as anyhow::context::ext::StdError>::ext_context323/// at /git/anyhow/src/backtrace.rs:26324/// 1: core::result::Result<T,E>::map_err325/// at /git/rustc/src/libcore/result.rs:596326/// 2: anyhow::context::<impl anyhow::Context<T,E> for core::result::Result<T,E>>::with_context327/// at /git/anyhow/src/context.rs:58328/// 3: testing::main329/// at src/main.rs:5330/// 4: std::rt::lang_start331/// at /git/rustc/src/libstd/rt.rs:61332/// 5: main333/// 6: __libc_start_main334/// 7: _start335/// ```336///337/// To see a conventional struct-style Debug representation, use "{:#?}".338///339/// ```console340/// Error {341/// context: "Failed to read instrs from ./path/to/instrs.json",342/// source: Os {343/// code: 2,344/// kind: NotFound,345/// message: "No such file or directory",346/// },347/// }348/// ```349///350/// If none of the built-in representations are appropriate and you would prefer351/// to render the error and its cause chain yourself, it can be done something352/// like this:353///354/// ```355/// use anyhow::{Context, Result};356///357/// fn main() {358/// if let Err(err) = try_main() {359/// eprintln!("ERROR: {}", err);360/// err.chain().skip(1).for_each(|cause| eprintln!("because: {}", cause));361/// std::process::exit(1);362/// }363/// }364///365/// fn try_main() -> Result<()> {366/// # const IGNORE: &str = stringify! {367/// ...368/// # };369/// # Ok(())370/// }371/// ```

Merge pull request #295 from dtolnay/docreprDavid Tolnaybefore adoptionf65b087

line 372why, one step back
372#[cfg_attr(not(doc), repr(transparent))]

Restore compatibility with rustc pre-1.38David Tolnaybefore adoptionf3fe8bd

lines 373–501why, one step back
373pub struct Error {
374 inner: Own<ErrorImpl>,375}376377/// Iterator of a chain of source errors.378///379/// This type is the iterator returned by [`Error::chain`].380///381/// # Example382///383/// ```384/// use anyhow::Error;385/// use std::io;386///387/// pub fn underlying_io_error_kind(error: &Error) -> Option<io::ErrorKind> {388/// for cause in error.chain() {389/// if let Some(io_error) = cause.downcast_ref::<io::Error>() {390/// return Some(io_error.kind());391/// }392/// }393/// None394/// }395/// ```396#[cfg(feature = "std")]397#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]398#[derive(Clone)]399pub struct Chain<'a> {400 state: crate::chain::ChainState<'a>,401}402403/// `Result<T, Error>`404///405/// This is a reasonable return type to use throughout your application but also406/// for `fn main`; if you do, failures will be printed along with any407/// [context][Context] and a backtrace if one was captured.408///409/// `anyhow::Result` may be used with one *or* two type parameters.410///411/// ```rust412/// use anyhow::Result;413///414/// # const IGNORE: &str = stringify! {415/// fn demo1() -> Result<T> {...}416/// // ^ equivalent to std::result::Result<T, anyhow::Error>417///418/// fn demo2() -> Result<T, OtherError> {...}419/// // ^ equivalent to std::result::Result<T, OtherError>420/// # };421/// ```422///423/// # Example424///425/// ```426/// # pub trait Deserialize {}427/// #428/// # mod serde_json {429/// # use super::Deserialize;430/// # use std::io;431/// #432/// # pub fn from_str<T: Deserialize>(json: &str) -> io::Result<T> {433/// # unimplemented!()434/// # }435/// # }436/// #437/// # #[derive(Debug)]438/// # struct ClusterMap;439/// #440/// # impl Deserialize for ClusterMap {}441/// #442/// use anyhow::Result;443///444/// fn main() -> Result<()> {445/// # return Ok(());446/// let config = std::fs::read_to_string("cluster.json")?;447/// let map: ClusterMap = serde_json::from_str(&config)?;448/// println!("cluster info: {:#?}", map);449/// Ok(())450/// }451/// ```452pub type Result<T, E = Error> = core::result::Result<T, E>;453454/// Provides the `context` method for `Result`.455///456/// This trait is sealed and cannot be implemented for types outside of457/// `anyhow`.458///459/// <br>460///461/// # Example462///463/// ```464/// use anyhow::{Context, Result};465/// use std::fs;466/// use std::path::PathBuf;467///468/// pub struct ImportantThing {469/// path: PathBuf,470/// }471///472/// impl ImportantThing {473/// # const IGNORE: &'static str = stringify! {474/// pub fn detach(&mut self) -> Result<()> {...}475/// # };476/// # fn detach(&mut self) -> Result<()> {477/// # unimplemented!()478/// # }479/// }480///481/// pub fn do_it(mut it: ImportantThing) -> Result<Vec<u8>> {482/// it.detach().context("Failed to detach the important thing")?;483///484/// let path = &it.path;485/// let content = fs::read(path)486/// .with_context(|| format!("Failed to read instrs from {}", path.display()))?;487///488/// Ok(content)489/// }490/// ```491///492/// When printed, the outermost context would be printed first and the lower493/// level underlying causes would be enumerated below.494///495/// ```console496/// Error: Failed to read instrs from ./path/to/instrs.json497///498/// Caused by:499/// No such file or directory (os error 2)500/// ```501///

Add link from Context docs to Display representationsDavid Tolnaybefore adoption6a31772

lines 502–506why, one step back
502/// Refer to the [Display representations] documentation for other forms in
503/// which this context chain can be rendered.504///505/// [Display representations]: Error#display-representations506///

Restore compatibility with rustc pre-1.38David Tolnaybefore adoptionf3fe8bd

lines 507–613why, one step back
507/// <br>
508///509/// # Effect on downcasting510///511/// After attaching context of type `C` onto an error of type `E`, the resulting512/// `anyhow::Error` may be downcast to `C` **or** to `E`.513///514/// That is, in codebases that rely on downcasting, Anyhow's context supports515/// both of the following use cases:516///517/// - **Attaching context whose type is insignificant onto errors whose type518/// is used in downcasts.**519///520/// In other error libraries whose context is not designed this way, it can521/// be risky to introduce context to existing code because new context might522/// break existing working downcasts. In Anyhow, any downcast that worked523/// before adding context will continue to work after you add a context, so524/// you should freely add human-readable context to errors wherever it would525/// be helpful.526///527/// ```528/// # use anyhow::bail;529/// # use thiserror::Error;530/// #531/// # #[derive(Error, Debug)]532/// # #[error("???")]533/// # struct SuspiciousError;534/// #535/// # fn helper() -> Result<()> {536/// # bail!(SuspiciousError);537/// # }538/// #539/// use anyhow::{Context, Result};540///541/// fn do_it() -> Result<()> {542/// helper().context("Failed to complete the work")?;543/// # const IGNORE: &str = stringify! {544/// ...545/// # };546/// # unreachable!()547/// }548///549/// fn main() {550/// let err = do_it().unwrap_err();551/// if let Some(e) = err.downcast_ref::<SuspiciousError>() {552/// // If helper() returned SuspiciousError, this downcast will553/// // correctly succeed even with the context in between.554/// # return;555/// }556/// # panic!("expected downcast to succeed");557/// }558/// ```559///560/// - **Attaching context whose type is used in downcasts onto errors whose561/// type is insignificant.**562///563/// Some codebases prefer to use machine-readable context to categorize564/// lower level errors in a way that will be actionable to higher levels of565/// the application.566///567/// ```568/// # use anyhow::bail;569/// # use thiserror::Error;570/// #571/// # #[derive(Error, Debug)]572/// # #[error("???")]573/// # struct HelperFailed;574/// #575/// # fn helper() -> Result<()> {576/// # bail!("no such file or directory");577/// # }578/// #579/// use anyhow::{Context, Result};580///581/// fn do_it() -> Result<()> {582/// helper().context(HelperFailed)?;583/// # const IGNORE: &str = stringify! {584/// ...585/// # };586/// # unreachable!()587/// }588///589/// fn main() {590/// let err = do_it().unwrap_err();591/// if let Some(e) = err.downcast_ref::<HelperFailed>() {592/// // If helper failed, this downcast will succeed because593/// // HelperFailed is the context that has been attached to594/// // that error.595/// # return;596/// }597/// # panic!("expected downcast to succeed");598/// }599/// ```600pub trait Context<T, E>: context::private::Sealed {601 /// Wrap the error value with additional context.602 fn context<C>(self, context: C) -> Result<T, Error>603 where604 C: Display + Send + Sync + 'static;605606 /// Wrap the error value with additional context that is evaluated lazily607 /// only once an error does occur.608 fn with_context<C, F>(self, f: F) -> Result<T, Error>609 where610 C: Display + Send + Sync + 'static,611 F: FnOnce() -> C;612}613

Show doc for Ok fnDavid Tolnaybefore adoption97cff68

line 614why, one step back
614/// Equivalent to Ok::<_, anyhow::Error>(value).

Add anyhow::OkDavid Tolnaybefore adoption2d4bb64

lines 615–636why, one step back
615///
616/// This simplifies creation of an anyhow::Result in places where type inference617/// cannot deduce the `E` type of the result &mdash; without needing to write618/// `Ok::<_, anyhow::Error>(value)`.619///620/// One might think that `anyhow::Result::Ok(value)` would work in such cases621/// but it does not.622///623/// ```console624/// error[E0282]: type annotations needed for `std::result::Result<i32, E>`625/// --> src/main.rs:11:13626/// |627/// 11 | let _ = anyhow::Result::Ok(1);628/// | - ^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `E` declared on the enum `Result`629/// | |630/// | consider giving this pattern the explicit type `std::result::Result<i32, E>`, where the type parameter `E` is specified631/// ```632#[allow(non_snake_case)]633pub fn Ok<T>(t: T) -> Result<T> {634 Result::Ok(t)635}636

Restore compatibility with rustc pre-1.38David Tolnaybefore adoptionf3fe8bd

lines 637–638why, one step back
637// Not public API. Referenced by macro-generated code.
638#[doc(hidden)]

Make private module more clearly privateDavid Tolnaybefore adoptionb88a699

line 639why, one step back
639pub mod __private {

Merge pull request #180 from dtolnay/captureDavid Tolnaybefore adoption8546f4c

lines 640–641why, one step back
640 use crate::Error;
641 use alloc::fmt;

Merge pull request #185 from dtolnay/fmtDavid Tolnaybefore adoptiona7f6089

line 642why, one step back
642 use core::fmt::Arguments;

Merge pull request #180 from dtolnay/captureDavid Tolnaybefore adoption8546f4c

line 643why, one step back
643

Merge pull request #193 from dtolnay/ensureDavid Tolnaybefore adoptione05df5f

line 644why, one step back
644 pub use crate::ensure::{BothDebug, NotBothDebug};

Merge pull request #179 from dtolnay/upDavid Tolnaybefore adoptioncd03064

line 645why, one step back
645 pub use alloc::format;

Restore compatibility with rustc pre-1.38David Tolnaybefore adoptionf3fe8bd

line 646why, one step back
646 pub use core::result::Result::Err;

Merge pull request #180 from dtolnay/captureDavid Tolnaybefore adoption8546f4c

line 647why, one step back
647 pub use core::{concat, format_args, stringify};

Restore compatibility with rustc pre-1.38David Tolnaybefore adoptionf3fe8bd

lines 648–654why, one step back
648
649 #[doc(hidden)]650 pub mod kind {651 pub use crate::kind::{AdhocKind, TraitKind};652653 #[cfg(feature = "std")]654 pub use crate::kind::BoxedKind;

Merge pull request #180 from dtolnay/captureDavid Tolnaybefore adoption8546f4c

lines 655–657why, one step back
655 }
656657 #[doc(hidden)]

Merge pull request #185 from dtolnay/fmtDavid Tolnaybefore adoptiona7f6089

line 658why, one step back
658 #[inline]

Merge pull request #180 from dtolnay/captureDavid Tolnaybefore adoption8546f4c

line 659why, one step back
659 #[cold]

Merge pull request #185 from dtolnay/fmtDavid Tolnaybefore adoptiona7f6089

line 660why, one step back
660 pub fn format_err(args: Arguments) -> Error {

Merge pull request #180 from dtolnay/captureDavid Tolnaybefore adoption8546f4c

line 661why, one step back
661 #[cfg(anyhow_no_fmt_arguments_as_str)]

Merge pull request #185 from dtolnay/fmtDavid Tolnaybefore adoptiona7f6089

line 662why, one step back
662 let fmt_arguments_as_str = None::<&str>;

Merge pull request #180 from dtolnay/captureDavid Tolnaybefore adoption8546f4c

line 663why, one step back
663 #[cfg(not(anyhow_no_fmt_arguments_as_str))]

Merge pull request #184 from dtolnay/escapeDavid Tolnaybefore adoption6c1fd34

line 664why, one step back
664 let fmt_arguments_as_str = args.as_str();

Merge pull request #180 from dtolnay/captureDavid Tolnaybefore adoption8546f4c

line 665why, one step back
665

Merge pull request #184 from dtolnay/escapeDavid Tolnaybefore adoption6c1fd34

line 666why, one step back
666 if let Some(message) = fmt_arguments_as_str {

Merge pull request #180 from dtolnay/captureDavid Tolnaybefore adoption8546f4c

lines 667–668why, one step back
667 // anyhow!("literal"), can downcast to &'static str
668 Error::msg(message)

Merge pull request #184 from dtolnay/escapeDavid Tolnaybefore adoption6c1fd34

lines 669–671why, one step back
669 } else {
670 // anyhow!("interpolate {var}"), can downcast to String671 Error::msg(fmt::format(args))

Merge pull request #180 from dtolnay/captureDavid Tolnaybefore adoption8546f4c

line 672why, one step back
672 }

Restore compatibility with rustc pre-1.38David Tolnaybefore adoptionf3fe8bd

line 673why, one step back
673 }

Merge pull request #229 from dtolnay/must_useDavid Tolnaybefore adoptionc8a3e42

lines 674–681why, one step back
674
675 #[doc(hidden)]676 #[inline]677 #[cold]678 #[must_use]679 pub fn must_use(error: Error) -> Error {680 error681 }

Restore compatibility with rustc pre-1.38David Tolnaybefore adoptionf3fe8bd

line 682why, one step back
682}