]> git.proxmox.com Git - rustc.git/blame - vendor/thiserror/tests/test_path.rs
Update upstream source from tag 'upstream/1.52.1+dfsg1'
[rustc.git] / vendor / thiserror / tests / test_path.rs
CommitLineData
f20569fa
XL
1#![deny(clippy::all, clippy::pedantic)]
2
3use ref_cast::RefCast;
4use std::fmt::Display;
5use std::path::{Path, PathBuf};
6use thiserror::Error;
7
8#[derive(Error, Debug)]
9#[error("failed to read '{file}'")]
10struct StructPathBuf {
11 file: PathBuf,
12}
13
14#[derive(Error, Debug, RefCast)]
15#[repr(C)]
16#[error("failed to read '{file}'")]
17struct StructPath {
18 file: Path,
19}
20
21#[derive(Error, Debug)]
22enum EnumPathBuf {
23 #[error("failed to read '{0}'")]
24 Read(PathBuf),
25}
26
27fn assert<T: Display>(expected: &str, value: T) {
28 assert_eq!(expected, value.to_string());
29}
30
31#[test]
32fn test_display() {
33 let path = Path::new("/thiserror");
34 let file = path.to_owned();
35 assert("failed to read '/thiserror'", StructPathBuf { file });
36 let file = path.to_owned();
37 assert("failed to read '/thiserror'", EnumPathBuf::Read(file));
38 assert("failed to read '/thiserror'", StructPath::ref_cast(path));
39}