1
1
use core:: fmt:: Display ;
2
+ #[ cfg( feature = "std" ) ]
2
3
use std:: path:: { self , Path , PathBuf } ;
3
4
4
5
#[ doc( hidden) ]
21
22
}
22
23
}
23
24
25
+ #[ cfg( feature = "std" ) ]
24
26
impl < ' a > AsDisplay < ' a > for Path {
25
27
type Target = path:: Display < ' a > ;
26
28
@@ -30,6 +32,7 @@ impl<'a> AsDisplay<'a> for Path {
30
32
}
31
33
}
32
34
35
+ #[ cfg( feature = "std" ) ]
33
36
impl < ' a > AsDisplay < ' a > for PathBuf {
34
37
type Target = path:: Display < ' a > ;
35
38
@@ -42,5 +45,37 @@ impl<'a> AsDisplay<'a> for PathBuf {
42
45
#[ doc( hidden) ]
43
46
pub trait Sealed { }
44
47
impl < T : Display > Sealed for & T { }
48
+ #[ cfg( feature = "std" ) ]
45
49
impl Sealed for Path { }
50
+ #[ cfg( feature = "std" ) ]
46
51
impl Sealed for PathBuf { }
52
+
53
+ // Add a synthetic second impl of AsDisplay to prevent the "single applicable
54
+ // impl" rule from making too weird inference decision based on the single impl
55
+ // for &T, which could lead to code that compiles with thiserror's std feature
56
+ // off but breaks under feature unification when std is turned on by an
57
+ // unrelated crate.
58
+ #[ cfg( not( feature = "std" ) ) ]
59
+ mod placeholder {
60
+ use super :: { AsDisplay , Sealed } ;
61
+ use core:: fmt:: { self , Display } ;
62
+
63
+ pub struct Placeholder ;
64
+
65
+ impl < ' a > AsDisplay < ' a > for Placeholder {
66
+ type Target = Self ;
67
+
68
+ #[ inline]
69
+ fn as_display ( & ' a self ) -> Self :: Target {
70
+ Placeholder
71
+ }
72
+ }
73
+
74
+ impl Display for Placeholder {
75
+ fn fmt ( & self , _formatter : & mut fmt:: Formatter ) -> fmt:: Result {
76
+ unreachable ! ( )
77
+ }
78
+ }
79
+
80
+ impl Sealed for Placeholder { }
81
+ }
0 commit comments