mirror of
https://github.com/dtolnay/thiserror.git
synced 2025-04-04 13:27:38 +03:00
Add trybuild tests for transparent feature
This commit is contained in:
parent
62e8e66bf6
commit
05f0a0fb77
12 changed files with 82 additions and 0 deletions
8
tests/ui/duplicate-transparent.rs
Normal file
8
tests/ui/duplicate-transparent.rs
Normal file
|
@ -0,0 +1,8 @@
|
|||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
#[error(transparent)]
|
||||
#[error(transparent)]
|
||||
pub struct Error(anyhow::Error);
|
||||
|
||||
fn main() {}
|
5
tests/ui/duplicate-transparent.stderr
Normal file
5
tests/ui/duplicate-transparent.stderr
Normal file
|
@ -0,0 +1,5 @@
|
|||
error: duplicate #[error(transparent)] attribute
|
||||
--> $DIR/duplicate-transparent.rs:5:1
|
||||
|
|
||||
5 | #[error(transparent)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
8
tests/ui/transparent-display.rs
Normal file
8
tests/ui/transparent-display.rs
Normal file
|
@ -0,0 +1,8 @@
|
|||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
#[error(transparent)]
|
||||
#[error("...")]
|
||||
pub struct Error(anyhow::Error);
|
||||
|
||||
fn main() {}
|
5
tests/ui/transparent-display.stderr
Normal file
5
tests/ui/transparent-display.stderr
Normal file
|
@ -0,0 +1,5 @@
|
|||
error: cannot have both #[error(transparent)] and a display attribute
|
||||
--> $DIR/transparent-display.rs:5:1
|
||||
|
|
||||
5 | #[error("...")]
|
||||
| ^^^^^^^^^^^^^^^
|
9
tests/ui/transparent-enum-many.rs
Normal file
9
tests/ui/transparent-enum-many.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum Error {
|
||||
#[error(transparent)]
|
||||
Other(anyhow::Error, String),
|
||||
}
|
||||
|
||||
fn main() {}
|
6
tests/ui/transparent-enum-many.stderr
Normal file
6
tests/ui/transparent-enum-many.stderr
Normal 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),
|
||||
| |________________________________^
|
9
tests/ui/transparent-enum-source.rs
Normal file
9
tests/ui/transparent-enum-source.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum Error {
|
||||
#[error(transparent)]
|
||||
Other(#[source] anyhow::Error),
|
||||
}
|
||||
|
||||
fn main() {}
|
5
tests/ui/transparent-enum-source.stderr
Normal file
5
tests/ui/transparent-enum-source.stderr
Normal file
|
@ -0,0 +1,5 @@
|
|||
error: transparent variant can't contain #[source]
|
||||
--> $DIR/transparent-enum-source.rs:6:11
|
||||
|
|
||||
6 | Other(#[source] anyhow::Error),
|
||||
| ^^^^^^^^^
|
10
tests/ui/transparent-struct-many.rs
Normal file
10
tests/ui/transparent-struct-many.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
#[error(transparent)]
|
||||
pub struct Error {
|
||||
inner: anyhow::Error,
|
||||
what: String,
|
||||
}
|
||||
|
||||
fn main() {}
|
5
tests/ui/transparent-struct-many.stderr
Normal file
5
tests/ui/transparent-struct-many.stderr
Normal file
|
@ -0,0 +1,5 @@
|
|||
error: #[error(transparent)] requires exactly one field
|
||||
--> $DIR/transparent-struct-many.rs:4:1
|
||||
|
|
||||
4 | #[error(transparent)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
7
tests/ui/transparent-struct-source.rs
Normal file
7
tests/ui/transparent-struct-source.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
#[error(transparent)]
|
||||
pub struct Error(#[source] anyhow::Error);
|
||||
|
||||
fn main() {}
|
5
tests/ui/transparent-struct-source.stderr
Normal file
5
tests/ui/transparent-struct-source.stderr
Normal 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);
|
||||
| ^^^^^^^^^
|
Loading…
Add table
Add a link
Reference in a new issue