1use crate::cfg::CFG;
2use crate::gen::fs;
3use std::error::Erroras StdError;
4use std::ffi::OsString;
5use std::fmt::{self, Display};
6use std::path::Path;
78pub(super) type Result<T, E = Error> = std::result::Result<T, E>;
910#[derive(#[automatically_derived]
impl ::core::fmt::Debug for Error {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Error::NoEnv(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "NoEnv",
&__self_0),
Error::Fs(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Fs",
&__self_0),
Error::ExportedDirNotAbsolute(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"ExportedDirNotAbsolute", &__self_0),
Error::ExportedEmptyPrefix =>
::core::fmt::Formatter::write_str(f, "ExportedEmptyPrefix"),
Error::ExportedDirsWithoutLinks =>
::core::fmt::Formatter::write_str(f,
"ExportedDirsWithoutLinks"),
Error::ExportedPrefixesWithoutLinks =>
::core::fmt::Formatter::write_str(f,
"ExportedPrefixesWithoutLinks"),
Error::ExportedLinksWithoutLinks =>
::core::fmt::Formatter::write_str(f,
"ExportedLinksWithoutLinks"),
Error::UnusedExportedPrefix(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"UnusedExportedPrefix", &__self_0),
Error::UnusedExportedLinks(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"UnusedExportedLinks", &__self_0),
}
}
}Debug)]
11pub(super) enum Error {
12 NoEnv(OsString),
13 Fs(fs::Error),
14 ExportedDirNotAbsolute(&'static Path),
15 ExportedEmptyPrefix,
16 ExportedDirsWithoutLinks,
17 ExportedPrefixesWithoutLinks,
18 ExportedLinksWithoutLinks,
19 UnusedExportedPrefix(&'static str),
20 UnusedExportedLinks(&'static str),
21}
2223macro_rules! expr {
24 ($expr:expr) => {{
25let _ = $expr; // ensure it doesn't fall out of sync with CFG definition
26stringify!($expr)
27 }};
28}
2930const LINKS_DOCUMENTATION: &str =
31"https://doc.rust-lang.org/cargo/reference/build-scripts.html#the-links-manifest-key";
3233impl Displayfor Error {
34fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
35match self{
36Error::NoEnv(var) => {
37f.write_fmt(format_args!("missing {0} environment variable",
var.to_string_lossy()))write!(f, "missing {} environment variable", var.to_string_lossy())38 }
39Error::Fs(err) => err.fmt(f),
40Error::ExportedDirNotAbsolute(path) => f.write_fmt(format_args!("element of {0} must be absolute path, but was: `{1}`",
{ let _ = CFG.exported_header_dirs; "CFG.exported_header_dirs" },
path.display()))write!(
41f,
42"element of {} must be absolute path, but was: `{}`",
43expr!(CFG.exported_header_dirs),
44 path.display(),
45 ),
46Error::ExportedEmptyPrefix => f.write_fmt(format_args!("element of {0} must not be empty string",
{
let _ = CFG.exported_header_prefixes;
"CFG.exported_header_prefixes"
}))write!(
47f,
48"element of {} must not be empty string",
49expr!(CFG.exported_header_prefixes),
50 ),
51Error::ExportedDirsWithoutLinks => f.write_fmt(format_args!("if {0} is nonempty then `links` needs to be set in Cargo.toml; see {1}",
{ let _ = CFG.exported_header_dirs; "CFG.exported_header_dirs" },
LINKS_DOCUMENTATION))write!(
52f,
53"if {} is nonempty then `links` needs to be set in Cargo.toml; see {}",
54expr!(CFG.exported_header_dirs),
55 LINKS_DOCUMENTATION,
56 ),
57Error::ExportedPrefixesWithoutLinks => f.write_fmt(format_args!("if {0} is nonempty then `links` needs to be set in Cargo.toml; see {1}",
{
let _ = CFG.exported_header_prefixes;
"CFG.exported_header_prefixes"
}, LINKS_DOCUMENTATION))write!(
58f,
59"if {} is nonempty then `links` needs to be set in Cargo.toml; see {}",
60expr!(CFG.exported_header_prefixes),
61 LINKS_DOCUMENTATION,
62 ),
63Error::ExportedLinksWithoutLinks => f.write_fmt(format_args!("if {0} is nonempty then `links` needs to be set in Cargo.toml; see {1}",
{ let _ = CFG.exported_header_links; "CFG.exported_header_links" },
LINKS_DOCUMENTATION))write!(
64f,
65"if {} is nonempty then `links` needs to be set in Cargo.toml; see {}",
66expr!(CFG.exported_header_links),
67 LINKS_DOCUMENTATION,
68 ),
69Error::UnusedExportedPrefix(unused) => f.write_fmt(format_args!("unused element in {0}: {1:?} does not match the include prefix of any direct dependency",
{
let _ = CFG.exported_header_prefixes;
"CFG.exported_header_prefixes"
}, unused))write!(
70f,
71"unused element in {}: {:?} does not match the include prefix of any direct dependency",
72expr!(CFG.exported_header_prefixes),
73 unused,
74 ),
75Error::UnusedExportedLinks(unused) => f.write_fmt(format_args!("unused element in {0}: {1:?} does not match the `links` attribute any direct dependency",
{ let _ = CFG.exported_header_links; "CFG.exported_header_links" },
unused))write!(
76f,
77"unused element in {}: {:?} does not match the `links` attribute any direct dependency",
78expr!(CFG.exported_header_links),
79 unused,
80 ),
81 }
82 }
83}
8485impl StdErrorfor Error {
86fn source(&self) -> Option<&(dyn StdError + 'static)> {
87match self{
88Error::Fs(err) => err.source(),
89_ => None,
90 }
91 }
92}
9394impl From<fs::Error> for Error {
95fn from(err: fs::Error) -> Self {
96Error::Fs(err)
97 }
98}