1use glob::{GlobError, PatternError};
2use std::ffi::OsString;
3use std::fmt::{self, Display};
4use std::io;
5use std::path::PathBuf;
6
7#[derive(#[automatically_derived]
impl ::core::fmt::Debug for Error {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Error::Cargo(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Cargo",
&__self_0),
Error::CargoFail =>
::core::fmt::Formatter::write_str(f, "CargoFail"),
Error::GetManifest(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"GetManifest", __self_0, &__self_1),
Error::Glob(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Glob",
&__self_0),
Error::Io(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Io",
&__self_0),
Error::Metadata(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Metadata", &__self_0),
Error::Mismatch =>
::core::fmt::Formatter::write_str(f, "Mismatch"),
Error::NoWorkspaceManifest =>
::core::fmt::Formatter::write_str(f, "NoWorkspaceManifest"),
Error::Open(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f, "Open",
__self_0, &__self_1),
Error::Pattern(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"Pattern", &__self_0),
Error::ProjectDir =>
::core::fmt::Formatter::write_str(f, "ProjectDir"),
Error::ReadStderr(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"ReadStderr", &__self_0),
Error::RunFailed =>
::core::fmt::Formatter::write_str(f, "RunFailed"),
Error::ShouldNotHaveCompiled =>
::core::fmt::Formatter::write_str(f, "ShouldNotHaveCompiled"),
Error::TomlDe(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "TomlDe",
&__self_0),
Error::TomlSer(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"TomlSer", &__self_0),
Error::UpdateVar(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"UpdateVar", &__self_0),
Error::WriteStderr(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"WriteStderr", &__self_0),
}
}
}Debug)]
8pub enum Error {
9 Cargo(io::Error),
10 CargoFail,
11 GetManifest(PathBuf, Box<Error>),
12 Glob(GlobError),
13 Io(io::Error),
14 Metadata(serde_json::Error),
15 Mismatch,
16 NoWorkspaceManifest,
17 Open(PathBuf, io::Error),
18 Pattern(PatternError),
19 ProjectDir,
20 ReadStderr(io::Error),
21 RunFailed,
22 ShouldNotHaveCompiled,
23 TomlDe(toml::de::Error),
24 TomlSer(toml::ser::Error),
25 UpdateVar(OsString),
26 WriteStderr(io::Error),
27}
28
29pub type Result<T> = std::result::Result<T, Error>;
30
31impl Display for Error {
32 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
33 use self::Error::*;
34
35 match self {
36 Cargo(e) => f.write_fmt(format_args!("failed to execute cargo: {0}", e))write!(f, "failed to execute cargo: {}", e),
37 CargoFail => f.write_fmt(format_args!("cargo reported an error"))write!(f, "cargo reported an error"),
38 GetManifest(path, e) => f.write_fmt(format_args!("failed to read manifest {0}: {1}", path.display(),
e))write!(f, "failed to read manifest {}: {}", path.display(), e),
39 Glob(e) => f.write_fmt(format_args!("{0}", e))write!(f, "{}", e),
40 Io(e) => f.write_fmt(format_args!("{0}", e))write!(f, "{}", e),
41 Metadata(e) => f.write_fmt(format_args!("failed to read cargo metadata: {0}", e))write!(f, "failed to read cargo metadata: {}", e),
42 Mismatch => f.write_fmt(format_args!("compiler error does not match expected error"))write!(f, "compiler error does not match expected error"),
43 NoWorkspaceManifest => f.write_fmt(format_args!("Cargo.toml uses edition.workspace=true, but no edition found in workspace\'s manifest"))write!(f, "Cargo.toml uses edition.workspace=true, but no edition found in workspace's manifest"),
44 Open(path, e) => f.write_fmt(format_args!("{0}: {1}", path.display(), e))write!(f, "{}: {}", path.display(), e),
45 Pattern(e) => f.write_fmt(format_args!("{0}", e))write!(f, "{}", e),
46 ProjectDir => f.write_fmt(format_args!("failed to determine name of project dir"))write!(f, "failed to determine name of project dir"),
47 ReadStderr(e) => f.write_fmt(format_args!("failed to read stderr file: {0}", e))write!(f, "failed to read stderr file: {}", e),
48 RunFailed => f.write_fmt(format_args!("execution of the test case was unsuccessful"))write!(f, "execution of the test case was unsuccessful"),
49 ShouldNotHaveCompiled => {
50 f.write_fmt(format_args!("expected test case to fail to compile, but it succeeded"))write!(f, "expected test case to fail to compile, but it succeeded")
51 }
52 TomlDe(e) => f.write_fmt(format_args!("{0}", e))write!(f, "{}", e),
53 TomlSer(e) => f.write_fmt(format_args!("{0}", e))write!(f, "{}", e),
54 UpdateVar(var) => f.write_fmt(format_args!("unrecognized value of TRYBUILD: {0:?}",
var.to_string_lossy()))write!(
55 f,
56 "unrecognized value of TRYBUILD: {:?}",
57 var.to_string_lossy(),
58 ),
59 WriteStderr(e) => f.write_fmt(format_args!("failed to write stderr file: {0}", e))write!(f, "failed to write stderr file: {}", e),
60 }
61 }
62}
63
64impl Error {
65 pub fn already_printed(&self) -> bool {
66 use self::Error::*;
67
68 #[allow(non_exhaustive_omitted_patterns)] match self {
CargoFail | Mismatch | RunFailed | ShouldNotHaveCompiled => true,
_ => false,
}matches!(
69 self,
70 CargoFail | Mismatch | RunFailed | ShouldNotHaveCompiled
71 )
72 }
73}
74
75impl From<GlobError> for Error {
76 fn from(err: GlobError) -> Self {
77 Error::Glob(err)
78 }
79}
80
81impl From<PatternError> for Error {
82 fn from(err: PatternError) -> Self {
83 Error::Pattern(err)
84 }
85}
86
87impl From<io::Error> for Error {
88 fn from(err: io::Error) -> Self {
89 Error::Io(err)
90 }
91}
92
93impl From<toml::de::Error> for Error {
94 fn from(err: toml::de::Error) -> Self {
95 Error::TomlDe(err)
96 }
97}
98
99impl From<toml::ser::Error> for Error {
100 fn from(err: toml::ser::Error) -> Self {
101 Error::TomlSer(err)
102 }
103}