Skip to content

Commit 05f0a0f

Browse files
committed
Add trybuild tests for transparent feature
1 parent 62e8e66 commit 05f0a0f

12 files changed

+82
-0
lines changed

tests/ui/duplicate-transparent.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use thiserror::Error;
2+
3+
#[derive(Error, Debug)]
4+
#[error(transparent)]
5+
#[error(transparent)]
6+
pub struct Error(anyhow::Error);
7+
8+
fn main() {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
error: duplicate #[error(transparent)] attribute
2+
--> $DIR/duplicate-transparent.rs:5:1
3+
|
4+
5 | #[error(transparent)]
5+
| ^^^^^^^^^^^^^^^^^^^^^

tests/ui/transparent-display.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use thiserror::Error;
2+
3+
#[derive(Error, Debug)]
4+
#[error(transparent)]
5+
#[error("...")]
6+
pub struct Error(anyhow::Error);
7+
8+
fn main() {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
error: cannot have both #[error(transparent)] and a display attribute
2+
--> $DIR/transparent-display.rs:5:1
3+
|
4+
5 | #[error("...")]
5+
| ^^^^^^^^^^^^^^^

tests/ui/transparent-enum-many.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use thiserror::Error;
2+
3+
#[derive(Error, Debug)]
4+
pub enum Error {
5+
#[error(transparent)]
6+
Other(anyhow::Error, String),
7+
}
8+
9+
fn main() {}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
error: #[error(transparent)] requires exactly one field
2+
--> $DIR/transparent-enum-many.rs:5:5
3+
|
4+
5 | / #[error(transparent)]
5+
6 | | Other(anyhow::Error, String),
6+
| |________________________________^
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use thiserror::Error;
2+
3+
#[derive(Error, Debug)]
4+
pub enum Error {
5+
#[error(transparent)]
6+
Other(#[source] anyhow::Error),
7+
}
8+
9+
fn main() {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
error: transparent variant can't contain #[source]
2+
--> $DIR/transparent-enum-source.rs:6:11
3+
|
4+
6 | Other(#[source] anyhow::Error),
5+
| ^^^^^^^^^
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use thiserror::Error;
2+
3+
#[derive(Error, Debug)]
4+
#[error(transparent)]
5+
pub struct Error {
6+
inner: anyhow::Error,
7+
what: String,
8+
}
9+
10+
fn main() {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
error: #[error(transparent)] requires exactly one field
2+
--> $DIR/transparent-struct-many.rs:4:1
3+
|
4+
4 | #[error(transparent)]
5+
| ^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)