Skip to content

Commit 3c0e0ce

Browse files
committed
Move ty::SymbolName to its own little module (cute)
1 parent cacaab6 commit 3c0e0ce

File tree

2 files changed

+31
-27
lines changed

2 files changed

+31
-27
lines changed

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ pub use vtable::*;
5454

5555
use std::fmt::Debug;
5656
use std::hash::Hash;
57-
use std::{fmt, str};
5857

5958
pub use crate::ty::diagnostics::*;
6059
pub use rustc_type_ir::AliasKind::*;
@@ -148,6 +147,7 @@ mod opaque_hidden_type;
148147
mod param_env;
149148
mod placeholder;
150149
mod predicate;
150+
mod symbol_name;
151151
mod term;
152152
mod ty_; // FIXME: rename to `ty` once we don't import `crate::ty` here
153153
mod variant_def;
@@ -166,6 +166,7 @@ pub use predicate::{
166166
PolyTypeOutlivesPredicate, Predicate, PredicateKind, ProjectionPredicate,
167167
RegionOutlivesPredicate, SubtypePredicate, ToPredicate, TraitPredicate, TypeOutlivesPredicate,
168168
};
169+
pub use symbol_name::SymbolName;
169170
pub use term::{Term, TermKind};
170171
pub use ty_::Ty;
171172
pub use variant_def::VariantDef;
@@ -1130,32 +1131,6 @@ pub struct CrateInherentImpls {
11301131
pub incoherent_impls: FxHashMap<SimplifiedType, Vec<LocalDefId>>,
11311132
}
11321133

1133-
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, HashStable)]
1134-
pub struct SymbolName<'tcx> {
1135-
/// `&str` gives a consistent ordering, which ensures reproducible builds.
1136-
pub name: &'tcx str,
1137-
}
1138-
1139-
impl<'tcx> SymbolName<'tcx> {
1140-
pub fn new(tcx: TyCtxt<'tcx>, name: &str) -> SymbolName<'tcx> {
1141-
SymbolName {
1142-
name: unsafe { str::from_utf8_unchecked(tcx.arena.alloc_slice(name.as_bytes())) },
1143-
}
1144-
}
1145-
}
1146-
1147-
impl<'tcx> fmt::Display for SymbolName<'tcx> {
1148-
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1149-
fmt::Display::fmt(&self.name, fmt)
1150-
}
1151-
}
1152-
1153-
impl<'tcx> fmt::Debug for SymbolName<'tcx> {
1154-
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1155-
fmt::Display::fmt(&self.name, fmt)
1156-
}
1157-
}
1158-
11591134
#[derive(Debug, Default, Copy, Clone)]
11601135
pub struct InferVarInfo {
11611136
/// This is true if we identified that this Ty (`?T`) is found in a `?T: Foo`
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use std::{fmt, str};
2+
3+
use crate::ty::TyCtxt;
4+
5+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, HashStable)]
6+
pub struct SymbolName<'tcx> {
7+
/// `&str` gives a consistent ordering, which ensures reproducible builds.
8+
pub name: &'tcx str,
9+
}
10+
11+
impl<'tcx> SymbolName<'tcx> {
12+
pub fn new(tcx: TyCtxt<'tcx>, name: &str) -> SymbolName<'tcx> {
13+
SymbolName {
14+
name: unsafe { str::from_utf8_unchecked(tcx.arena.alloc_slice(name.as_bytes())) },
15+
}
16+
}
17+
}
18+
19+
impl<'tcx> fmt::Display for SymbolName<'tcx> {
20+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
21+
fmt::Display::fmt(&self.name, fmt)
22+
}
23+
}
24+
25+
impl<'tcx> fmt::Debug for SymbolName<'tcx> {
26+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
27+
fmt::Display::fmt(&self.name, fmt)
28+
}
29+
}

0 commit comments

Comments
 (0)