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,
234 default_lib_allocator,
235 default_type_parameter_fallback,
251 document_private_items,
252 dotdoteq_in_patterns,
253 dotdot_in_tuple_patterns,
254 double_braced_crate: "{{crate}}",
255 double_braced_impl: "{{impl}}",
256 double_braced_misc: "{{misc}}",
257 double_braced_closure: "{{closure}}",
258 double_braced_constructor: "{{constructor}}",
259 double_braced_constant: "{{constant}}",
260 double_braced_opaque: "{{opaque}}",
262 dropck_parametricity,
277 exclusive_range_pattern,
278 exhaustive_integer_patterns,
284 extern_absolute_paths,
286 extern_crate_item_prelude,
297 field_init_shorthand,
320 generic_associated_types,
329 hexagon_target_feature,
331 homogeneous_aggregate,
345 if_while_or_patterns,
347 impl_header_lifetime_elision,
349 impl_trait_in_bindings,
357 inclusive_range_syntax,
358 infer_outlives_requirements,
359 infer_static_outlives_requirements,
366 irrefutable_let_patterns,
369 issue_5723_bootstrap,
370 issue_tracker_base_url,
390 link_llvm_intrinsics,
399 macro_at_most_once_rep,
402 macro_lifetime_matcher,
403 macro_literal_matcher,
414 match_beginning_vert,
415 match_default_bindings,
428 movbe_target_feature,
462 omit_gdb_pretty_printer_section,
469 optin_builtin_traits,
479 overlapping_marker_traits,
484 panic_implementation,
504 poll_with_tls_context,
505 powerpc_target_feature,
506 precise_pointer_size_matching,
510 proc_dash_macro: "proc-macro",
512 proc_macro_attribute,
518 proc_macro_internals,
520 proc_macro_non_items,
521 proc_macro_path_invoc,
525 quad_precision_float,
538 reexport_test_harness_main,
548 re_rebalance_coherence,
564 rustc_allocator_nounwind,
565 rustc_allow_const_fn_ptr,
566 rustc_args_required_const,
570 rustc_const_unstable,
571 rustc_conversion_suggestion,
574 rustc_diagnostic_item,
575 rustc_diagnostic_macros,
578 rustc_dump_env_program_clauses,
579 rustc_dump_program_clauses,
580 rustc_dump_user_substs,
582 rustc_expected_cgu_reuse,
583 rustc_if_this_changed,
584 rustc_inherit_overflow_checks,
586 rustc_layout_scalar_valid_range_end,
587 rustc_layout_scalar_valid_range_start,
588 rustc_macro_transparency,
590 rustc_nonnull_optimization_guaranteed,
591 rustc_object_lifetime_default,
592 rustc_on_unimplemented,
595 rustc_partition_codegened,
596 rustc_partition_reused,
598 rustc_peek_definite_init,
599 rustc_peek_maybe_init,
600 rustc_peek_maybe_uninit,
602 rustc_proc_macro_decls,
606 rustc_std_internal_symbol,
610 rustc_then_this_would_need,
615 rust_eh_unwind_resume,
617 rvalue_static_promotion,
634 sse4a_target_feature,
647 stmt_expr_attributes,
649 struct_field_attributes,
661 termination_trait_test,
664 test_accepted_feature,
666 test_removed_feature,
686 type_alias_impl_trait,
689 type_alias_enum_variants,
699 underscore_const_names,
701 underscore_lifetimes,
704 universal_impl_trait,
707 unrestricted_attribute_tokens,
710 unsized_tuple_coercion,
725 visible_private_types,
728 warn_directory_ownership,
739 #[derive(Copy, Clone, Eq)]
747 /// Constructs a new identifier from a symbol and a span.
748 pub const fn new(name: Symbol, span: Span) -> Ident {
752 /// Constructs a new identifier with a dummy span.
754 pub const fn with_dummy_span(name: Symbol) -> Ident {
755 Ident::new(name, DUMMY_SP)
759 pub fn invalid() -> Ident {
760 Ident::with_dummy_span(kw::Invalid)
763 /// Maps an interned string to an identifier with an empty syntax context.
764 pub fn from_interned_str(string: InternedString) -> Ident {
765 Ident::with_dummy_span(string.as_symbol())
768 /// Maps a string to an identifier with a dummy span.
769 pub fn from_str(string: &str) -> Ident {
770 Ident::with_dummy_span(Symbol::intern(string))
773 /// Maps a string and a span to an identifier.
774 pub fn from_str_and_span(string: &str, span: Span) -> Ident {
775 Ident::new(Symbol::intern(string), span)
778 /// Replaces `lo` and `hi` with those from `span`, but keep hygiene context.
779 pub fn with_span_pos(self, span: Span) -> Ident {
780 Ident::new(self.name, span.with_ctxt(self.span.ctxt()))
783 pub fn without_first_quote(self) -> Ident {
784 Ident::new(Symbol::intern(self.as_str().trim_start_matches('\'')), self.span)
787 /// "Normalize" ident for use in comparisons using "item hygiene".
788 /// Identifiers with same string value become same if they came from the same "modern" macro
789 /// (e.g., `macro` item, but not `macro_rules` item) and stay different if they came from
790 /// different "modern" macros.
791 /// Technically, this operation strips all non-opaque marks from ident's syntactic context.
792 pub fn modern(self) -> Ident {
793 Ident::new(self.name, self.span.modern())
796 /// "Normalize" ident for use in comparisons using "local variable hygiene".
797 /// Identifiers with same string value become same if they came from the same non-transparent
798 /// macro (e.g., `macro` or `macro_rules!` items) and stay different if they came from different
799 /// non-transparent macros.
800 /// Technically, this operation strips all transparent marks from ident's syntactic context.
801 pub fn modern_and_legacy(self) -> Ident {
802 Ident::new(self.name, self.span.modern_and_legacy())
805 /// Transforms an underscore identifier into one with the same name, but
806 /// gensymed. Leaves non-underscore identifiers unchanged.
807 pub fn gensym_if_underscore(self) -> Ident {
808 if self.name == kw::Underscore {
809 let name = with_interner(|interner| interner.gensymed(self.name));
810 Ident::new(name, self.span)
816 /// Convert the name to a `LocalInternedString`. This is a slowish
817 /// operation because it requires locking the symbol interner.
818 pub fn as_str(self) -> LocalInternedString {
822 /// Convert the name to an `InternedString`. This is a slowish operation
823 /// because it requires locking the symbol interner.
824 pub fn as_interned_str(self) -> InternedString {
825 self.name.as_interned_str()
829 impl PartialEq for Ident {
830 fn eq(&self, rhs: &Self) -> bool {
831 self.name == rhs.name && self.span.ctxt() == rhs.span.ctxt()
835 impl Hash for Ident {
836 fn hash<H: Hasher>(&self, state: &mut H) {
837 self.name.hash(state);
838 self.span.ctxt().hash(state);
842 impl fmt::Debug for Ident {
843 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
844 write!(f, "{}{:?}", self.name, self.span.ctxt())
848 impl fmt::Display for Ident {
849 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
850 fmt::Display::fmt(&self.name, f)
854 impl UseSpecializedEncodable for Ident {
855 fn default_encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
856 s.emit_struct("Ident", 2, |s| {
857 s.emit_struct_field("name", 0, |s| {
860 s.emit_struct_field("span", 1, |s| {
867 impl UseSpecializedDecodable for Ident {
868 fn default_decode<D: Decoder>(d: &mut D) -> Result<Self, D::Error> {
869 d.read_struct("Ident", 2, |d| {
871 name: d.read_struct_field("name", 0, Decodable::decode)?,
872 span: d.read_struct_field("span", 1, Decodable::decode)?,
878 /// A symbol is an interned or gensymed string. A gensym is a symbol that is
879 /// never equal to any other symbol.
881 /// Conceptually, a gensym can be thought of as a normal symbol with an
882 /// invisible unique suffix. Gensyms are useful when creating new identifiers
883 /// that must not match any existing identifiers, e.g. during macro expansion
884 /// and syntax desugaring. Because gensyms should always be identifiers, all
885 /// gensym operations are on `Ident` rather than `Symbol`. (Indeed, in the
886 /// future the gensym-ness may be moved from `Symbol` to hygiene data.)
890 /// assert_eq!(Ident::from_str("_"), Ident::from_str("_"))
891 /// assert_ne!(Ident::from_str("_").gensym_if_underscore(), Ident::from_str("_"))
893 /// Ident::from_str("_").gensym_if_underscore(),
894 /// Ident::from_str("_").gensym_if_underscore(),
897 /// Internally, a symbol is implemented as an index, and all operations
898 /// (including hashing, equality, and ordering) operate on that index. The use
899 /// of `newtype_index!` means that `Option<Symbol>` only takes up 4 bytes,
900 /// because `newtype_index!` reserves the last 256 values for tagging purposes.
902 /// Note that `Symbol` cannot directly be a `newtype_index!` because it
903 /// implements `fmt::Debug`, `Encodable`, and `Decodable` in special ways.
904 #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
905 pub struct Symbol(SymbolIndex);
908 pub struct SymbolIndex { .. }
912 const fn new(n: u32) -> Self {
913 Symbol(SymbolIndex::from_u32_const(n))
916 /// Maps a string to its interned representation.
917 pub fn intern(string: &str) -> Self {
918 with_interner(|interner| interner.intern(string))
921 /// Access the symbol's chars. This is a slowish operation because it
922 /// requires locking the symbol interner.
923 pub fn with<F: FnOnce(&str) -> R, R>(self, f: F) -> R {
924 with_interner(|interner| {
925 f(interner.get(self))
929 /// Access two symbols' chars. This is a slowish operation because it
930 /// requires locking the symbol interner, but it is faster than calling
932 fn with2<F: FnOnce(&str, &str) -> R, R>(self, other: Symbol, f: F) -> R {
933 with_interner(|interner| {
934 f(interner.get(self), interner.get(other))
938 /// Convert to a `LocalInternedString`. This is a slowish operation because
939 /// it requires locking the symbol interner.
940 pub fn as_str(self) -> LocalInternedString {
941 with_interner(|interner| unsafe {
942 LocalInternedString {
943 string: std::mem::transmute::<&str, &str>(interner.get(self))
948 /// Convert to an `InternedString`. This is a slowish operation because it
949 /// requires locking the symbol interner.
950 pub fn as_interned_str(self) -> InternedString {
951 with_interner(|interner| InternedString {
952 symbol: interner.interned(self)
956 pub fn as_u32(self) -> u32 {
961 impl fmt::Debug for Symbol {
962 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
963 let is_gensymed = with_interner(|interner| interner.is_gensymed(*self));
965 write!(f, "{}({:?})", self, self.0)
967 write!(f, "{}", self)
972 impl fmt::Display for Symbol {
973 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
974 fmt::Display::fmt(&self.as_str(), f)
978 impl Encodable for Symbol {
979 fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
980 s.emit_str(&self.as_str())
984 impl Decodable for Symbol {
985 fn decode<D: Decoder>(d: &mut D) -> Result<Symbol, D::Error> {
986 Ok(Symbol::intern(&d.read_str()?))
990 // The `&'static str`s in this type actually point into the arena.
992 // Note that normal symbols are indexed upward from 0, and gensyms are indexed
993 // downward from SymbolIndex::MAX_AS_U32.
995 pub struct Interner {
996 arena: DroplessArena,
997 names: FxHashMap<&'static str, Symbol>,
998 strings: Vec<&'static str>,
999 gensyms: Vec<Symbol>,
1003 fn prefill(init: &[&'static str]) -> Self {
1005 strings: init.into(),
1006 names: init.iter().copied().zip((0..).map(Symbol::new)).collect(),
1007 ..Default::default()
1011 pub fn intern(&mut self, string: &str) -> Symbol {
1012 if let Some(&name) = self.names.get(string) {
1016 let name = Symbol::new(self.strings.len() as u32);
1018 // `from_utf8_unchecked` is safe since we just allocated a `&str` which is known to be
1020 let string: &str = unsafe {
1021 str::from_utf8_unchecked(self.arena.alloc_slice(string.as_bytes()))
1023 // It is safe to extend the arena allocation to `'static` because we only access
1024 // these while the arena is still alive.
1025 let string: &'static str = unsafe {
1026 &*(string as *const str)
1028 self.strings.push(string);
1029 self.names.insert(string, name);
1033 fn interned(&self, symbol: Symbol) -> Symbol {
1034 if (symbol.0.as_usize()) < self.strings.len() {
1037 self.gensyms[(SymbolIndex::MAX_AS_U32 - symbol.0.as_u32()) as usize]
1041 fn gensymed(&mut self, symbol: Symbol) -> Symbol {
1042 self.gensyms.push(symbol);
1043 Symbol::new(SymbolIndex::MAX_AS_U32 - self.gensyms.len() as u32 + 1)
1046 fn is_gensymed(&mut self, symbol: Symbol) -> bool {
1047 symbol.0.as_usize() >= self.strings.len()
1050 // Get the symbol as a string. `Symbol::as_str()` should be used in
1051 // preference to this function.
1052 pub fn get(&self, symbol: Symbol) -> &str {
1053 match self.strings.get(symbol.0.as_usize()) {
1054 Some(string) => string,
1056 let symbol = self.gensyms[(SymbolIndex::MAX_AS_U32 - symbol.0.as_u32()) as usize];
1057 self.strings[symbol.0.as_usize()]
1063 // This module has a very short name because it's used a lot.
1069 // This module has a very short name because it's used a lot.
1071 use std::convert::TryInto;
1076 // Get the symbol for an integer. The first few non-negative integers each
1077 // have a static symbol and therefore are fast.
1078 pub fn integer<N: TryInto<usize> + Copy + ToString>(n: N) -> Symbol {
1079 if let Result::Ok(idx) = n.try_into() {
1080 if let Option::Some(&sym) = digits_array.get(idx) {
1084 Symbol::intern(&n.to_string())
1089 fn is_used_keyword_2018(self) -> bool {
1093 fn is_unused_keyword_2018(self) -> bool {
1094 self >= kw::Async && self <= kw::Try
1097 /// Used for sanity checking rustdoc keyword sections.
1098 pub fn is_doc_keyword(self) -> bool {
1102 /// A keyword or reserved identifier that can be used as a path segment.
1103 pub fn is_path_segment_keyword(self) -> bool {
1104 self == kw::Super ||
1105 self == kw::SelfLower ||
1106 self == kw::SelfUpper ||
1107 self == kw::Crate ||
1108 self == kw::PathRoot ||
1109 self == kw::DollarCrate
1112 /// Returns `true` if the symbol is `true` or `false`.
1113 pub fn is_bool_lit(self) -> bool {
1114 self == kw::True || self == kw::False
1117 /// This symbol can be a raw identifier.
1118 pub fn can_be_raw(self) -> bool {
1119 self != kw::Invalid && self != kw::Underscore && !self.is_path_segment_keyword()
1124 // Returns `true` for reserved identifiers used internally for elided lifetimes,
1125 // unnamed method parameters, crate root module, error recovery etc.
1126 pub fn is_special(self) -> bool {
1127 self.name <= kw::Underscore
1130 /// Returns `true` if the token is a keyword used in the language.
1131 pub fn is_used_keyword(self) -> bool {
1132 // Note: `span.edition()` is relatively expensive, don't call it unless necessary.
1133 self.name >= kw::As && self.name <= kw::While ||
1134 self.name.is_used_keyword_2018() && self.span.rust_2018()
1137 /// Returns `true` if the token is a keyword reserved for possible future use.
1138 pub fn is_unused_keyword(self) -> bool {
1139 // Note: `span.edition()` is relatively expensive, don't call it unless necessary.
1140 self.name >= kw::Abstract && self.name <= kw::Yield ||
1141 self.name.is_unused_keyword_2018() && self.span.rust_2018()
1144 /// Returns `true` if the token is either a special identifier or a keyword.
1145 pub fn is_reserved(self) -> bool {
1146 self.is_special() || self.is_used_keyword() || self.is_unused_keyword()
1149 /// A keyword or reserved identifier that can be used as a path segment.
1150 pub fn is_path_segment_keyword(self) -> bool {
1151 self.name.is_path_segment_keyword()
1154 /// We see this identifier in a normal identifier position, like variable name or a type.
1155 /// How was it written originally? Did it use the raw form? Let's try to guess.
1156 pub fn is_raw_guess(self) -> bool {
1157 self.name.can_be_raw() && self.is_reserved()
1161 // If an interner exists, return it. Otherwise, prepare a fresh one.
1163 fn with_interner<T, F: FnOnce(&mut Interner) -> T>(f: F) -> T {
1164 GLOBALS.with(|globals| f(&mut *globals.symbol_interner.lock()))
1167 /// An alternative to `Symbol` and `InternedString`, useful when the chars
1168 /// within the symbol need to be accessed. It is best used for temporary
1171 /// Because the interner outlives any thread which uses this type, we can
1172 /// safely treat `string` which points to interner data, as an immortal string,
1173 /// as long as this type never crosses between threads.
1175 // FIXME: ensure that the interner outlives any thread which uses
1176 // `LocalInternedString`, by creating a new thread right after constructing the
1178 #[derive(Clone, Copy, Eq, PartialOrd, Ord)]
1179 pub struct LocalInternedString {
1180 string: &'static str,
1183 impl<U: ?Sized> std::convert::AsRef<U> for LocalInternedString
1185 str: std::convert::AsRef<U>
1188 fn as_ref(&self) -> &U {
1189 self.string.as_ref()
1193 impl<T: std::ops::Deref<Target = str>> std::cmp::PartialEq<T> for LocalInternedString {
1194 fn eq(&self, other: &T) -> bool {
1195 self.string == other.deref()
1199 impl std::cmp::PartialEq<LocalInternedString> for str {
1200 fn eq(&self, other: &LocalInternedString) -> bool {
1201 self == other.string
1205 impl<'a> std::cmp::PartialEq<LocalInternedString> for &'a str {
1206 fn eq(&self, other: &LocalInternedString) -> bool {
1207 *self == other.string
1211 impl std::cmp::PartialEq<LocalInternedString> for String {
1212 fn eq(&self, other: &LocalInternedString) -> bool {
1213 self == other.string
1217 impl<'a> std::cmp::PartialEq<LocalInternedString> for &'a String {
1218 fn eq(&self, other: &LocalInternedString) -> bool {
1219 *self == other.string
1223 impl !Send for LocalInternedString {}
1224 impl !Sync for LocalInternedString {}
1226 impl std::ops::Deref for LocalInternedString {
1229 fn deref(&self) -> &str { self.string }
1232 impl fmt::Debug for LocalInternedString {
1233 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1234 fmt::Debug::fmt(self.string, f)
1238 impl fmt::Display for LocalInternedString {
1239 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1240 fmt::Display::fmt(self.string, f)
1244 /// An alternative to `Symbol` that is focused on string contents. It has two
1245 /// main differences to `Symbol`.
1247 /// First, its implementations of `Hash`, `PartialOrd` and `Ord` work with the
1248 /// string chars rather than the symbol integer. This is useful when hash
1249 /// stability is required across compile sessions, or a guaranteed sort
1250 /// ordering is required.
1252 /// Second, gensym-ness is irrelevant. E.g.:
1254 /// assert_ne!(Symbol::gensym("x"), Symbol::gensym("x"))
1255 /// assert_eq!(Symbol::gensym("x").as_interned_str(), Symbol::gensym("x").as_interned_str())
1257 #[derive(Clone, Copy, PartialEq, Eq)]
1258 pub struct InternedString {
1262 impl InternedString {
1263 /// Maps a string to its interned representation.
1264 pub fn intern(string: &str) -> Self {
1266 symbol: Symbol::intern(string)
1270 pub fn with<F: FnOnce(&str) -> R, R>(self, f: F) -> R {
1274 fn with2<F: FnOnce(&str, &str) -> R, R>(self, other: &InternedString, f: F) -> R {
1275 self.symbol.with2(other.symbol, f)
1278 pub fn as_symbol(self) -> Symbol {
1282 /// Convert to a `LocalInternedString`. This is a slowish operation because it
1283 /// requires locking the symbol interner.
1284 pub fn as_str(self) -> LocalInternedString {
1285 self.symbol.as_str()
1289 impl Hash for InternedString {
1290 fn hash<H: Hasher>(&self, state: &mut H) {
1291 self.with(|str| str.hash(state))
1295 impl PartialOrd<InternedString> for InternedString {
1296 fn partial_cmp(&self, other: &InternedString) -> Option<Ordering> {
1297 if self.symbol == other.symbol {
1298 return Some(Ordering::Equal);
1300 self.with2(other, |self_str, other_str| self_str.partial_cmp(other_str))
1304 impl Ord for InternedString {
1305 fn cmp(&self, other: &InternedString) -> Ordering {
1306 if self.symbol == other.symbol {
1307 return Ordering::Equal;
1309 self.with2(other, |self_str, other_str| self_str.cmp(other_str))
1313 impl fmt::Debug for InternedString {
1314 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1315 self.with(|str| fmt::Debug::fmt(&str, f))
1319 impl fmt::Display for InternedString {
1320 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1321 self.with(|str| fmt::Display::fmt(&str, f))
1325 impl Decodable for InternedString {
1326 fn decode<D: Decoder>(d: &mut D) -> Result<InternedString, D::Error> {
1327 Ok(InternedString::intern(&d.read_str()?))
1331 impl Encodable for InternedString {
1332 fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
1333 self.with(|string| s.emit_str(string))