thiserror-1.0.20/.cargo_vcs_info.json0000644000000001121367200127500132300ustar00{ "git": { "sha1": "42b537acf08de385dcf6138f24e3274ff8a18148" } } thiserror-1.0.20/.github/workflows/ci.yml010064400017500001750000000016351366162722100165620ustar0000000000000000name: CI on: push: pull_request: schedule: [cron: "40 1 * * *"] jobs: test: name: Rust ${{matrix.rust}} runs-on: ubuntu-latest strategy: fail-fast: false matrix: rust: [beta, stable, 1.36.0] include: - rust: nightly rustflags: --cfg thiserror_nightly_testing steps: - uses: actions/checkout@v2 - uses: dtolnay/rust-toolchain@master with: toolchain: ${{matrix.rust}} - run: cargo test --all env: RUSTFLAGS: ${{matrix.rustflags}} msrv: name: Rust 1.31.0 runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: dtolnay/rust-toolchain@1.31.0 - run: cargo check clippy: name: Clippy runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: dtolnay/rust-toolchain@clippy - run: cargo clippy --tests -- -Dclippy::all thiserror-1.0.20/.gitignore010066400017500001750000000000361354727330500140360ustar0000000000000000/target **/*.rs.bk Cargo.lock thiserror-1.0.20/Cargo.toml0000644000000022141367200127500112330ustar00# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] edition = "2018" name = "thiserror" version = "1.0.20" authors = ["David Tolnay "] description = "derive(Error)" documentation = "https://docs.rs/thiserror" readme = "README.md" categories = ["rust-patterns"] license = "MIT OR Apache-2.0" repository = "https://github.com/dtolnay/thiserror" [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] [dependencies.thiserror-impl] version = "=1.0.20" [dev-dependencies.anyhow] version = "1.0" [dev-dependencies.ref-cast] version = "1.0" [dev-dependencies.rustversion] version = "1.0" [dev-dependencies.trybuild] version = "1.0.19" features = ["diff"] thiserror-1.0.20/Cargo.toml.orig010064400017500001750000000011521367200123600147220ustar0000000000000000[package] name = "thiserror" version = "1.0.20" authors = ["David Tolnay "] edition = "2018" license = "MIT OR Apache-2.0" description = "derive(Error)" repository = "https://github.com/dtolnay/thiserror" documentation = "https://docs.rs/thiserror" categories = ["rust-patterns"] readme = "README.md" [dependencies] thiserror-impl = { version = "=1.0.20", path = "impl" } [dev-dependencies] anyhow = "1.0" ref-cast = "1.0" rustversion = "1.0" trybuild = { version = "1.0.19", features = ["diff"] } [workspace] members = ["impl"] [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] thiserror-1.0.20/LICENSE-APACHE010066400017500001750000000251371354727576700140210ustar0000000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. thiserror-1.0.20/LICENSE-MIT010066400017500001750000000017771354727576700135350ustar0000000000000000Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. thiserror-1.0.20/README.md010064400017500001750000000154631365670467100133430ustar0000000000000000derive(Error) ============= [github](https://github.com/dtolnay/thiserror) [crates.io](https://crates.io/crates/thiserror) [docs.rs](https://docs.rs/thiserror) [build status](https://github.com/dtolnay/thiserror/actions?query=branch%3Amaster) This library provides a convenient derive macro for the standard library's [`std::error::Error`] trait. [`std::error::Error`]: https://doc.rust-lang.org/std/error/trait.Error.html ```toml [dependencies] thiserror = "1.0" ``` *Compiler support: requires rustc 1.31+*
## Example ```rust use thiserror::Error; #[derive(Error, Debug)] pub enum DataStoreError { #[error("data store disconnected")] Disconnect(#[from] io::Error), #[error("the data for key `{0}` is not available")] Redaction(String), #[error("invalid header (expected {expected:?}, found {found:?})")] InvalidHeader { expected: String, found: String, }, #[error("unknown data store error")] Unknown, } ```
## Details - Thiserror deliberately does not appear in your public API. You get the same thing as if you had written an implementation of `std::error::Error` by hand, and switching from handwritten impls to thiserror or vice versa is not a breaking change. - Errors may be enums, structs with named fields, tuple structs, or unit structs. - A `Display` impl is generated for your error if you provide `#[error("...")]` messages on the struct or each variant of your enum, as shown above in the example. The messages support a shorthand for interpolating fields from the error. - `#[error("{var}")]` ⟶ `write!("{}", self.var)` - `#[error("{0}")]` ⟶ `write!("{}", self.0)` - `#[error("{var:?}")]` ⟶ `write!("{:?}", self.var)` - `#[error("{0:?}")]` ⟶ `write!("{:?}", self.0)` These shorthands can be used together with any additional format args, which may be arbitrary expressions. For example: ```rust #[derive(Error, Debug)] pub enum Error { #[error("invalid rdo_lookahead_frames {0} (expected < {})", i32::max_value())] InvalidLookahead(u32), } ``` If one of the additional expression arguments needs to refer to a field of the struct or enum, then refer to named fields as `.var` and tuple fields as `.0`. ```rust #[derive(Error, Debug)] pub enum Error { #[error("first letter must be lowercase but was {:?}", first_char(.0))] WrongCase(String), #[error("invalid index {idx}, expected at least {} and at most {}", .limits.lo, .limits.hi)] OutOfBounds { idx: usize, limits: Limits }, } ``` - A `From` impl is generated for each variant containing a `#[from]` attribute. Note that the variant must not contain any other fields beyond the source error and possibly a backtrace. A backtrace is captured from within the `From` impl if there is a field for it. ```rust #[derive(Error, Debug)] pub enum MyError { Io { #[from] source: io::Error, backtrace: Backtrace, }, } ``` - The Error trait's `source()` method is implemented to return whichever field has a `#[source]` attribute or is named `source`, if any. This is for identifying the underlying lower level error that caused your error. The `#[from]` attribute always implies that the same field is `#[source]`, so you don't ever need to specify both attributes. Any error type that implements `std::error::Error` or dereferences to `dyn std::error::Error` will work as a source. ```rust #[derive(Error, Debug)] pub struct MyError { msg: String, #[source] // optional if field name is `source` source: anyhow::Error, } ``` - The Error trait's `backtrace()` method is implemented to return whichever field has a type named `Backtrace`, if any. ```rust use std::backtrace::Backtrace; #[derive(Error, Debug)] pub struct MyError { msg: String, backtrace: Backtrace, // automatically detected } ``` - Errors may use `error(transparent)` to forward the source and Display methods straight through to an underlying error without adding an additional message. This would be appropriate for enums that need an "anything else" variant. ```rust #[derive(Error, Debug)] pub enum MyError { ... #[error(transparent)] Other(#[from] anyhow::Error), // source and Display delegate to anyhow::Error } ``` - See also the [`anyhow`] library for a convenient single error type to use in application code. [`anyhow`]: https://github.com/dtolnay/anyhow
## Comparison to anyhow Use thiserror if you care about designing your own dedicated error type(s) so that the caller receives exactly the information that you choose in the event of failure. This most often applies to library-like code. Use [Anyhow] if you don't care what error type your functions return, you just want it to be easy. This is common in application-like code. [Anyhow]: https://github.com/dtolnay/anyhow
#### License Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. thiserror-1.0.20/src/aserror.rs010064400017500001750000000012221356471342100146510ustar0000000000000000use std::error::Error; pub trait AsDynError { fn as_dyn_error(&self) -> &(dyn Error + 'static); } impl AsDynError for T { #[inline] fn as_dyn_error(&self) -> &(dyn Error + 'static) { self } } impl AsDynError for dyn Error + 'static { #[inline] fn as_dyn_error(&self) -> &(dyn Error + 'static) { self } } impl AsDynError for dyn Error + Send + 'static { #[inline] fn as_dyn_error(&self) -> &(dyn Error + 'static) { self } } impl AsDynError for dyn Error + Send + Sync + 'static { #[inline] fn as_dyn_error(&self) -> &(dyn Error + 'static) { self } } thiserror-1.0.20/src/display.rs010064400017500001750000000010161357633425300146470ustar0000000000000000use std::fmt::Display; use std::path::{self, Path, PathBuf}; pub trait DisplayAsDisplay { fn as_display(&self) -> Self; } impl DisplayAsDisplay for &T { fn as_display(&self) -> Self { self } } pub trait PathAsDisplay { fn as_display(&self) -> path::Display<'_>; } impl PathAsDisplay for Path { fn as_display(&self) -> path::Display<'_> { self.display() } } impl PathAsDisplay for PathBuf { fn as_display(&self) -> path::Display<'_> { self.display() } } thiserror-1.0.20/src/lib.rs010064400017500001750000000161301366162721400137500ustar0000000000000000//! [![github]](https://github.com/dtolnay/thiserror) [![crates-io]](https://crates.io/crates/thiserror) [![docs-rs]](https://docs.rs/thiserror) //! //! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github //! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust //! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logoColor=white&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K //! //!
//! //! This library provides a convenient derive macro for the standard library's //! [`std::error::Error`] trait. //! //! [`std::error::Error`]: https://doc.rust-lang.org/std/error/trait.Error.html //! //!
//! //! # Example //! //! ```rust //! # use std::io; //! use thiserror::Error; //! //! #[derive(Error, Debug)] //! pub enum DataStoreError { //! #[error("data store disconnected")] //! Disconnect(#[from] io::Error), //! #[error("the data for key `{0}` is not available")] //! Redaction(String), //! #[error("invalid header (expected {expected:?}, found {found:?})")] //! InvalidHeader { //! expected: String, //! found: String, //! }, //! #[error("unknown data store error")] //! Unknown, //! } //! ``` //! //!
//! //! # Details //! //! - Thiserror deliberately does not appear in your public API. You get the //! same thing as if you had written an implementation of `std::error::Error` //! by hand, and switching from handwritten impls to thiserror or vice versa //! is not a breaking change. //! //! - Errors may be enums, structs with named fields, tuple structs, or unit //! structs. //! //! - A `Display` impl is generated for your error if you provide //! `#[error("...")]` messages on the struct or each variant of your enum, as //! shown above in the example. //! //! The messages support a shorthand for interpolating fields from the error. //! //! - `#[error("{var}")]` ⟶ `write!("{}", self.var)` //! - `#[error("{0}")]` ⟶ `write!("{}", self.0)` //! - `#[error("{var:?}")]` ⟶ `write!("{:?}", self.var)` //! - `#[error("{0:?}")]` ⟶ `write!("{:?}", self.0)` //! //! These shorthands can be used together with any additional format args, //! which may be arbitrary expressions. For example: //! //! ```rust //! # use thiserror::Error; //! # //! #[derive(Error, Debug)] //! pub enum Error { //! #[error("invalid rdo_lookahead_frames {0} (expected < {})", i32::max_value())] //! InvalidLookahead(u32), //! } //! ``` //! //! If one of the additional expression arguments needs to refer to a field of //! the struct or enum, then refer to named fields as `.var` and tuple fields //! as `.0`. //! //! ```rust //! # use thiserror::Error; //! # //! # fn first_char(s: &String) -> char { //! # s.chars().next().unwrap() //! # } //! # //! # #[derive(Debug)] //! # struct Limits { //! # lo: usize, //! # hi: usize, //! # } //! # //! #[derive(Error, Debug)] //! pub enum Error { //! #[error("first letter must be lowercase but was {:?}", first_char(.0))] //! WrongCase(String), //! #[error("invalid index {idx}, expected at least {} and at most {}", .limits.lo, .limits.hi)] //! OutOfBounds { idx: usize, limits: Limits }, //! } //! ``` //! //! - A `From` impl is generated for each variant containing a `#[from]` //! attribute. //! //! Note that the variant must not contain any other fields beyond the source //! error and possibly a backtrace. A backtrace is captured from within the //! `From` impl if there is a field for it. //! //! ```rust //! # const IGNORE: &str = stringify! { //! #[derive(Error, Debug)] //! pub enum MyError { //! Io { //! #[from] //! source: io::Error, //! backtrace: Backtrace, //! }, //! } //! # }; //! ``` //! //! - The Error trait's `source()` method is implemented to return whichever //! field has a `#[source]` attribute or is named `source`, if any. This is //! for identifying the underlying lower level error that caused your error. //! //! The `#[from]` attribute always implies that the same field is `#[source]`, //! so you don't ever need to specify both attributes. //! //! Any error type that implements `std::error::Error` or dereferences to `dyn //! std::error::Error` will work as a source. //! //! ```rust //! # use std::fmt::{self, Display}; //! # use thiserror::Error; //! # //! #[derive(Error, Debug)] //! pub struct MyError { //! msg: String, //! #[source] // optional if field name is `source` //! source: anyhow::Error, //! } //! # //! # impl Display for MyError { //! # fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { //! # unimplemented!() //! # } //! # } //! ``` //! //! - The Error trait's `backtrace()` method is implemented to return whichever //! field has a type named `Backtrace`, if any. //! //! ```rust //! # const IGNORE: &str = stringify! { //! use std::backtrace::Backtrace; //! //! #[derive(Error, Debug)] //! pub struct MyError { //! msg: String, //! backtrace: Backtrace, // automatically detected //! } //! # }; //! ``` //! //! - Errors may use `error(transparent)` to forward the source and Display //! methods straight through to an underlying error without adding an //! additional message. This would be appropriate for enums that need an //! "anything else" variant. //! //! ``` //! # use thiserror::Error; //! # //! #[derive(Error, Debug)] //! pub enum MyError { //! # /* //! ... //! # */ //! //! #[error(transparent)] //! Other(#[from] anyhow::Error), // source and Display delegate to anyhow::Error //! } //! ``` //! //! - See also the [`anyhow`] library for a convenient single error type to use //! in application code. //! //! [`anyhow`]: https://github.com/dtolnay/anyhow mod aserror; mod display; pub use thiserror_impl::*; // Not public API. #[doc(hidden)] pub mod private { pub use crate::aserror::AsDynError; pub use crate::display::{DisplayAsDisplay, PathAsDisplay}; } thiserror-1.0.20/tests/compiletest.rs010064400017500001750000000002651366162667100161150ustar0000000000000000#![deny(clippy::all, clippy::pedantic)] #[rustversion::attr(not(nightly), ignore)] #[test] fn ui() { let t = trybuild::TestCases::new(); t.compile_fail("tests/ui/*.rs"); } thiserror-1.0.20/tests/test_deprecated.rs010064400017500001750000000002551366162667100167230ustar0000000000000000#![deny(deprecated, clippy::all, clippy::pedantic)] use thiserror::Error; #[derive(Error, Debug)] pub enum Error { #[deprecated] #[error("...")] Deprecated, } thiserror-1.0.20/tests/test_display.rs010064400017500001750000000107131367200121400162460ustar0000000000000000#![deny(clippy::all, clippy::pedantic)] use std::fmt::Display; use thiserror::Error; fn assert(expected: &str, value: T) { assert_eq!(expected, value.to_string()); } #[test] fn test_braced() { #[derive(Error, Debug)] #[error("braced error: {msg}")] struct Error { msg: String, } let msg = "T".to_owned(); assert("braced error: T", Error { msg }); } #[test] fn test_braced_unused() { #[derive(Error, Debug)] #[error("braced error")] struct Error { extra: usize, } assert("braced error", Error { extra: 0 }); } #[test] fn test_tuple() { #[derive(Error, Debug)] #[error("tuple error: {0}")] struct Error(usize); assert("tuple error: 0", Error(0)); } #[test] fn test_unit() { #[derive(Error, Debug)] #[error("unit error")] struct Error; assert("unit error", Error); } #[test] fn test_enum() { #[derive(Error, Debug)] enum Error { #[error("braced error: {id}")] Braced { id: usize }, #[error("tuple error: {0}")] Tuple(usize), #[error("unit error")] Unit, } assert("braced error: 0", Error::Braced { id: 0 }); assert("tuple error: 0", Error::Tuple(0)); assert("unit error", Error::Unit); } #[test] fn test_constants() { #[derive(Error, Debug)] #[error("{MSG}: {id:?} (code {CODE:?})")] struct Error { id: &'static str, } const MSG: &str = "failed to do"; const CODE: usize = 9; assert("failed to do: \"\" (code 9)", Error { id: "" }); } #[test] fn test_inherit() { #[derive(Error, Debug)] #[error("{0}")] enum Error { Some(&'static str), #[error("other error")] Other(&'static str), } assert("some error", Error::Some("some error")); assert("other error", Error::Other("...")); } #[test] fn test_brace_escape() { #[derive(Error, Debug)] #[error("fn main() {{}}")] struct Error; assert("fn main() {}", Error); } #[test] fn test_expr() { #[derive(Error, Debug)] #[error("1 + 1 = {}", 1 + 1)] struct Error; assert("1 + 1 = 2", Error); } #[test] fn test_nested() { #[derive(Error, Debug)] #[error("!bool = {}", not(.0))] struct Error(bool); #[allow(clippy::trivially_copy_pass_by_ref)] fn not(bool: &bool) -> bool { !*bool } assert("!bool = false", Error(true)); } #[test] fn test_match() { #[derive(Error, Debug)] #[error("{}: {0}", match .1 { Some(n) => format!("error occurred with {}", n), None => "there was an empty error".to_owned(), })] struct Error(String, Option); assert( "error occurred with 1: ...", Error("...".to_owned(), Some(1)), ); assert( "there was an empty error: ...", Error("...".to_owned(), None), ); } #[test] fn test_void() { #[allow(clippy::empty_enum)] #[derive(Error, Debug)] #[error("...")] pub enum Error {} let _: Error; } #[test] fn test_mixed() { #[derive(Error, Debug)] #[error("a={a} :: b={} :: c={c} :: d={d}", 1, c = 2, d = 3)] struct Error { a: usize, d: usize, } assert("a=0 :: b=1 :: c=2 :: d=3", Error { a: 0, d: 0 }); } #[test] fn test_ints() { #[derive(Error, Debug)] enum Error { #[error("error {0}")] Tuple(usize, usize), #[error("error {0}", '?')] Struct { v: usize }, } assert("error 9", Error::Tuple(9, 0)); assert("error ?", Error::Struct { v: 0 }); } #[test] fn test_trailing_comma() { #[derive(Error, Debug)] #[error( "error {0}", )] #[rustfmt::skip] struct Error(char); assert("error ?", Error('?')); } #[test] fn test_field() { #[derive(Debug)] struct Inner { data: usize, } #[derive(Error, Debug)] #[error("{}", .0.data)] struct Error(Inner); assert("0", Error(Inner { data: 0 })); } #[test] fn test_macro_rules() { // Regression test for https://github.com/dtolnay/thiserror/issues/86 macro_rules! decl_error { ($variant:ident($value:ident)) => { #[derive(Debug, Error)] pub enum Error0 { #[error("{0:?}")] $variant($value), } #[derive(Debug, Error)] #[error("{0:?}")] pub enum Error1 { $variant($value), } }; } decl_error!(Repro(u8)); assert("0", Error0::Repro(0)); assert("0", Error1::Repro(0)); } thiserror-1.0.20/tests/test_error.rs010064400017500001750000000020641366162667100157540ustar0000000000000000#![deny(clippy::all, clippy::pedantic)] #![allow(dead_code)] use std::fmt::{self, Display}; use std::io; use thiserror::Error; macro_rules! unimplemented_display { ($ty:ty) => { impl Display for $ty { fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result { unimplemented!() } } }; } #[derive(Error, Debug)] struct BracedError { msg: String, pos: usize, } #[derive(Error, Debug)] struct TupleError(String, usize); #[derive(Error, Debug)] struct UnitError; #[derive(Error, Debug)] struct WithSource { #[source] cause: io::Error, } #[derive(Error, Debug)] struct WithAnyhow { #[source] cause: anyhow::Error, } #[derive(Error, Debug)] enum EnumError { Braced { #[source] cause: io::Error, }, Tuple(#[source] io::Error), Unit, } unimplemented_display!(BracedError); unimplemented_display!(TupleError); unimplemented_display!(UnitError); unimplemented_display!(WithSource); unimplemented_display!(WithAnyhow); unimplemented_display!(EnumError); thiserror-1.0.20/tests/test_expr.rs010064400017500001750000000045131366162667100156020ustar0000000000000000#![deny(clippy::all, clippy::pedantic)] use std::fmt::Display; use thiserror::Error; // Some of the elaborate cases from the rcc codebase, which is a C compiler in // Rust. https://github.com/jyn514/rcc/blob/0.8.0/src/data/error.rs #[derive(Error, Debug)] pub enum CompilerError { #[error("cannot shift {} by {maximum} or more bits (got {current})", if *.is_left { "left" } else { "right" })] TooManyShiftBits { is_left: bool, maximum: u64, current: u64, }, #[error("#error {}", (.0).iter().copied().collect::>().join(" "))] User(Vec<&'static str>), #[error("overflow while parsing {}integer literal", if let Some(signed) = .is_signed { if *signed { "signed "} else { "unsigned "} } else { "" } )] IntegerOverflow { is_signed: Option }, #[error("overflow while parsing {}integer literal", match .is_signed { Some(true) => "signed ", Some(false) => "unsigned ", None => "", })] IntegerOverflow2 { is_signed: Option }, } // Examples drawn from Rustup. #[derive(Error, Debug)] pub enum RustupError { #[error( "toolchain '{name}' does not contain component {component}{}", .suggestion .as_ref() .map_or_else(String::new, |s| format!("; did you mean '{}'?", s)), )] UnknownComponent { name: String, component: String, suggestion: Option, }, } fn assert(expected: &str, value: T) { assert_eq!(expected, value.to_string()); } #[test] fn test_rcc() { assert( "cannot shift left by 32 or more bits (got 50)", CompilerError::TooManyShiftBits { is_left: true, maximum: 32, current: 50, }, ); assert("#error A B C", CompilerError::User(vec!["A", "B", "C"])); assert( "overflow while parsing signed integer literal", CompilerError::IntegerOverflow { is_signed: Some(true), }, ); } #[test] fn test_rustup() { assert( "toolchain 'nightly' does not contain component clipy; did you mean 'clippy'?", RustupError::UnknownComponent { name: "nightly".to_owned(), component: "clipy".to_owned(), suggestion: Some("clippy".to_owned()), }, ); } thiserror-1.0.20/tests/test_from.rs010064400017500001750000000012741366162667100155700ustar0000000000000000#![deny(clippy::all, clippy::pedantic)] use std::io; use thiserror::Error; #[derive(Error, Debug)] #[error("...")] pub struct ErrorStruct { #[from] source: io::Error, } #[derive(Error, Debug)] #[error("...")] pub struct ErrorTuple(#[from] io::Error); #[derive(Error, Debug)] #[error("...")] pub enum ErrorEnum { Test { #[from] source: io::Error, }, } #[derive(Error, Debug)] #[error("...")] pub enum Many { Any(#[from] anyhow::Error), Io(#[from] io::Error), } fn assert_impl>() {} #[test] fn test_from() { assert_impl::(); assert_impl::(); assert_impl::(); assert_impl::(); } thiserror-1.0.20/tests/test_lints.rs010064400017500001750000000006411367200121400157310ustar0000000000000000use thiserror::Error; pub use std::error::Error; #[test] fn test_unused_qualifications() { #![deny(unused_qualifications)] // Expansion of derive(Error) macro can't know whether something like // std::error::Error is already imported in the caller's scope so it must // suppress unused_qualifications. #[derive(Debug, Error)] #[error("...")] pub struct MyError; let _: MyError; } thiserror-1.0.20/tests/test_option.rs010064400017500001750000000045051366162667100161350ustar0000000000000000#![cfg_attr(thiserror_nightly_testing, feature(backtrace))] #![deny(clippy::all, clippy::pedantic)] #[cfg(thiserror_nightly_testing)] pub mod structs { use std::backtrace::Backtrace; use thiserror::Error; #[derive(Error, Debug)] #[error("...")] pub struct OptSourceNoBacktrace { #[source] source: Option, } #[derive(Error, Debug)] #[error("...")] pub struct OptSourceAlwaysBacktrace { #[source] source: Option, backtrace: Backtrace, } #[derive(Error, Debug)] #[error("...")] pub struct NoSourceOptBacktrace { #[backtrace] backtrace: Option, } #[derive(Error, Debug)] #[error("...")] pub struct AlwaysSourceOptBacktrace { source: anyhow::Error, #[backtrace] backtrace: Option, } #[derive(Error, Debug)] #[error("...")] pub struct OptSourceOptBacktrace { #[source] source: Option, #[backtrace] backtrace: Option, } } #[cfg(thiserror_nightly_testing)] pub mod enums { use std::backtrace::Backtrace; use thiserror::Error; #[derive(Error, Debug)] pub enum OptSourceNoBacktrace { #[error("...")] Test { #[source] source: Option, }, } #[derive(Error, Debug)] pub enum OptSourceAlwaysBacktrace { #[error("...")] Test { #[source] source: Option, backtrace: Backtrace, }, } #[derive(Error, Debug)] pub enum NoSourceOptBacktrace { #[error("...")] Test { #[backtrace] backtrace: Option, }, } #[derive(Error, Debug)] pub enum AlwaysSourceOptBacktrace { #[error("...")] Test { source: anyhow::Error, #[backtrace] backtrace: Option, }, } #[derive(Error, Debug)] pub enum OptSourceOptBacktrace { #[error("...")] Test { #[source] source: Option, #[backtrace] backtrace: Option, }, } } #[test] #[cfg_attr(not(thiserror_nightly_testing), ignore)] fn test_option() {} thiserror-1.0.20/tests/test_path.rs010064400017500001750000000016121366162667100155550ustar0000000000000000#![deny(clippy::all, clippy::pedantic)] use ref_cast::RefCast; use std::fmt::Display; use std::path::{Path, PathBuf}; use thiserror::Error; #[derive(Error, Debug)] #[error("failed to read '{file}'")] struct StructPathBuf { file: PathBuf, } #[derive(Error, Debug, RefCast)] #[repr(C)] #[error("failed to read '{file}'")] struct StructPath { file: Path, } #[derive(Error, Debug)] enum EnumPathBuf { #[error("failed to read '{0}'")] Read(PathBuf), } fn assert(expected: &str, value: T) { assert_eq!(expected, value.to_string()); } #[test] fn test_display() { let path = Path::new("/thiserror"); let file = path.to_owned(); assert("failed to read '/thiserror'", StructPathBuf { file }); let file = path.to_owned(); assert("failed to read '/thiserror'", EnumPathBuf::Read(file)); assert("failed to read '/thiserror'", StructPath::ref_cast(path)); } thiserror-1.0.20/tests/test_source.rs010064400017500001750000000022231366162667100161200ustar0000000000000000#![deny(clippy::all, clippy::pedantic)] use std::error::Error as StdError; use std::io; use thiserror::Error; #[derive(Error, Debug)] #[error("implicit source")] pub struct ImplicitSource { source: io::Error, } #[derive(Error, Debug)] #[error("explicit source")] pub struct ExplicitSource { source: String, #[source] io: io::Error, } #[derive(Error, Debug)] #[error("boxed source")] pub struct BoxedSource { #[source] source: Box, } #[test] fn test_implicit_source() { let io = io::Error::new(io::ErrorKind::Other, "oh no!"); let error = ImplicitSource { source: io }; error.source().unwrap().downcast_ref::().unwrap(); } #[test] fn test_explicit_source() { let io = io::Error::new(io::ErrorKind::Other, "oh no!"); let error = ExplicitSource { source: String::new(), io, }; error.source().unwrap().downcast_ref::().unwrap(); } #[test] fn test_boxed_source() { let source = Box::new(io::Error::new(io::ErrorKind::Other, "oh no!")); let error = BoxedSource { source }; error.source().unwrap().downcast_ref::().unwrap(); } thiserror-1.0.20/tests/test_transparent.rs010064400017500001750000000026731366162667100171720ustar0000000000000000#![deny(clippy::all, clippy::pedantic)] use anyhow::anyhow; use std::error::Error as _; use std::io; use thiserror::Error; #[test] fn test_transparent_struct() { #[derive(Error, Debug)] #[error(transparent)] struct Error(ErrorKind); #[derive(Error, Debug)] enum ErrorKind { #[error("E0")] E0, #[error("E1")] E1(#[from] io::Error), } let error = Error(ErrorKind::E0); assert_eq!("E0", error.to_string()); assert!(error.source().is_none()); let io = io::Error::new(io::ErrorKind::Other, "oh no!"); let error = Error(ErrorKind::from(io)); assert_eq!("E1", error.to_string()); error.source().unwrap().downcast_ref::().unwrap(); } #[test] fn test_transparent_enum() { #[derive(Error, Debug)] enum Error { #[error("this failed")] This, #[error(transparent)] Other(anyhow::Error), } let error = Error::This; assert_eq!("this failed", error.to_string()); let error = Error::Other(anyhow!("inner").context("outer")); assert_eq!("outer", error.to_string()); assert_eq!("inner", error.source().unwrap().to_string()); } #[test] fn test_anyhow() { #[derive(Error, Debug)] #[error(transparent)] struct Any(#[from] anyhow::Error); let error = Any::from(anyhow!("inner").context("outer")); assert_eq!("outer", error.to_string()); assert_eq!("inner", error.source().unwrap().to_string()); } thiserror-1.0.20/tests/ui/bad-field-attr.rs010064400017500001750000000002131365166002600167410ustar0000000000000000use thiserror::Error; #[derive(Error, Debug)] #[error(transparent)] pub struct Error(#[error(transparent)] std::io::Error); fn main() {} thiserror-1.0.20/tests/ui/bad-field-attr.stderr010064400017500001750000000003541365166046500176350ustar0000000000000000error: #[error(transparent)] needs to go outside the enum or struct, not on an individual field --> $DIR/bad-field-attr.rs:5:18 | 5 | pub struct Error(#[error(transparent)] std::io::Error); | ^^^^^^^^^^^^^^^^^^^^^ thiserror-1.0.20/tests/ui/duplicate-enum-source.rs010064400017500001750000000003041357647346700204160ustar0000000000000000use thiserror::Error; #[derive(Error, Debug)] pub enum ErrorEnum { Confusing { #[source] a: std::io::Error, #[source] b: anyhow::Error, }, } fn main() {} thiserror-1.0.20/tests/ui/duplicate-enum-source.stderr010064400017500001750000000001741357647347100212750ustar0000000000000000error: duplicate #[source] attribute --> $DIR/duplicate-enum-source.rs:8:9 | 8 | #[source] | ^^^^^^^^^ thiserror-1.0.20/tests/ui/duplicate-fmt.rs010066400017500001750000000001571355014646500167350ustar0000000000000000use thiserror::Error; #[derive(Error, Debug)] #[error("...")] #[error("...")] pub struct Error; fn main() {} thiserror-1.0.20/tests/ui/duplicate-fmt.stderr010066400017500001750000000001761355014707200176100ustar0000000000000000error: only one #[error(...)] attribute is allowed --> $DIR/duplicate-fmt.rs:5:1 | 5 | #[error("...")] | ^^^^^^^^^^^^^^^ thiserror-1.0.20/tests/ui/duplicate-struct-source.rs010066400017500001750000000002411357647346400207750ustar0000000000000000use thiserror::Error; #[derive(Error, Debug)] pub struct ErrorStruct { #[source] a: std::io::Error, #[source] b: anyhow::Error, } fn main() {} thiserror-1.0.20/tests/ui/duplicate-struct-source.stderr010064400017500001750000000001661357647347200216570ustar0000000000000000error: duplicate #[source] attribute --> $DIR/duplicate-struct-source.rs:7:5 | 7 | #[source] | ^^^^^^^^^ thiserror-1.0.20/tests/ui/duplicate-transparent.rs010064400017500001750000000002121357107703300204730ustar0000000000000000use thiserror::Error; #[derive(Error, Debug)] #[error(transparent)] #[error(transparent)] pub struct Error(anyhow::Error); fn main() {} thiserror-1.0.20/tests/ui/duplicate-transparent.stderr010064400017500001750000000002201357107703300213510ustar0000000000000000error: duplicate #[error(transparent)] attribute --> $DIR/duplicate-transparent.rs:5:1 | 5 | #[error(transparent)] | ^^^^^^^^^^^^^^^^^^^^^ thiserror-1.0.20/tests/ui/from-not-source.rs010066400017500001750000000002421355047300100172160ustar0000000000000000use thiserror::Error; #[derive(Debug, Error)] pub struct Error { #[source] source: std::io::Error, #[from] other: anyhow::Error, } fn main() {} thiserror-1.0.20/tests/ui/from-not-source.stderr010066400017500001750000000002171355047300100200770ustar0000000000000000error: #[from] is only supported on the source field, not any other field --> $DIR/from-not-source.rs:7:5 | 7 | #[from] | ^^^^^^^ thiserror-1.0.20/tests/ui/lifetime.rs010064400017500001750000000003721363532220100157560ustar0000000000000000use thiserror::Error; #[derive(Error, Debug)] #[error("error")] struct Error<'a>(#[from] Inner<'a>); #[derive(Error, Debug)] #[error("{0}")] struct Inner<'a>(&'a str); fn main() -> Result<(), Error<'static>> { Err(Error(Inner("some text"))) } thiserror-1.0.20/tests/ui/lifetime.stderr010064400017500001750000000002651363532420200166410ustar0000000000000000error: non-static lifetimes are not allowed in the source of an error --> $DIR/lifetime.rs:5:18 | 5 | struct Error<'a>(#[from] Inner<'a>); | ^^^^^^^^^^^^^^^^^ thiserror-1.0.20/tests/ui/missing-display.rs010064400017500001750000000001511364437546000173060ustar0000000000000000use thiserror::Error; #[derive(Error, Debug)] pub enum MyError { First, Second, } fn main() {} thiserror-1.0.20/tests/ui/missing-display.stderr010064400017500001750000000005721364736401300201670ustar0000000000000000error[E0277]: `MyError` doesn't implement `std::fmt::Display` --> $DIR/missing-display.rs:4:1 | 4 | pub enum MyError { | ^^^^^^^^^^^^^^^^ `MyError` cannot be formatted with the default formatter | = help: the trait `std::fmt::Display` is not implemented for `MyError` = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead thiserror-1.0.20/tests/ui/missing-fmt.rs010066400017500001750000000002001355014712400164120ustar0000000000000000use thiserror::Error; #[derive(Error, Debug)] pub enum Error { #[error("...")] A(usize), B(usize), } fn main() {} thiserror-1.0.20/tests/ui/missing-fmt.stderr010066400017500001750000000001651355014712600173050ustar0000000000000000error: missing #[error("...")] display attribute --> $DIR/missing-fmt.rs:7:5 | 7 | B(usize), | ^^^^^^^^ thiserror-1.0.20/tests/ui/no-display.rs010064400017500001750000000002341356167401200162440ustar0000000000000000use std::thread::Thread; use thiserror::Error; #[derive(Error, Debug)] #[error("thread: {thread}")] pub struct Error { thread: Thread, } fn main() {} thiserror-1.0.20/tests/ui/no-display.stderr010064400017500001750000000010011362700766700171250ustar0000000000000000error[E0599]: no method named `as_display` found for reference `&std::thread::Thread` in the current scope --> $DIR/no-display.rs:5:9 | 5 | #[error("thread: {thread}")] | ^^^^^^^^^^^^^^^^^^ method not found in `&std::thread::Thread` | = note: the method `as_display` exists but the following trait bounds were not satisfied: `std::thread::Thread: std::fmt::Display` which is required by `&std::thread::Thread: thiserror::display::DisplayAsDisplay` thiserror-1.0.20/tests/ui/source-enum-not-error.rs010064400017500001750000000002201357647316600203640ustar0000000000000000use thiserror::Error; #[derive(Error, Debug)] #[error("...")] pub enum ErrorEnum { Broken { source: String, }, } fn main() {} thiserror-1.0.20/tests/ui/source-enum-not-error.stderr010064400017500001750000000015271362700767000212440ustar0000000000000000error[E0599]: no method named `as_dyn_error` found for reference `&std::string::String` in the current scope --> $DIR/source-enum-not-error.rs:7:9 | 7 | source: String, | ^^^^^^ method not found in `&std::string::String` | = note: the method `as_dyn_error` exists but the following trait bounds were not satisfied: `std::string::String: std::error::Error` which is required by `std::string::String: thiserror::aserror::AsDynError` `&std::string::String: std::error::Error` which is required by `&std::string::String: thiserror::aserror::AsDynError` `str: std::marker::Sized` which is required by `str: thiserror::aserror::AsDynError` `str: std::error::Error` which is required by `str: thiserror::aserror::AsDynError` thiserror-1.0.20/tests/ui/source-struct-not-error.rs010066400017500001750000000001741357647316200207520ustar0000000000000000use thiserror::Error; #[derive(Error, Debug)] #[error("...")] pub struct ErrorStruct { source: String, } fn main() {} thiserror-1.0.20/tests/ui/source-struct-not-error.stderr010064400017500001750000000012761362700767000216250ustar0000000000000000error[E0599]: no method named `as_dyn_error` found for struct `std::string::String` in the current scope --> $DIR/source-struct-not-error.rs:6:5 | 6 | source: String, | ^^^^^^ method not found in `std::string::String` | = note: the method `as_dyn_error` exists but the following trait bounds were not satisfied: `std::string::String: std::error::Error` which is required by `std::string::String: thiserror::aserror::AsDynError` `str: std::marker::Sized` which is required by `str: thiserror::aserror::AsDynError` `str: std::error::Error` which is required by `str: thiserror::aserror::AsDynError` thiserror-1.0.20/tests/ui/transparent-display.rs010064400017500001750000000002041357107703300201670ustar0000000000000000use thiserror::Error; #[derive(Error, Debug)] #[error(transparent)] #[error("...")] pub struct Error(anyhow::Error); fn main() {} thiserror-1.0.20/tests/ui/transparent-display.stderr010064400017500001750000000002271357107703300210530ustar0000000000000000error: cannot have both #[error(transparent)] and a display attribute --> $DIR/transparent-display.rs:5:1 | 5 | #[error("...")] | ^^^^^^^^^^^^^^^ thiserror-1.0.20/tests/ui/transparent-enum-many.rs010064400017500001750000000002141357107703300204310ustar0000000000000000use thiserror::Error; #[derive(Error, Debug)] pub enum Error { #[error(transparent)] Other(anyhow::Error, String), } fn main() {} thiserror-1.0.20/tests/ui/transparent-enum-many.stderr010064400017500001750000000003221357107703300213100ustar0000000000000000error: #[error(transparent)] requires exactly one field --> $DIR/transparent-enum-many.rs:5:5 | 5 | / #[error(transparent)] 6 | | Other(anyhow::Error, String), | |________________________________^ thiserror-1.0.20/tests/ui/transparent-enum-source.rs010064400017500001750000000002161357107703300207670ustar0000000000000000use thiserror::Error; #[derive(Error, Debug)] pub enum Error { #[error(transparent)] Other(#[source] anyhow::Error), } fn main() {} thiserror-1.0.20/tests/ui/transparent-enum-source.stderr010064400017500001750000000002411357107703300216440ustar0000000000000000error: transparent variant can't contain #[source] --> $DIR/transparent-enum-source.rs:6:11 | 6 | Other(#[source] anyhow::Error), | ^^^^^^^^^ thiserror-1.0.20/tests/ui/transparent-struct-many.rs010064400017500001750000000002241357107703300210120ustar0000000000000000use thiserror::Error; #[derive(Error, Debug)] #[error(transparent)] pub struct Error { inner: anyhow::Error, what: String, } fn main() {} thiserror-1.0.20/tests/ui/transparent-struct-many.stderr010064400017500001750000000002311357107703300216670ustar0000000000000000error: #[error(transparent)] requires exactly one field --> $DIR/transparent-struct-many.rs:4:1 | 4 | #[error(transparent)] | ^^^^^^^^^^^^^^^^^^^^^ thiserror-1.0.20/tests/ui/transparent-struct-source.rs010064400017500001750000000001761357107703300213540ustar0000000000000000use thiserror::Error; #[derive(Error, Debug)] #[error(transparent)] pub struct Error(#[source] anyhow::Error); fn main() {} thiserror-1.0.20/tests/ui/transparent-struct-source.stderr010064400017500001750000000002661357107703300222330ustar0000000000000000error: transparent error struct can't contain #[source] --> $DIR/transparent-struct-source.rs:5:18 | 5 | pub struct Error(#[source] anyhow::Error); | ^^^^^^^^^ thiserror-1.0.20/tests/ui/unexpected-field-fmt.rs010066400017500001750000000002261355043543000201760ustar0000000000000000use thiserror::Error; #[derive(Error, Debug)] pub enum Error { What { #[error("...")] io: std::io::Error, }, } fn main() {} thiserror-1.0.20/tests/ui/unexpected-field-fmt.stderr010066400017500001750000000003061355043545400210620ustar0000000000000000error: not expected here; the #[error(...)] attribute belongs on top of a struct or an enum variant --> $DIR/unexpected-field-fmt.rs:6:9 | 6 | #[error("...")] | ^^^^^^^^^^^^^^^ thiserror-1.0.20/tests/ui/unexpected-struct-source.rs010066400017500001750000000001311355043524300211460ustar0000000000000000use thiserror::Error; #[derive(Error, Debug)] #[source] pub struct Error; fn main() {} thiserror-1.0.20/tests/ui/unexpected-struct-source.stderr010066400017500001750000000002301355043524300220250ustar0000000000000000error: not expected here; the #[source] attribute belongs on a specific field --> $DIR/unexpected-struct-source.rs:4:1 | 4 | #[source] | ^^^^^^^^^ thiserror-1.0.20/tests/ui/union.rs010066400017500001750000000001551355014671400153220ustar0000000000000000use thiserror::Error; #[derive(Error)] pub union U { msg: &'static str, num: usize, } fn main() {} thiserror-1.0.20/tests/ui/union.stderr010066400017500001750000000002331355014674300162000ustar0000000000000000error: union as errors are not supported --> $DIR/union.rs:4:1 | 4 | / pub union U { 5 | | msg: &'static str, 6 | | num: usize, 7 | | } | |_^