Fixed unsound errors (#1143)

This commit is contained in:
Nathan West 2020-08-20 13:51:17 -04:00 committed by GitHub
parent 51a2213fcf
commit af0dd5ef32
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 14 deletions

4
Cargo.lock generated
View file

@ -2307,9 +2307,9 @@ dependencies = [
[[package]] [[package]]
name = "syntect" name = "syntect"
version = "4.3.0" version = "4.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b57a45fdcf4891bc79f635be5c559210a4cfa464891f969724944c713282eedb" checksum = "4e3978df05b5850c839a6b352d3c35ce0478944a4be689be826b53cf75363e88"
dependencies = [ dependencies = [
"bincode", "bincode",
"bitflags", "bitflags",

View file

@ -8,4 +8,4 @@ edition = "2018"
tera = "1" tera = "1"
toml = "0.5" toml = "0.5"
image = "0.23" image = "0.23"
syntect = "4.1" syntect = "4.4"

View file

@ -17,21 +17,18 @@ pub enum ErrorKind {
pub struct Error { pub struct Error {
/// Kind of error /// Kind of error
pub kind: ErrorKind, pub kind: ErrorKind,
pub source: Option<Box<dyn StdError>>, pub source: Option<Box<dyn StdError + Send + Sync>>,
} }
unsafe impl Sync for Error {}
unsafe impl Send for Error {}
impl StdError for Error { impl StdError for Error {
fn source(&self) -> Option<&(dyn StdError + 'static)> { fn source(&self) -> Option<&(dyn StdError + 'static)> {
let mut source = self.source.as_ref().map(|c| &**c); match self.source {
if source.is_none() { Some(ref err) => Some(&**err),
if let ErrorKind::Tera(ref err) = self.kind { None => match self.kind {
source = err.source(); ErrorKind::Tera(ref err) => err.source(),
} _ => None,
},
} }
source
} }
} }
@ -55,7 +52,7 @@ impl Error {
} }
/// Creates generic error with a cause /// Creates generic error with a cause
pub fn chain(value: impl ToString, source: impl Into<Box<dyn StdError>>) -> Self { pub fn chain(value: impl ToString, source: impl Into<Box<dyn StdError + Send + Sync>>) -> Self {
Self { kind: ErrorKind::Msg(value.to_string()), source: Some(source.into()) } Self { kind: ErrorKind::Msg(value.to_string()), source: Some(source.into()) }
} }