Add trybuild tests for transparent feature

This commit is contained in:
David Tolnay 2019-11-30 23:39:22 -08:00
parent 62e8e66bf6
commit 05f0a0fb77
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
12 changed files with 82 additions and 0 deletions

View file

@ -0,0 +1,8 @@
use thiserror::Error;
#[derive(Error, Debug)]
#[error(transparent)]
#[error(transparent)]
pub struct Error(anyhow::Error);
fn main() {}

View file

@ -0,0 +1,5 @@
error: duplicate #[error(transparent)] attribute
--> $DIR/duplicate-transparent.rs:5:1
|
5 | #[error(transparent)]
| ^^^^^^^^^^^^^^^^^^^^^

View file

@ -0,0 +1,8 @@
use thiserror::Error;
#[derive(Error, Debug)]
#[error(transparent)]
#[error("...")]
pub struct Error(anyhow::Error);
fn main() {}

View file

@ -0,0 +1,5 @@
error: cannot have both #[error(transparent)] and a display attribute
--> $DIR/transparent-display.rs:5:1
|
5 | #[error("...")]
| ^^^^^^^^^^^^^^^

View file

@ -0,0 +1,9 @@
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error(transparent)]
Other(anyhow::Error, String),
}
fn main() {}

View file

@ -0,0 +1,6 @@
error: #[error(transparent)] requires exactly one field
--> $DIR/transparent-enum-many.rs:5:5
|
5 | / #[error(transparent)]
6 | | Other(anyhow::Error, String),
| |________________________________^

View file

@ -0,0 +1,9 @@
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error(transparent)]
Other(#[source] anyhow::Error),
}
fn main() {}

View file

@ -0,0 +1,5 @@
error: transparent variant can't contain #[source]
--> $DIR/transparent-enum-source.rs:6:11
|
6 | Other(#[source] anyhow::Error),
| ^^^^^^^^^

View file

@ -0,0 +1,10 @@
use thiserror::Error;
#[derive(Error, Debug)]
#[error(transparent)]
pub struct Error {
inner: anyhow::Error,
what: String,
}
fn main() {}

View file

@ -0,0 +1,5 @@
error: #[error(transparent)] requires exactly one field
--> $DIR/transparent-struct-many.rs:4:1
|
4 | #[error(transparent)]
| ^^^^^^^^^^^^^^^^^^^^^

View file

@ -0,0 +1,7 @@
use thiserror::Error;
#[derive(Error, Debug)]
#[error(transparent)]
pub struct Error(#[source] anyhow::Error);
fn main() {}

View file

@ -0,0 +1,5 @@
error: transparent error struct can't contain #[source]
--> $DIR/transparent-struct-source.rs:5:18
|
5 | pub struct Error(#[source] anyhow::Error);
| ^^^^^^^^^