Skip to content

Commit 861af88

Browse files
committed
Fix CI failure
``` error[E0283]: type annotations needed --> tests/net/addr.rs:34:20 | 34 | cstr!("/").into() | ^^^^ cannot infer type for type parameter `U` | = note: cannot satisfy `_: From<&CStr>` = note: required for `&CStr` to implement `Into<_>` ``` ``` error[E0283]: type annotations needed --> tests/path/arg.rs:19:32 | 19 | assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap())); | ^^^^^^^^^^^^^^ -------------------------- type must be known at this point | | | cannot infer type of the type parameter `Borrowed` declared on the trait `Borrow` | = note: multiple `impl`s satisfying `Cow<'_, CStr>: Borrow<_>` found in the following crates: `alloc`, `core`: - impl<'a, B> Borrow<B> for Cow<'a, B> where B: ToOwned, B: ?Sized; - impl<T> Borrow<T> for T where T: ?Sized; help: consider specifying the generic argument | 19 | assert_eq!(cstr!("hello"), Borrow::<Borrowed>::borrow(&t.as_cow_c_str().unwrap())); | ++++++++++++ ```
1 parent 5245b81 commit 861af88

File tree

2 files changed

+162
-44
lines changed

2 files changed

+162
-44
lines changed

tests/net/addr.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,23 @@ fn encode_decode() {
2828
fn test_unix_addr() {
2929
use rustix::cstr;
3030
use rustix::net::SocketAddrUnix;
31+
use std::borrow::Cow;
3132

3233
assert_eq!(
3334
SocketAddrUnix::new("/").unwrap().path().unwrap(),
34-
cstr!("/").into()
35+
Cow::from(cstr!("/"))
3536
);
3637
assert_eq!(
3738
SocketAddrUnix::new("//").unwrap().path().unwrap(),
38-
cstr!("//").into()
39+
Cow::from(cstr!("//"))
3940
);
4041
assert_eq!(
4142
SocketAddrUnix::new("/foo/bar").unwrap().path().unwrap(),
42-
cstr!("/foo/bar").into()
43+
Cow::from(cstr!("/foo/bar"))
4344
);
4445
assert_eq!(
4546
SocketAddrUnix::new("foo").unwrap().path().unwrap(),
46-
cstr!("foo").into()
47+
Cow::from(cstr!("foo"))
4748
);
4849
SocketAddrUnix::new("/foo\0/bar").unwrap_err();
4950
assert!(SocketAddrUnix::new("").unwrap().path().is_none());

tests/path/arg.rs

Lines changed: 157 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,126 +16,243 @@ fn test_arg() {
1616
let t: &str = "hello";
1717
assert_eq!("hello", Arg::as_str(&t).unwrap());
1818
assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t));
19-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap()));
20-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap()));
19+
assert_eq!(
20+
cstr!("hello"),
21+
Borrow::<CStr>::borrow(&t.as_cow_c_str().unwrap())
22+
);
23+
assert_eq!(
24+
cstr!("hello"),
25+
Borrow::<CStr>::borrow(&t.into_c_str().unwrap())
26+
);
2127

2228
let t: String = "hello".to_owned();
2329
assert_eq!("hello", Arg::as_str(&t).unwrap());
2430
assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t));
25-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap()));
26-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap()));
31+
assert_eq!(
32+
cstr!("hello"),
33+
Borrow::<CStr>::borrow(&t.as_cow_c_str().unwrap())
34+
);
35+
assert_eq!(
36+
cstr!("hello"),
37+
Borrow::<CStr>::borrow(&t.into_c_str().unwrap())
38+
);
2739

2840
let t: &OsStr = OsStr::new("hello");
2941
assert_eq!("hello", t.as_str().unwrap());
3042
assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t));
31-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap()));
32-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap()));
43+
assert_eq!(
44+
cstr!("hello"),
45+
Borrow::<CStr>::borrow(&t.as_cow_c_str().unwrap())
46+
);
47+
assert_eq!(
48+
cstr!("hello"),
49+
Borrow::<CStr>::borrow(&t.into_c_str().unwrap())
50+
);
3351

3452
let t: OsString = OsString::from("hello".to_owned());
3553
assert_eq!("hello", t.as_str().unwrap());
3654
assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t));
37-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap()));
38-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap()));
55+
assert_eq!(
56+
cstr!("hello"),
57+
Borrow::<CStr>::borrow(&t.as_cow_c_str().unwrap())
58+
);
59+
assert_eq!(
60+
cstr!("hello"),
61+
Borrow::<CStr>::borrow(&t.into_c_str().unwrap())
62+
);
3963

4064
let t: &Path = Path::new("hello");
4165
assert_eq!("hello", t.as_str().unwrap());
4266
assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t));
43-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap()));
44-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap()));
67+
assert_eq!(
68+
cstr!("hello"),
69+
Borrow::<CStr>::borrow(&t.as_cow_c_str().unwrap())
70+
);
71+
assert_eq!(
72+
cstr!("hello"),
73+
Borrow::<CStr>::borrow(&t.into_c_str().unwrap())
74+
);
4575

4676
let t: PathBuf = PathBuf::from("hello".to_owned());
4777
assert_eq!("hello", t.as_str().unwrap());
4878
assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t));
49-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap()));
50-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap()));
79+
assert_eq!(
80+
cstr!("hello"),
81+
Borrow::<CStr>::borrow(&t.as_cow_c_str().unwrap())
82+
);
83+
assert_eq!(
84+
cstr!("hello"),
85+
Borrow::<CStr>::borrow(&t.into_c_str().unwrap())
86+
);
5187

5288
let t: &CStr = cstr!("hello");
5389
assert_eq!("hello", t.as_str().unwrap());
5490
assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t));
55-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap()));
56-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap()));
91+
assert_eq!(
92+
cstr!("hello"),
93+
Borrow::<CStr>::borrow(&t.as_cow_c_str().unwrap())
94+
);
95+
assert_eq!(
96+
cstr!("hello"),
97+
Borrow::<CStr>::borrow(&t.into_c_str().unwrap())
98+
);
5799

58100
let t: CString = cstr!("hello").to_owned();
59101
assert_eq!("hello", t.as_str().unwrap());
60102
assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t));
61103
assert_eq!(
62104
cstr!("hello"),
63-
Borrow::borrow(&Arg::as_cow_c_str(&t).unwrap())
105+
Borrow::<CStr>::borrow(&Arg::as_cow_c_str(&t).unwrap())
106+
);
107+
assert_eq!(
108+
cstr!("hello"),
109+
Borrow::<CStr>::borrow(&t.into_c_str().unwrap())
64110
);
65-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap()));
66111

67112
let t: Components<'_> = Path::new("hello").components();
68113
assert_eq!("hello", t.as_str().unwrap());
69114
assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t));
70-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap()));
71-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap()));
115+
assert_eq!(
116+
cstr!("hello"),
117+
Borrow::<CStr>::borrow(&t.as_cow_c_str().unwrap())
118+
);
119+
assert_eq!(
120+
cstr!("hello"),
121+
Borrow::<CStr>::borrow(&t.into_c_str().unwrap())
122+
);
72123

73124
let t: Component<'_> = Path::new("hello").components().next().unwrap();
74125
assert_eq!("hello", t.as_str().unwrap());
75126
assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t));
76-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap()));
77-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap()));
127+
assert_eq!(
128+
cstr!("hello"),
129+
Borrow::<CStr>::borrow(&t.as_cow_c_str().unwrap())
130+
);
131+
assert_eq!(
132+
cstr!("hello"),
133+
Borrow::<CStr>::borrow(&t.into_c_str().unwrap())
134+
);
78135

79136
let t: Iter<'_> = Path::new("hello").iter();
80137
assert_eq!("hello", t.as_str().unwrap());
81138
assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t));
82-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap()));
83-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap()));
139+
assert_eq!(
140+
cstr!("hello"),
141+
Borrow::<CStr>::borrow(&t.as_cow_c_str().unwrap())
142+
);
143+
assert_eq!(
144+
cstr!("hello"),
145+
Borrow::<CStr>::borrow(&t.into_c_str().unwrap())
146+
);
84147

85148
let t: Cow<'_, str> = Cow::Borrowed("hello");
86149
assert_eq!("hello", t.as_str().unwrap());
87150
assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t));
88-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap()));
89-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap()));
151+
assert_eq!(
152+
cstr!("hello"),
153+
Borrow::<CStr>::borrow(&t.as_cow_c_str().unwrap())
154+
);
155+
assert_eq!(
156+
cstr!("hello"),
157+
Borrow::<CStr>::borrow(&t.into_c_str().unwrap())
158+
);
90159

91160
let t: Cow<'_, str> = Cow::Owned("hello".to_owned());
92161
assert_eq!("hello", t.as_str().unwrap());
93162
assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t));
94-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap()));
95-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap()));
163+
assert_eq!(
164+
cstr!("hello"),
165+
Borrow::<CStr>::borrow(&t.as_cow_c_str().unwrap())
166+
);
167+
assert_eq!(
168+
cstr!("hello"),
169+
Borrow::<CStr>::borrow(&t.into_c_str().unwrap())
170+
);
96171

97172
let t: Cow<'_, OsStr> = Cow::Borrowed(OsStr::new("hello"));
98173
assert_eq!("hello", t.as_str().unwrap());
99174
assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t));
100-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap()));
101-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap()));
175+
assert_eq!(
176+
cstr!("hello"),
177+
Borrow::<CStr>::borrow(&t.as_cow_c_str().unwrap())
178+
);
179+
assert_eq!(
180+
cstr!("hello"),
181+
Borrow::<CStr>::borrow(&t.into_c_str().unwrap())
182+
);
102183

103184
let t: Cow<'_, OsStr> = Cow::Owned(OsString::from("hello".to_owned()));
104185
assert_eq!("hello", t.as_str().unwrap());
105186
assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t));
106-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap()));
107-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap()));
187+
assert_eq!(
188+
cstr!("hello"),
189+
Borrow::<CStr>::borrow(&t.as_cow_c_str().unwrap())
190+
);
191+
assert_eq!(
192+
cstr!("hello"),
193+
Borrow::<CStr>::borrow(&t.into_c_str().unwrap())
194+
);
108195

109196
let t: Cow<'_, CStr> = Cow::Borrowed(cstr!("hello"));
110197
assert_eq!("hello", t.as_str().unwrap());
111198
assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t));
112-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap()));
113-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap()));
199+
assert_eq!(
200+
cstr!("hello"),
201+
Borrow::<CStr>::borrow(&t.as_cow_c_str().unwrap())
202+
);
203+
assert_eq!(
204+
cstr!("hello"),
205+
Borrow::<CStr>::borrow(&t.into_c_str().unwrap())
206+
);
114207

115208
let t: Cow<'_, CStr> = Cow::Owned(cstr!("hello").to_owned());
116209
assert_eq!("hello", t.as_str().unwrap());
117210
assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t));
118-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap()));
119-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap()));
211+
assert_eq!(
212+
cstr!("hello"),
213+
Borrow::<CStr>::borrow(&t.as_cow_c_str().unwrap())
214+
);
215+
assert_eq!(
216+
cstr!("hello"),
217+
Borrow::<CStr>::borrow(&t.into_c_str().unwrap())
218+
);
120219

121220
let t: &[u8] = b"hello";
122221
assert_eq!("hello", t.as_str().unwrap());
123222
assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t));
124-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap()));
125-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap()));
223+
assert_eq!(
224+
cstr!("hello"),
225+
Borrow::<CStr>::borrow(&t.as_cow_c_str().unwrap())
226+
);
227+
assert_eq!(
228+
cstr!("hello"),
229+
Borrow::<CStr>::borrow(&t.into_c_str().unwrap())
230+
);
126231

127232
let t: Vec<u8> = b"hello".to_vec();
128233
assert_eq!("hello", t.as_str().unwrap());
129234
assert_eq!("hello".to_owned(), Arg::to_string_lossy(&t));
130-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.as_cow_c_str().unwrap()));
131-
assert_eq!(cstr!("hello"), Borrow::borrow(&t.into_c_str().unwrap()));
235+
assert_eq!(
236+
cstr!("hello"),
237+
Borrow::<CStr>::borrow(&t.as_cow_c_str().unwrap())
238+
);
239+
assert_eq!(
240+
cstr!("hello"),
241+
Borrow::<CStr>::borrow(&t.into_c_str().unwrap())
242+
);
132243

133244
let t: DecInt = DecInt::new(43110);
134245
assert_eq!("43110", t.as_str());
135246
assert_eq!("43110".to_owned(), Arg::to_string_lossy(&t));
136-
assert_eq!(cstr!("43110"), Borrow::borrow(&t.as_cow_c_str().unwrap()));
247+
assert_eq!(
248+
cstr!("43110"),
249+
Borrow::<CStr>::borrow(&t.as_cow_c_str().unwrap())
250+
);
137251
assert_eq!(cstr!("43110"), t.as_c_str());
138-
assert_eq!(cstr!("43110"), Borrow::borrow(&t.into_c_str().unwrap()));
252+
assert_eq!(
253+
cstr!("43110"),
254+
Borrow::<CStr>::borrow(&t.into_c_str().unwrap())
255+
);
139256
}
140257

141258
#[test]

0 commit comments

Comments
 (0)