Skip to content

Commit a01330c

Browse files
committed
Make OsStr usable with queries
1 parent ffa2135 commit a01330c

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

compiler/rustc_data_structures/src/stable_hasher.rs

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

568+
impl_stable_traits_for_trivial_type!(::std::ffi::OsStr);
569+
568570
impl_stable_traits_for_trivial_type!(::std::path::Path);
569571
impl_stable_traits_for_trivial_type!(::std::path::PathBuf);
570572

compiler/rustc_middle/src/query/erase.rs

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

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

69+
impl EraseType for &'_ OsStr {
70+
type Result = [u8; size_of::<&'static OsStr>()];
71+
}
72+
6873
impl<T> EraseType for &'_ ty::List<T> {
6974
type Result = [u8; size_of::<&'static ty::List<()>>()];
7075
}
@@ -180,6 +185,10 @@ impl<T> EraseType for Option<&'_ [T]> {
180185
type Result = [u8; size_of::<Option<&'static [()]>>()];
181186
}
182187

188+
impl EraseType for Option<&'_ OsStr> {
189+
type Result = [u8; size_of::<Option<&'static OsStr>>()];
190+
}
191+
183192
impl EraseType for Option<mir::DestructuredConstant<'_>> {
184193
type Result = [u8; size_of::<Option<mir::DestructuredConstant<'static>>>()];
185194
}

compiler/rustc_middle/src/query/keys.rs

+18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Defines the set of legal keys that can be used in queries.
22
3+
use std::ffi::OsStr;
4+
35
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalModDefId, ModDefId};
46
use rustc_hir::hir_id::{HirId, OwnerId};
57
use rustc_query_system::dep_graph::DepNodeIndex;
@@ -492,6 +494,22 @@ impl Key for Option<Symbol> {
492494
}
493495
}
494496

497+
impl<'tcx> Key for &'tcx OsStr {
498+
type Cache<V> = DefaultCache<Self, V>;
499+
500+
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
501+
DUMMY_SP
502+
}
503+
}
504+
505+
impl<'tcx> Key for Option<&'tcx OsStr> {
506+
type Cache<V> = DefaultCache<Self, V>;
507+
508+
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
509+
DUMMY_SP
510+
}
511+
}
512+
495513
/// Canonical query goals correspond to abstract trait operations that
496514
/// are not tied to any crate in particular.
497515
impl<'tcx, T: Clone> Key for CanonicalQueryInput<'tcx, T> {

0 commit comments

Comments
 (0)