Skip to content

Commit 916e404

Browse files
committed
Make OsStr and CStr a bit more usable with queries
1 parent 2ee0861 commit 916e404

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

compiler/rustc_data_structures/src/stable_hasher.rs

+6
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,12 @@ where
565565
}
566566
}
567567

568+
impl_stable_traits_for_trivial_type!(::std::ffi::OsStr);
569+
impl_stable_traits_for_trivial_type!(::std::ffi::OsString);
570+
571+
impl_stable_traits_for_trivial_type!(::std::ffi::CStr);
572+
impl_stable_traits_for_trivial_type!(::std::ffi::CString);
573+
568574
impl_stable_traits_for_trivial_type!(::std::path::Path);
569575
impl_stable_traits_for_trivial_type!(::std::path::PathBuf);
570576

compiler/rustc_middle/src/query/erase.rs

+25
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::ffi::{CStr, OsStr};
12
use std::intrinsics::transmute_unchecked;
23
use std::mem::MaybeUninit;
34

@@ -65,6 +66,18 @@ impl<T> EraseType for &'_ [T] {
6566
type Result = [u8; size_of::<&'static [()]>()];
6667
}
6768

69+
impl EraseType for &'_ str {
70+
type Result = [u8; size_of::<&'static str>()];
71+
}
72+
73+
impl EraseType for &'_ OsStr {
74+
type Result = [u8; size_of::<&'static OsStr>()];
75+
}
76+
77+
impl EraseType for &'_ CStr {
78+
type Result = [u8; size_of::<&'static CStr>()];
79+
}
80+
6881
impl<T> EraseType for &'_ ty::List<T> {
6982
type Result = [u8; size_of::<&'static ty::List<()>>()];
7083
}
@@ -180,6 +193,18 @@ impl<T> EraseType for Option<&'_ [T]> {
180193
type Result = [u8; size_of::<Option<&'static [()]>>()];
181194
}
182195

196+
impl EraseType for Option<&'_ str> {
197+
type Result = [u8; size_of::<Option<&'static str>>()];
198+
}
199+
200+
impl EraseType for Option<&'_ OsStr> {
201+
type Result = [u8; size_of::<Option<&'static OsStr>>()];
202+
}
203+
204+
impl EraseType for Option<&'_ CStr> {
205+
type Result = [u8; size_of::<Option<&'static CStr>>()];
206+
}
207+
183208
impl EraseType for Option<mir::DestructuredConstant<'_>> {
184209
type Result = [u8; size_of::<Option<mir::DestructuredConstant<'static>>>()];
185210
}

0 commit comments

Comments
 (0)