1 //! An "interner" is a data structure that associates values with usize tags and
2 //! allows bidirectional lookup; i.e., given a value, one can easily find the
3 //! type, and vice versa.
5 use arena::DroplessArena;
6 use rustc_data_structures::fx::FxHashMap;
7 use rustc_data_structures::indexed_vec::Idx;
8 use rustc_data_structures::newtype_index;
9 use rustc_macros::symbols;
10 use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
11 use rustc_serialize::{UseSpecializedDecodable, UseSpecializedEncodable};
13 use std::cmp::{PartialEq, Ordering, PartialOrd, Ord};
15 use std::hash::{Hash, Hasher};
18 use crate::{Span, DUMMY_SP, GLOBALS};
24 // After modifying this list adjust `is_special`, `is_used_keyword`/`is_unused_keyword`,
25 // this should be rarely necessary though if the keywords are kept in alphabetic order.
27 // Special reserved identifiers used internally for elided lifetimes,
28 // unnamed method parameters, crate root module, error recovery etc.
31 DollarCrate: "$crate",
34 // Keywords that are used in stable Rust.
71 // Keywords that are used in unstable Rust or reserved for future use.
85 // Edition-specific keywords that are used in stable Rust.
86 Dyn: "dyn", // >= 2018 Edition only
88 // Edition-specific keywords that are used in unstable Rust or reserved for future use.
89 Async: "async", // >= 2018 Edition only
90 Await: "await", // >= 2018 Edition only
91 Try: "try", // >= 2018 Edition only
93 // Special lifetime names
94 UnderscoreLifetime: "'_",
95 StaticLifetime: "'static",
97 // Weak keywords, have special meaning only in specific contexts.
104 // Symbols that can be referred to with syntax_pos::sym::*. The symbol is
105 // the stringified identifier unless otherwise specified (e.g.
106 // `proc_dash_macro` represents "proc-macro").
108 // As well as the symbols listed, there are symbols for the the strings
109 // "0", "1", ..., "9", which are accessible via `sym::integer`.
111 aarch64_target_feature,
114 abi_msp430_interrupt,
122 advanced_slice_patterns,
134 allow_internal_unsafe,
135 allow_internal_unstable,
136 allow_internal_unstable_backcompat_hack,
140 arbitrary_enum_discriminant,
141 arbitrary_self_types,
148 associated_type_bounds,
149 associated_type_defaults,
156 augmented_assignments,
157 automatically_derived,
158 avx512_target_feature,
163 bind_by_move_pattern_guards,
166 borrowck_graphviz_postflow,
167 borrowck_graphviz_preflow,
170 braced_empty_structs,
178 cfg_target_has_atomic,
179 cfg_target_thread_local,
187 closure_to_fn_coercion,
189 cmpxchg16b_target_feature,
196 conservative_impl_trait,
198 const_compare_raw_pointers,
204 const_in_array_repeat_expressions,
208 const_raw_ptr_to_usize_cast,
222 crate_visibility_modifier,
225 custom_inner_attributes,
226 custom_test_frameworks,
233 default_lib_allocator,
234 default_type_parameter_fallback,
249 document_private_items,
250 dotdoteq_in_patterns,
251 dotdot_in_tuple_patterns,
252 double_braced_crate: "{{crate}}",
253 double_braced_impl: "{{impl}}",
254 double_braced_misc: "{{misc}}",
255 double_braced_closure: "{{closure}}",
256 double_braced_constructor: "{{constructor}}",
257 double_braced_constant: "{{constant}}",
258 double_braced_opaque: "{{opaque}}",
260 dropck_parametricity,
275 exclusive_range_pattern,
276 exhaustive_integer_patterns,
282 extern_absolute_paths,
284 extern_crate_item_prelude,
295 field_init_shorthand,
318 generic_associated_types,
327 hexagon_target_feature,
329 homogeneous_aggregate,
343 if_while_or_patterns,
345 impl_header_lifetime_elision,
347 impl_trait_in_bindings,
355 inclusive_range_syntax,
356 infer_outlives_requirements,
357 infer_static_outlives_requirements,
364 irrefutable_let_patterns,
367 issue_5723_bootstrap,
368 issue_tracker_base_url,
388 link_llvm_intrinsics,
397 macro_at_most_once_rep,
400 macro_lifetime_matcher,
401 macro_literal_matcher,
412 match_beginning_vert,
413 match_default_bindings,
426 movbe_target_feature,
460 omit_gdb_pretty_printer_section,
467 optin_builtin_traits,
476 overlapping_marker_traits,
481 panic_implementation,
501 poll_with_tls_context,
502 powerpc_target_feature,
503 precise_pointer_size_matching,
507 proc_dash_macro: "proc-macro",
509 proc_macro_attribute,
515 proc_macro_internals,
517 proc_macro_non_items,
518 proc_macro_path_invoc,
522 quad_precision_float,
535 reexport_test_harness_main,
545 re_rebalance_coherence,
561 rustc_allocator_nounwind,
562 rustc_allow_const_fn_ptr,
563 rustc_args_required_const,
567 rustc_const_unstable,
568 rustc_conversion_suggestion,
571 rustc_diagnostic_macros,
574 rustc_dump_env_program_clauses,
575 rustc_dump_program_clauses,
576 rustc_dump_user_substs,
578 rustc_expected_cgu_reuse,
579 rustc_if_this_changed,
580 rustc_inherit_overflow_checks,
582 rustc_layout_scalar_valid_range_end,
583 rustc_layout_scalar_valid_range_start,
584 rustc_macro_transparency,
586 rustc_nonnull_optimization_guaranteed,
587 rustc_object_lifetime_default,
588 rustc_on_unimplemented,
591 rustc_partition_codegened,
592 rustc_partition_reused,
594 rustc_peek_definite_init,
595 rustc_peek_maybe_init,
596 rustc_peek_maybe_uninit,
598 rustc_proc_macro_decls,
602 rustc_std_internal_symbol,
606 rustc_then_this_would_need,
611 rust_eh_unwind_resume,
613 rvalue_static_promotion,
629 sse4a_target_feature,
642 stmt_expr_attributes,
644 struct_field_attributes,
656 termination_trait_test,
659 test_accepted_feature,
661 test_removed_feature,
681 type_alias_impl_trait,
684 type_alias_enum_variants,
694 underscore_const_names,
696 underscore_lifetimes,
699 universal_impl_trait,
702 unrestricted_attribute_tokens,
705 unsized_tuple_coercion,
720 visible_private_types,
723 warn_directory_ownership,
734 #[derive(Copy, Clone, Eq)]
742 /// Constructs a new identifier from a symbol and a span.
743 pub const fn new(name: Symbol, span: Span) -> Ident {
747 /// Constructs a new identifier with a dummy span.
749 pub const fn with_dummy_span(name: Symbol) -> Ident {
750 Ident::new(name, DUMMY_SP)
754 pub fn invalid() -> Ident {
755 Ident::with_dummy_span(kw::Invalid)
758 /// Maps an interned string to an identifier with an empty syntax context.
759 pub fn from_interned_str(string: InternedString) -> Ident {
760 Ident::with_dummy_span(string.as_symbol())
763 /// Maps a string to an identifier with an empty span.
764 pub fn from_str(string: &str) -> Ident {
765 Ident::with_dummy_span(Symbol::intern(string))
768 /// Maps a string and a span to an identifier.
769 pub fn from_str_and_span(string: &str, span: Span) -> Ident {
770 Ident::new(Symbol::intern(string), span)
773 /// Replaces `lo` and `hi` with those from `span`, but keep hygiene context.
774 pub fn with_span_pos(self, span: Span) -> Ident {
775 Ident::new(self.name, span.with_ctxt(self.span.ctxt()))
778 pub fn without_first_quote(self) -> Ident {
779 Ident::new(Symbol::intern(self.as_str().trim_start_matches('\'')), self.span)
782 /// "Normalize" ident for use in comparisons using "item hygiene".
783 /// Identifiers with same string value become same if they came from the same "modern" macro
784 /// (e.g., `macro` item, but not `macro_rules` item) and stay different if they came from
785 /// different "modern" macros.
786 /// Technically, this operation strips all non-opaque marks from ident's syntactic context.
787 pub fn modern(self) -> Ident {
788 Ident::new(self.name, self.span.modern())
791 /// "Normalize" ident for use in comparisons using "local variable hygiene".
792 /// Identifiers with same string value become same if they came from the same non-transparent
793 /// macro (e.g., `macro` or `macro_rules!` items) and stay different if they came from different
794 /// non-transparent macros.
795 /// Technically, this operation strips all transparent marks from ident's syntactic context.
796 pub fn modern_and_legacy(self) -> Ident {
797 Ident::new(self.name, self.span.modern_and_legacy())
800 /// Transforms an identifier into one with the same name, but gensymed.
801 pub fn gensym(self) -> Ident {
802 let name = with_interner(|interner| interner.gensymed(self.name));
803 Ident::new(name, self.span)
806 /// Transforms an underscore identifier into one with the same name, but
807 /// gensymed. Leaves non-underscore identifiers unchanged.
808 pub fn gensym_if_underscore(self) -> Ident {
809 if self.name == kw::Underscore { self.gensym() } else { self }
812 // WARNING: this function is deprecated and will be removed in the future.
813 pub fn is_gensymed(self) -> bool {
814 with_interner(|interner| interner.is_gensymed(self.name))
817 pub fn as_str(self) -> LocalInternedString {
821 pub fn as_interned_str(self) -> InternedString {
822 self.name.as_interned_str()
826 impl PartialEq for Ident {
827 fn eq(&self, rhs: &Self) -> bool {
828 self.name == rhs.name && self.span.ctxt() == rhs.span.ctxt()
832 impl Hash for Ident {
833 fn hash<H: Hasher>(&self, state: &mut H) {
834 self.name.hash(state);
835 self.span.ctxt().hash(state);
839 impl fmt::Debug for Ident {
840 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
841 write!(f, "{}{:?}", self.name, self.span.ctxt())
845 impl fmt::Display for Ident {
846 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
847 fmt::Display::fmt(&self.name, f)
851 impl UseSpecializedEncodable for Ident {}
853 impl UseSpecializedDecodable for Ident {}
855 /// A symbol is an interned or gensymed string. A gensym is a symbol that is
856 /// never equal to any other symbol.
858 /// Conceptually, a gensym can be thought of as a normal symbol with an
859 /// invisible unique suffix. Gensyms are useful when creating new identifiers
860 /// that must not match any existing identifiers, e.g. during macro expansion
861 /// and syntax desugaring. Because gensyms should always be identifiers, all
862 /// gensym operations are on `Ident` rather than `Symbol`. (Indeed, in the
863 /// future the gensym-ness may be moved from `Symbol` to hygiene data.)
867 /// assert_eq!(Ident::from_str("x"), Ident::from_str("x"))
868 /// assert_ne!(Ident::from_str("x").gensym(), Ident::from_str("x"))
869 /// assert_ne!(Ident::from_str("x").gensym(), Ident::from_str("x").gensym())
871 /// Internally, a symbol is implemented as an index, and all operations
872 /// (including hashing, equality, and ordering) operate on that index. The use
873 /// of `newtype_index!` means that `Option<Symbol>` only takes up 4 bytes,
874 /// because `newtype_index!` reserves the last 256 values for tagging purposes.
876 /// Note that `Symbol` cannot directly be a `newtype_index!` because it
877 /// implements `fmt::Debug`, `Encodable`, and `Decodable` in special ways.
878 #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
879 pub struct Symbol(SymbolIndex);
882 pub struct SymbolIndex { .. }
886 const fn new(n: u32) -> Self {
887 Symbol(SymbolIndex::from_u32_const(n))
890 /// Maps a string to its interned representation.
891 pub fn intern(string: &str) -> Self {
892 with_interner(|interner| interner.intern(string))
895 pub fn as_str(self) -> LocalInternedString {
896 with_interner(|interner| unsafe {
897 LocalInternedString {
898 string: std::mem::transmute::<&str, &str>(interner.get(self))
903 pub fn as_interned_str(self) -> InternedString {
904 with_interner(|interner| InternedString {
905 symbol: interner.interned(self)
909 pub fn as_u32(self) -> u32 {
914 impl fmt::Debug for Symbol {
915 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
916 let is_gensymed = with_interner(|interner| interner.is_gensymed(*self));
918 write!(f, "{}({:?})", self, self.0)
920 write!(f, "{}", self)
925 impl fmt::Display for Symbol {
926 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
927 fmt::Display::fmt(&self.as_str(), f)
931 impl Encodable for Symbol {
932 fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
933 s.emit_str(&self.as_str())
937 impl Decodable for Symbol {
938 fn decode<D: Decoder>(d: &mut D) -> Result<Symbol, D::Error> {
939 Ok(Symbol::intern(&d.read_str()?))
943 // The `&'static str`s in this type actually point into the arena.
945 // Note that normal symbols are indexed upward from 0, and gensyms are indexed
946 // downward from SymbolIndex::MAX_AS_U32.
948 pub struct Interner {
949 arena: DroplessArena,
950 names: FxHashMap<&'static str, Symbol>,
951 strings: Vec<&'static str>,
952 gensyms: Vec<Symbol>,
956 fn prefill(init: &[&'static str]) -> Self {
958 strings: init.into(),
959 names: init.iter().copied().zip((0..).map(Symbol::new)).collect(),
964 pub fn intern(&mut self, string: &str) -> Symbol {
965 if let Some(&name) = self.names.get(string) {
969 let name = Symbol::new(self.strings.len() as u32);
971 // `from_utf8_unchecked` is safe since we just allocated a `&str` which is known to be
973 let string: &str = unsafe {
974 str::from_utf8_unchecked(self.arena.alloc_slice(string.as_bytes()))
976 // It is safe to extend the arena allocation to `'static` because we only access
977 // these while the arena is still alive.
978 let string: &'static str = unsafe {
979 &*(string as *const str)
981 self.strings.push(string);
982 self.names.insert(string, name);
986 fn interned(&self, symbol: Symbol) -> Symbol {
987 if (symbol.0.as_usize()) < self.strings.len() {
990 self.gensyms[(SymbolIndex::MAX_AS_U32 - symbol.0.as_u32()) as usize]
994 fn gensymed(&mut self, symbol: Symbol) -> Symbol {
995 self.gensyms.push(symbol);
996 Symbol::new(SymbolIndex::MAX_AS_U32 - self.gensyms.len() as u32 + 1)
999 fn is_gensymed(&mut self, symbol: Symbol) -> bool {
1000 symbol.0.as_usize() >= self.strings.len()
1003 // Get the symbol as a string. `Symbol::as_str()` should be used in
1004 // preference to this function.
1005 pub fn get(&self, symbol: Symbol) -> &str {
1006 match self.strings.get(symbol.0.as_usize()) {
1007 Some(string) => string,
1009 let symbol = self.gensyms[(SymbolIndex::MAX_AS_U32 - symbol.0.as_u32()) as usize];
1010 self.strings[symbol.0.as_usize()]
1016 // This module has a very short name because it's used a lot.
1022 // This module has a very short name because it's used a lot.
1024 use std::convert::TryInto;
1029 // Get the symbol for an integer. The first few non-negative integers each
1030 // have a static symbol and therefore are fast.
1031 pub fn integer<N: TryInto<usize> + Copy + ToString>(n: N) -> Symbol {
1032 if let Result::Ok(idx) = n.try_into() {
1033 if let Option::Some(&sym) = digits_array.get(idx) {
1037 Symbol::intern(&n.to_string())
1042 fn is_used_keyword_2018(self) -> bool {
1046 fn is_unused_keyword_2018(self) -> bool {
1047 self >= kw::Async && self <= kw::Try
1050 /// Used for sanity checking rustdoc keyword sections.
1051 pub fn is_doc_keyword(self) -> bool {
1055 /// A keyword or reserved identifier that can be used as a path segment.
1056 pub fn is_path_segment_keyword(self) -> bool {
1057 self == kw::Super ||
1058 self == kw::SelfLower ||
1059 self == kw::SelfUpper ||
1060 self == kw::Crate ||
1061 self == kw::PathRoot ||
1062 self == kw::DollarCrate
1065 /// This symbol can be a raw identifier.
1066 pub fn can_be_raw(self) -> bool {
1067 self != kw::Invalid && self != kw::Underscore && !self.is_path_segment_keyword()
1072 // Returns `true` for reserved identifiers used internally for elided lifetimes,
1073 // unnamed method parameters, crate root module, error recovery etc.
1074 pub fn is_special(self) -> bool {
1075 self.name <= kw::Underscore
1078 /// Returns `true` if the token is a keyword used in the language.
1079 pub fn is_used_keyword(self) -> bool {
1080 // Note: `span.edition()` is relatively expensive, don't call it unless necessary.
1081 self.name >= kw::As && self.name <= kw::While ||
1082 self.name.is_used_keyword_2018() && self.span.rust_2018()
1085 /// Returns `true` if the token is a keyword reserved for possible future use.
1086 pub fn is_unused_keyword(self) -> bool {
1087 // Note: `span.edition()` is relatively expensive, don't call it unless necessary.
1088 self.name >= kw::Abstract && self.name <= kw::Yield ||
1089 self.name.is_unused_keyword_2018() && self.span.rust_2018()
1092 /// Returns `true` if the token is either a special identifier or a keyword.
1093 pub fn is_reserved(self) -> bool {
1094 self.is_special() || self.is_used_keyword() || self.is_unused_keyword()
1097 /// A keyword or reserved identifier that can be used as a path segment.
1098 pub fn is_path_segment_keyword(self) -> bool {
1099 self.name.is_path_segment_keyword()
1102 /// We see this identifier in a normal identifier position, like variable name or a type.
1103 /// How was it written originally? Did it use the raw form? Let's try to guess.
1104 pub fn is_raw_guess(self) -> bool {
1105 self.name.can_be_raw() && self.is_reserved()
1109 // If an interner exists, return it. Otherwise, prepare a fresh one.
1111 fn with_interner<T, F: FnOnce(&mut Interner) -> T>(f: F) -> T {
1112 GLOBALS.with(|globals| f(&mut *globals.symbol_interner.lock()))
1115 /// An alternative to `Symbol` and `InternedString`, useful when the chars
1116 /// within the symbol need to be accessed. It is best used for temporary
1119 /// Because the interner outlives any thread which uses this type, we can
1120 /// safely treat `string` which points to interner data, as an immortal string,
1121 /// as long as this type never crosses between threads.
1123 // FIXME: ensure that the interner outlives any thread which uses
1124 // `LocalInternedString`, by creating a new thread right after constructing the
1126 #[derive(Clone, Copy, Hash, PartialOrd, Eq, Ord)]
1127 pub struct LocalInternedString {
1128 string: &'static str,
1131 impl LocalInternedString {
1132 /// Maps a string to its interned representation.
1133 pub fn intern(string: &str) -> Self {
1134 let string = with_interner(|interner| {
1135 let symbol = interner.intern(string);
1136 interner.strings[symbol.0.as_usize()]
1138 LocalInternedString {
1139 string: unsafe { std::mem::transmute::<&str, &str>(string) }
1143 pub fn as_interned_str(self) -> InternedString {
1145 symbol: Symbol::intern(self.string)
1150 pub fn get(&self) -> &str {
1151 // This returns a valid string since we ensure that `self` outlives the interner
1152 // by creating the interner on a thread which outlives threads which can access it.
1153 // This type cannot move to a thread which outlives the interner since it does
1154 // not implement Send.
1159 impl<U: ?Sized> std::convert::AsRef<U> for LocalInternedString
1161 str: std::convert::AsRef<U>
1164 fn as_ref(&self) -> &U {
1165 self.string.as_ref()
1169 impl<T: std::ops::Deref<Target = str>> std::cmp::PartialEq<T> for LocalInternedString {
1170 fn eq(&self, other: &T) -> bool {
1171 self.string == other.deref()
1175 impl std::cmp::PartialEq<LocalInternedString> for str {
1176 fn eq(&self, other: &LocalInternedString) -> bool {
1177 self == other.string
1181 impl<'a> std::cmp::PartialEq<LocalInternedString> for &'a str {
1182 fn eq(&self, other: &LocalInternedString) -> bool {
1183 *self == other.string
1187 impl std::cmp::PartialEq<LocalInternedString> for String {
1188 fn eq(&self, other: &LocalInternedString) -> bool {
1189 self == other.string
1193 impl<'a> std::cmp::PartialEq<LocalInternedString> for &'a String {
1194 fn eq(&self, other: &LocalInternedString) -> bool {
1195 *self == other.string
1199 impl !Send for LocalInternedString {}
1200 impl !Sync for LocalInternedString {}
1202 impl std::ops::Deref for LocalInternedString {
1205 fn deref(&self) -> &str { self.string }
1208 impl fmt::Debug for LocalInternedString {
1209 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1210 fmt::Debug::fmt(self.string, f)
1214 impl fmt::Display for LocalInternedString {
1215 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1216 fmt::Display::fmt(self.string, f)
1220 impl Decodable for LocalInternedString {
1221 fn decode<D: Decoder>(d: &mut D) -> Result<LocalInternedString, D::Error> {
1222 Ok(LocalInternedString::intern(&d.read_str()?))
1226 impl Encodable for LocalInternedString {
1227 fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
1228 s.emit_str(self.string)
1232 /// An alternative to `Symbol` that is focused on string contents. It has two
1233 /// main differences to `Symbol`.
1235 /// First, its implementations of `Hash`, `PartialOrd` and `Ord` work with the
1236 /// string chars rather than the symbol integer. This is useful when hash
1237 /// stability is required across compile sessions, or a guaranteed sort
1238 /// ordering is required.
1240 /// Second, gensym-ness is irrelevant. E.g.:
1242 /// assert_ne!(Symbol::gensym("x"), Symbol::gensym("x"))
1243 /// assert_eq!(Symbol::gensym("x").as_interned_str(), Symbol::gensym("x").as_interned_str())
1245 #[derive(Clone, Copy, PartialEq, Eq)]
1246 pub struct InternedString {
1250 impl InternedString {
1251 /// Maps a string to its interned representation.
1252 pub fn intern(string: &str) -> Self {
1254 symbol: Symbol::intern(string)
1258 pub fn with<F: FnOnce(&str) -> R, R>(self, f: F) -> R {
1259 let str = with_interner(|interner| {
1260 interner.get(self.symbol) as *const str
1262 // This is safe because the interner keeps string alive until it is dropped.
1263 // We can access it because we know the interner is still alive since we use a
1264 // scoped thread local to access it, and it was alive at the beginning of this scope
1268 fn with2<F: FnOnce(&str, &str) -> R, R>(self, other: &InternedString, f: F) -> R {
1269 let (self_str, other_str) = with_interner(|interner| {
1270 (interner.get(self.symbol) as *const str,
1271 interner.get(other.symbol) as *const str)
1273 // This is safe for the same reason that `with` is safe.
1274 unsafe { f(&*self_str, &*other_str) }
1277 pub fn as_symbol(self) -> Symbol {
1281 pub fn as_str(self) -> LocalInternedString {
1282 self.symbol.as_str()
1286 impl Hash for InternedString {
1287 fn hash<H: Hasher>(&self, state: &mut H) {
1288 self.with(|str| str.hash(state))
1292 impl PartialOrd<InternedString> for InternedString {
1293 fn partial_cmp(&self, other: &InternedString) -> Option<Ordering> {
1294 if self.symbol == other.symbol {
1295 return Some(Ordering::Equal);
1297 self.with2(other, |self_str, other_str| self_str.partial_cmp(other_str))
1301 impl Ord for InternedString {
1302 fn cmp(&self, other: &InternedString) -> Ordering {
1303 if self.symbol == other.symbol {
1304 return Ordering::Equal;
1306 self.with2(other, |self_str, other_str| self_str.cmp(other_str))
1310 impl fmt::Debug for InternedString {
1311 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1312 self.with(|str| fmt::Debug::fmt(&str, f))
1316 impl fmt::Display for InternedString {
1317 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1318 self.with(|str| fmt::Display::fmt(&str, f))
1322 impl Decodable for InternedString {
1323 fn decode<D: Decoder>(d: &mut D) -> Result<InternedString, D::Error> {
1324 Ok(InternedString::intern(&d.read_str()?))
1328 impl Encodable for InternedString {
1329 fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
1330 self.with(|string| s.emit_str(string))