Skip to content

Commit

Permalink
fix(miri): Resolve Miri's concerns around unsafe code (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanwhit committed Aug 25, 2022
1 parent 12279f8 commit 5f3429b
Show file tree
Hide file tree
Showing 9 changed files with 388 additions and 153 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -45,6 +45,24 @@ jobs:
- name: Run tests
run: cargo test --all --verbose --features fancy

miri:
name: Miri
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
components: miri,rust-src
override: true
- name: Run tests with miri
env:
MIRIFLAGS: -Zmiri-disable-isolation -Zmiri-strict-provenance
run: cargo miri test --all --verbose --features fancy

minimal_versions:
name: Minimal versions check
runs-on: ${{ matrix.os }}
Expand Down
14 changes: 7 additions & 7 deletions src/eyreish/context.rs
@@ -1,4 +1,4 @@
use super::error::ContextError;
use super::error::{ContextError, ErrorImpl};
use super::{Report, WrapErr};
use core::fmt::{self, Debug, Display, Write};

Expand Down Expand Up @@ -116,7 +116,7 @@ where
D: Display,
{
fn source(&self) -> Option<&(dyn StdError + 'static)> {
Some(self.error.inner.error())
unsafe { Some(ErrorImpl::error(self.error.inner.by_ref())) }
}
}

Expand Down Expand Up @@ -159,23 +159,23 @@ where
D: Display,
{
fn code<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
self.error.inner.diagnostic().code()
unsafe { ErrorImpl::diagnostic(self.error.inner.by_ref()).code() }
}

fn severity(&self) -> Option<crate::Severity> {
self.error.inner.diagnostic().severity()
unsafe { ErrorImpl::diagnostic(self.error.inner.by_ref()).severity() }
}

fn help<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
self.error.inner.diagnostic().help()
unsafe { ErrorImpl::diagnostic(self.error.inner.by_ref()).help() }
}

fn url<'a>(&'a self) -> Option<Box<dyn Display + 'a>> {
self.error.inner.diagnostic().url()
unsafe { ErrorImpl::diagnostic(self.error.inner.by_ref()).url() }
}

fn labels<'a>(&'a self) -> Option<Box<dyn Iterator<Item = LabeledSpan> + 'a>> {
self.error.inner.diagnostic().labels()
unsafe { ErrorImpl::diagnostic(self.error.inner.by_ref()).labels() }
}

fn source_code(&self) -> Option<&dyn crate::SourceCode> {
Expand Down

0 comments on commit 5f3429b

Please sign in to comment.