-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #443 from shepmaster/report-return-inference
Improve how the `report` macro handles return type inference
- Loading branch information
Showing
5 changed files
with
129 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#![cfg(test)] | ||
|
||
mod location; | ||
mod report; | ||
|
||
mod api { | ||
use futures::{stream, StreamExt, TryStream}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use snafu::{prelude::*, Report}; | ||
|
||
#[derive(Debug, Snafu)] | ||
struct Error; | ||
|
||
#[test] | ||
fn tokio_main_attribute_first() { | ||
#[tokio::main(flavor = "current_thread")] | ||
#[snafu::report] | ||
async fn mainlike() -> Result<(), Error> { | ||
Snafu.fail() | ||
} | ||
|
||
let _: Report<_> = mainlike(); | ||
} | ||
|
||
#[test] | ||
fn tokio_main_attribute_last() { | ||
#[snafu::report] | ||
#[tokio::main(flavor = "current_thread")] | ||
async fn mainlike() -> Result<(), Error> { | ||
Snafu.fail() | ||
} | ||
|
||
let _: Report<_> = mainlike(); | ||
} | ||
|
||
#[tokio::test] | ||
#[snafu::report] | ||
async fn tokio_test_attribute_first() -> Result<(), Error> { | ||
Ok(()) | ||
} | ||
|
||
#[snafu::report] | ||
#[tokio::test] | ||
async fn tokio_test_attribute_last() -> Result<(), Error> { | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn async_std_main_attribute_last() { | ||
#[derive(Debug, Snafu)] | ||
struct Error; | ||
|
||
#[snafu::report] | ||
#[async_std::main] | ||
async fn main() -> Result<(), Error> { | ||
Snafu.fail() | ||
} | ||
|
||
let _: Report<_> = main(); | ||
} | ||
|
||
#[snafu::report] | ||
#[async_std::test] | ||
async fn async_std_test_attribute_last() -> Result<(), Error> { | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn works_with_tough_inference() { | ||
#[derive(Debug, Snafu)] | ||
struct InnerError; | ||
|
||
#[derive(Debug, Snafu)] | ||
struct OuterError { | ||
source: InnerError, | ||
} | ||
|
||
fn inner() -> Result<(), InnerError> { | ||
InnerSnafu.fail() | ||
} | ||
|
||
#[snafu::report] | ||
#[tokio::main(flavor = "current_thread")] | ||
async fn mainlike() -> Result<(), OuterError> { | ||
loop { | ||
inner().context(OuterSnafu)?; | ||
} | ||
} | ||
|
||
let _: Report<_> = mainlike(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters