Replace thiserror dependency with handwritten impls

A dependency wasn't carrying its weight for just two Error impls.
This commit is contained in:
David Tolnay 2020-04-25 19:38:59 -07:00
parent 7b4e657015
commit 52509840c7
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
10 changed files with 76 additions and 89 deletions

2
BUCK
View File

@ -12,7 +12,6 @@ rust_library(
"//third-party:proc-macro2",
"//third-party:quote",
"//third-party:syn",
"//third-party:thiserror",
],
)
@ -30,7 +29,6 @@ rust_binary(
"//third-party:quote",
"//third-party:structopt",
"//third-party:syn",
"//third-party:thiserror",
],
)

2
BUILD
View File

@ -15,7 +15,6 @@ rust_library(
"//third-party:proc-macro2",
"//third-party:quote",
"//third-party:syn",
"//third-party:thiserror",
],
)
@ -31,7 +30,6 @@ rust_binary(
"//third-party:quote",
"//third-party:structopt",
"//third-party:syn",
"//third-party:thiserror",
],
)

View File

@ -23,7 +23,6 @@ link-cplusplus = "1.0"
proc-macro2 = { version = "1.0", features = ["span-locations"] }
quote = "1.0"
syn = { version = "1.0", features = ["full"] }
thiserror = "1.0"
[build-dependencies]
cc = "1.0.49"

View File

@ -21,7 +21,6 @@ proc-macro2 = { version = "1.0", features = ["span-locations"] }
quote = "1.0"
structopt = "0.3"
syn = { version = "1.0", features = ["full"] }
thiserror = "1.0"
[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

View File

@ -1,15 +1,59 @@
use crate::gen::Error;
use crate::syntax;
use anyhow::anyhow;
use codespan_reporting::diagnostic::{Diagnostic, Label};
use codespan_reporting::files::SimpleFiles;
use codespan_reporting::term::termcolor::{ColorChoice, StandardStream, WriteColor};
use codespan_reporting::term::{self, Config};
use std::io::Write;
use std::error::Error as StdError;
use std::fmt::{self, Display};
use std::io::{self, Write};
use std::ops::Range;
use std::path::Path;
use std::process;
pub(super) type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Debug)]
pub(super) enum Error {
NoBridgeMod,
OutOfLineMod,
Io(io::Error),
Syn(syn::Error),
}
impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::NoBridgeMod => write!(f, "no #[cxx::bridge] module found"),
Error::OutOfLineMod => write!(f, "#[cxx::bridge] module must have inline contents"),
Error::Io(err) => err.fmt(f),
Error::Syn(err) => err.fmt(f),
}
}
}
impl StdError for Error {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
match self {
Error::Io(err) => Some(err),
Error::Syn(err) => Some(err),
_ => None,
}
}
}
impl From<io::Error> for Error {
fn from(err: io::Error) -> Self {
Error::Io(err)
}
}
impl From<syn::Error> for Error {
fn from(err: syn::Error) -> Self {
Error::Syn(err)
}
}
pub(super) fn format_err(path: &Path, source: &str, error: Error) -> ! {
match error {
Error::Syn(syn_error) => {

View File

@ -6,29 +6,13 @@ pub(super) mod include;
pub(super) mod out;
mod write;
use self::error::format_err;
use self::error::{format_err, Error, Result};
use crate::syntax::namespace::Namespace;
use crate::syntax::{self, check, Types};
use quote::quote;
use std::fs;
use std::io;
use std::path::Path;
use syn::{Attribute, File, Item};
use thiserror::Error;
pub(super) type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Error, Debug)]
pub(super) enum Error {
#[error("no #[cxx::bridge] module found")]
NoBridgeMod,
#[error("#[cxx::bridge] module must have inline contents")]
OutOfLineMod,
#[error(transparent)]
Io(#[from] io::Error),
#[error(transparent)]
Syn(#[from] syn::Error),
}
struct Input {
namespace: Namespace,

View File

@ -1,14 +1,37 @@
use std::error::Error as StdError;
use std::fmt::{self, Display};
use std::io;
use thiserror::Error;
pub(super) type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Error, Debug)]
#[derive(Debug)]
pub(super) enum Error {
#[error("missing OUT_DIR environment variable")]
MissingOutDir,
#[error("failed to locate target dir")]
TargetDir,
#[error(transparent)]
Io(#[from] io::Error),
Io(io::Error),
}
impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Error::MissingOutDir => write!(f, "missing OUT_DIR environment variable"),
Error::TargetDir => write!(f, "failed to locate target dir"),
Error::Io(err) => err.fmt(f),
}
}
}
impl StdError for Error {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
match self {
Error::Io(err) => Some(err),
_ => None,
}
}
}
impl From<io::Error> for Error {
fn from(err: io::Error) -> Self {
Error::Io(err)
}
}

18
third-party/BUCK vendored
View File

@ -169,24 +169,6 @@ rust_library(
deps = [":unicode-width"],
)
rust_library(
name = "thiserror",
srcs = glob(["vendor/thiserror-1.0.15/src/**"]),
visibility = ["PUBLIC"],
deps = [":thiserror-impl"],
)
rust_library(
name = "thiserror-impl",
srcs = glob(["vendor/thiserror-impl-1.0.15/src/**"]),
proc_macro = True,
deps = [
":proc-macro2",
":quote",
":syn",
],
)
rust_library(
name = "unicode-segmentation",
srcs = glob(["vendor/unicode-segmentation-1.6.0/src/**"]),

18
third-party/BUILD vendored
View File

@ -174,24 +174,6 @@ rust_library(
deps = [":unicode-width"],
)
rust_library(
name = "thiserror",
srcs = glob(["vendor/thiserror-1.0.15/src/**"]),
visibility = ["//visibility:public"],
deps = [":thiserror-impl"],
)
rust_library(
name = "thiserror-impl",
srcs = glob(["vendor/thiserror-impl-1.0.15/src/**"]),
crate_type = "proc-macro",
deps = [
":proc-macro2",
":quote",
":syn",
],
)
rust_library(
name = "unicode-segmentation",
srcs = glob(["vendor/unicode-segmentation-1.6.0/src/**"]),

22
third-party/Cargo.lock generated vendored
View File

@ -77,7 +77,6 @@ dependencies = [
"quote",
"rustversion",
"syn",
"thiserror",
"trybuild",
]
@ -98,7 +97,6 @@ dependencies = [
"quote",
"structopt",
"syn",
"thiserror",
]
[[package]]
@ -337,26 +335,6 @@ dependencies = [
"unicode-width",
]
[[package]]
name = "thiserror"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54b3d3d2ff68104100ab257bb6bb0cb26c901abe4bd4ba15961f3bf867924012"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca972988113b7715266f91250ddb98070d033c62a011fa0fcc57434a649310dd"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "toml"
version = "0.5.6"