From 916e4049b96fa4066acd91827634e8333a3559ee Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sat, 16 Nov 2024 18:14:19 +0100 Subject: [PATCH] Make OsStr and CStr a bit more usable with queries --- .../src/stable_hasher.rs | 6 +++++ compiler/rustc_middle/src/query/erase.rs | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/compiler/rustc_data_structures/src/stable_hasher.rs b/compiler/rustc_data_structures/src/stable_hasher.rs index 0872bd2c9acc9..4fdec3c6c5e12 100644 --- a/compiler/rustc_data_structures/src/stable_hasher.rs +++ b/compiler/rustc_data_structures/src/stable_hasher.rs @@ -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); diff --git a/compiler/rustc_middle/src/query/erase.rs b/compiler/rustc_middle/src/query/erase.rs index a12c79b78bedf..b27d881e2695b 100644 --- a/compiler/rustc_middle/src/query/erase.rs +++ b/compiler/rustc_middle/src/query/erase.rs @@ -1,3 +1,4 @@ +use std::ffi::{CStr, OsStr}; use std::intrinsics::transmute_unchecked; use std::mem::MaybeUninit; @@ -65,6 +66,18 @@ impl 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 EraseType for &'_ ty::List { type Result = [u8; size_of::<&'static ty::List<()>>()]; } @@ -180,6 +193,18 @@ impl EraseType for Option<&'_ [T]> { type Result = [u8; size_of::>()]; } +impl EraseType for Option<&'_ str> { + type Result = [u8; size_of::>()]; +} + +impl EraseType for Option<&'_ OsStr> { + type Result = [u8; size_of::>()]; +} + +impl EraseType for Option<&'_ CStr> { + type Result = [u8; size_of::>()]; +} + impl EraseType for Option> { type Result = [u8; size_of::>>()]; }