]> git.proxmox.com Git - rustc.git/blob - vendor/failure_derive/tests/custom_type_bounds.rs
New upstream version 1.45.0+dfsg1
[rustc.git] / vendor / failure_derive / tests / custom_type_bounds.rs
1 #[macro_use]
2 extern crate failure;
3
4 use std::fmt::Debug;
5
6 use failure::Fail;
7
8 #[derive(Debug, Fail)]
9 #[fail(display = "An error has occurred.")]
10 pub struct UnboundedGenericTupleError<T: 'static + Debug + Send + Sync>(T);
11
12 #[test]
13 fn unbounded_generic_tuple_error() {
14 let s = format!("{}", UnboundedGenericTupleError(()));
15 assert_eq!(&s[..], "An error has occurred.");
16 }
17
18 #[derive(Debug, Fail)]
19 #[fail(display = "An error has occurred: {}", _0)]
20 pub struct FailBoundsGenericTupleError<T: Fail>(T);
21
22 #[test]
23 fn fail_bounds_generic_tuple_error() {
24 let error = FailBoundsGenericTupleError(UnboundedGenericTupleError(()));
25 let s = format!("{}", error);
26 assert_eq!(&s[..], "An error has occurred: An error has occurred.");
27 }
28
29 pub trait NoDisplay: 'static + Debug + Send + Sync {}
30
31 impl NoDisplay for &'static str {}
32
33 #[derive(Debug, Fail)]
34 #[fail(display = "An error has occurred: {:?}", _0)]
35 pub struct CustomBoundsGenericTupleError<T: NoDisplay>(T);
36
37 #[test]
38 fn custom_bounds_generic_tuple_error() {
39 let error = CustomBoundsGenericTupleError("more details unavailable.");
40 let s = format!("{}", error);
41 assert_eq!(
42 &s[..],
43 "An error has occurred: \"more details unavailable.\""
44 );
45 }