Skip to content

Commit

Permalink
Make OsStr and CStr a bit more usable with queries
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Nov 16, 2024
1 parent 2ee0861 commit 916e404
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions compiler/rustc_data_structures/src/stable_hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,12 @@ where
}
}

impl_stable_traits_for_trivial_type!(::std::ffi::OsStr);
impl_stable_traits_for_trivial_type!(::std::ffi::OsString);

impl_stable_traits_for_trivial_type!(::std::ffi::CStr);
impl_stable_traits_for_trivial_type!(::std::ffi::CString);

impl_stable_traits_for_trivial_type!(::std::path::Path);
impl_stable_traits_for_trivial_type!(::std::path::PathBuf);

Expand Down
25 changes: 25 additions & 0 deletions compiler/rustc_middle/src/query/erase.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::ffi::{CStr, OsStr};
use std::intrinsics::transmute_unchecked;
use std::mem::MaybeUninit;

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

impl EraseType for &'_ str {
type Result = [u8; size_of::<&'static str>()];
}

impl EraseType for &'_ OsStr {
type Result = [u8; size_of::<&'static OsStr>()];
}

impl EraseType for &'_ CStr {
type Result = [u8; size_of::<&'static CStr>()];
}

impl<T> EraseType for &'_ ty::List<T> {
type Result = [u8; size_of::<&'static ty::List<()>>()];
}
Expand Down Expand Up @@ -180,6 +193,18 @@ impl<T> EraseType for Option<&'_ [T]> {
type Result = [u8; size_of::<Option<&'static [()]>>()];
}

impl EraseType for Option<&'_ str> {
type Result = [u8; size_of::<Option<&'static str>>()];
}

impl EraseType for Option<&'_ OsStr> {
type Result = [u8; size_of::<Option<&'static OsStr>>()];
}

impl EraseType for Option<&'_ CStr> {
type Result = [u8; size_of::<Option<&'static CStr>>()];
}

impl EraseType for Option<mir::DestructuredConstant<'_>> {
type Result = [u8; size_of::<Option<mir::DestructuredConstant<'static>>>()];
}
Expand Down

0 comments on commit 916e404

Please sign in to comment.