]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_utils/symbol_names.rs
Rollup merge of #61291 - spastorino:avoid-unneeded-bug-call, r=estebank
[rust.git] / src / librustc_codegen_utils / symbol_names.rs
1 //! The Rust Linkage Model and Symbol Names
2 //! =======================================
3 //!
4 //! The semantic model of Rust linkage is, broadly, that "there's no global
5 //! namespace" between crates. Our aim is to preserve the illusion of this
6 //! model despite the fact that it's not *quite* possible to implement on
7 //! modern linkers. We initially didn't use system linkers at all, but have
8 //! been convinced of their utility.
9 //!
10 //! There are a few issues to handle:
11 //!
12 //!  - Linkers operate on a flat namespace, so we have to flatten names.
13 //!    We do this using the C++ namespace-mangling technique. Foo::bar
14 //!    symbols and such.
15 //!
16 //!  - Symbols for distinct items with the same *name* need to get different
17 //!    linkage-names. Examples of this are monomorphizations of functions or
18 //!    items within anonymous scopes that end up having the same path.
19 //!
20 //!  - Symbols in different crates but with same names "within" the crate need
21 //!    to get different linkage-names.
22 //!
23 //!  - Symbol names should be deterministic: Two consecutive runs of the
24 //!    compiler over the same code base should produce the same symbol names for
25 //!    the same items.
26 //!
27 //!  - Symbol names should not depend on any global properties of the code base,
28 //!    so that small modifications to the code base do not result in all symbols
29 //!    changing. In previous versions of the compiler, symbol names incorporated
30 //!    the SVH (Stable Version Hash) of the crate. This scheme turned out to be
31 //!    infeasible when used in conjunction with incremental compilation because
32 //!    small code changes would invalidate all symbols generated previously.
33 //!
34 //!  - Even symbols from different versions of the same crate should be able to
35 //!    live next to each other without conflict.
36 //!
37 //! In order to fulfill the above requirements the following scheme is used by
38 //! the compiler:
39 //!
40 //! The main tool for avoiding naming conflicts is the incorporation of a 64-bit
41 //! hash value into every exported symbol name. Anything that makes a difference
42 //! to the symbol being named, but does not show up in the regular path needs to
43 //! be fed into this hash:
44 //!
45 //! - Different monomorphizations of the same item have the same path but differ
46 //!   in their concrete type parameters, so these parameters are part of the
47 //!   data being digested for the symbol hash.
48 //!
49 //! - Rust allows items to be defined in anonymous scopes, such as in
50 //!   `fn foo() { { fn bar() {} } { fn bar() {} } }`. Both `bar` functions have
51 //!   the path `foo::bar`, since the anonymous scopes do not contribute to the
52 //!   path of an item. The compiler already handles this case via so-called
53 //!   disambiguating `DefPaths` which use indices to distinguish items with the
54 //!   same name. The DefPaths of the functions above are thus `foo[0]::bar[0]`
55 //!   and `foo[0]::bar[1]`. In order to incorporate this disambiguation
56 //!   information into the symbol name too, these indices are fed into the
57 //!   symbol hash, so that the above two symbols would end up with different
58 //!   hash values.
59 //!
60 //! The two measures described above suffice to avoid intra-crate conflicts. In
61 //! order to also avoid inter-crate conflicts two more measures are taken:
62 //!
63 //! - The name of the crate containing the symbol is prepended to the symbol
64 //!   name, i.e., symbols are "crate qualified". For example, a function `foo` in
65 //!   module `bar` in crate `baz` would get a symbol name like
66 //!   `baz::bar::foo::{hash}` instead of just `bar::foo::{hash}`. This avoids
67 //!   simple conflicts between functions from different crates.
68 //!
69 //! - In order to be able to also use symbols from two versions of the same
70 //!   crate (which naturally also have the same name), a stronger measure is
71 //!   required: The compiler accepts an arbitrary "disambiguator" value via the
72 //!   `-C metadata` command-line argument. This disambiguator is then fed into
73 //!   the symbol hash of every exported item. Consequently, the symbols in two
74 //!   identical crates but with different disambiguators are not in conflict
75 //!   with each other. This facility is mainly intended to be used by build
76 //!   tools like Cargo.
77 //!
78 //! A note on symbol name stability
79 //! -------------------------------
80 //! Previous versions of the compiler resorted to feeding NodeIds into the
81 //! symbol hash in order to disambiguate between items with the same path. The
82 //! current version of the name generation algorithm takes great care not to do
83 //! that, since NodeIds are notoriously unstable: A small change to the
84 //! code base will offset all NodeIds after the change and thus, much as using
85 //! the SVH in the hash, invalidate an unbounded number of symbol names. This
86 //! makes re-using previously compiled code for incremental compilation
87 //! virtually impossible. Thus, symbol hash generation exclusively relies on
88 //! DefPaths which are much more robust in the face of changes to the code base.
89
90 use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
91 use rustc::hir::Node;
92 use rustc::hir::CodegenFnAttrFlags;
93 use rustc::hir::map::{DefPathData, DisambiguatedDefPathData};
94 use rustc::ich::NodeIdHashingMode;
95 use rustc::ty::print::{PrettyPrinter, Printer, Print};
96 use rustc::ty::query::Providers;
97 use rustc::ty::subst::{Kind, SubstsRef, UnpackedKind};
98 use rustc::ty::{self, Ty, TyCtxt, TypeFoldable};
99 use rustc::mir::interpret::{ConstValue, Scalar};
100 use rustc::util::common::record_time;
101 use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
102 use rustc_mir::monomorphize::item::{InstantiationMode, MonoItem, MonoItemExt};
103 use rustc_mir::monomorphize::Instance;
104
105 use syntax_pos::symbol::InternedString;
106
107 use log::debug;
108
109 use std::fmt::{self, Write};
110 use std::mem::{self, discriminant};
111
112 pub fn provide(providers: &mut Providers<'_>) {
113     *providers = Providers {
114         symbol_name,
115
116         ..*providers
117     };
118 }
119
120 fn get_symbol_hash<'a, 'tcx>(
121     tcx: TyCtxt<'a, 'tcx, 'tcx>,
122
123     // the DefId of the item this name is for
124     def_id: DefId,
125
126     // instance this name will be for
127     instance: Instance<'tcx>,
128
129     // type of the item, without any generic
130     // parameters substituted; this is
131     // included in the hash as a kind of
132     // safeguard.
133     item_type: Ty<'tcx>,
134
135     // values for generic type parameters,
136     // if any.
137     substs: SubstsRef<'tcx>,
138 ) -> u64 {
139     debug!(
140         "get_symbol_hash(def_id={:?}, parameters={:?})",
141         def_id, substs
142     );
143
144     let mut hasher = StableHasher::<u64>::new();
145     let mut hcx = tcx.create_stable_hashing_context();
146
147     record_time(&tcx.sess.perf_stats.symbol_hash_time, || {
148         // the main symbol name is not necessarily unique; hash in the
149         // compiler's internal def-path, guaranteeing each symbol has a
150         // truly unique path
151         tcx.def_path_hash(def_id).hash_stable(&mut hcx, &mut hasher);
152
153         // Include the main item-type. Note that, in this case, the
154         // assertions about `needs_subst` may not hold, but this item-type
155         // ought to be the same for every reference anyway.
156         assert!(!item_type.has_erasable_regions());
157         hcx.while_hashing_spans(false, |hcx| {
158             hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
159                 item_type.hash_stable(hcx, &mut hasher);
160             });
161         });
162
163         // If this is a function, we hash the signature as well.
164         // This is not *strictly* needed, but it may help in some
165         // situations, see the `run-make/a-b-a-linker-guard` test.
166         if let ty::FnDef(..) = item_type.sty {
167             item_type.fn_sig(tcx).hash_stable(&mut hcx, &mut hasher);
168         }
169
170         // also include any type parameters (for generic items)
171         assert!(!substs.has_erasable_regions());
172         assert!(!substs.needs_subst());
173         substs.hash_stable(&mut hcx, &mut hasher);
174
175         let is_generic = substs.non_erasable_generics().next().is_some();
176         let avoid_cross_crate_conflicts =
177             // If this is an instance of a generic function, we also hash in
178             // the ID of the instantiating crate. This avoids symbol conflicts
179             // in case the same instances is emitted in two crates of the same
180             // project.
181             is_generic ||
182
183             // If we're dealing with an instance of a function that's inlined from
184             // another crate but we're marking it as globally shared to our
185             // compliation (aka we're not making an internal copy in each of our
186             // codegen units) then this symbol may become an exported (but hidden
187             // visibility) symbol. This means that multiple crates may do the same
188             // and we want to be sure to avoid any symbol conflicts here.
189             match MonoItem::Fn(instance).instantiation_mode(tcx) {
190                 InstantiationMode::GloballyShared { may_conflict: true } => true,
191                 _ => false,
192             };
193
194         if avoid_cross_crate_conflicts {
195             let instantiating_crate = if is_generic {
196                 if !def_id.is_local() && tcx.sess.opts.share_generics() {
197                     // If we are re-using a monomorphization from another crate,
198                     // we have to compute the symbol hash accordingly.
199                     let upstream_monomorphizations = tcx.upstream_monomorphizations_for(def_id);
200
201                     upstream_monomorphizations
202                         .and_then(|monos| monos.get(&substs).cloned())
203                         .unwrap_or(LOCAL_CRATE)
204                 } else {
205                     LOCAL_CRATE
206                 }
207             } else {
208                 LOCAL_CRATE
209             };
210
211             (&tcx.original_crate_name(instantiating_crate).as_str()[..])
212                 .hash_stable(&mut hcx, &mut hasher);
213             (&tcx.crate_disambiguator(instantiating_crate)).hash_stable(&mut hcx, &mut hasher);
214         }
215
216         // We want to avoid accidental collision between different types of instances.
217         // Especially, VtableShim may overlap with its original instance without this.
218         discriminant(&instance.def).hash_stable(&mut hcx, &mut hasher);
219     });
220
221     // 64 bits should be enough to avoid collisions.
222     hasher.finish()
223 }
224
225 fn symbol_name(tcx: TyCtxt<'_, 'tcx, 'tcx>, instance: Instance<'tcx>) -> ty::SymbolName {
226     ty::SymbolName {
227         name: compute_symbol_name(tcx, instance),
228     }
229 }
230
231 fn compute_symbol_name(tcx: TyCtxt<'_, 'tcx, 'tcx>, instance: Instance<'tcx>) -> InternedString {
232     let def_id = instance.def_id();
233     let substs = instance.substs;
234
235     debug!("symbol_name(def_id={:?}, substs={:?})", def_id, substs);
236
237     let hir_id = tcx.hir().as_local_hir_id(def_id);
238
239     if def_id.is_local() {
240         if tcx.plugin_registrar_fn(LOCAL_CRATE) == Some(def_id) {
241             let disambiguator = tcx.sess.local_crate_disambiguator();
242             return
243                 InternedString::intern(&tcx.sess.generate_plugin_registrar_symbol(disambiguator));
244         }
245         if tcx.proc_macro_decls_static(LOCAL_CRATE) == Some(def_id) {
246             let disambiguator = tcx.sess.local_crate_disambiguator();
247             return
248                 InternedString::intern(&tcx.sess.generate_proc_macro_decls_symbol(disambiguator));
249         }
250     }
251
252     // FIXME(eddyb) Precompute a custom symbol name based on attributes.
253     let is_foreign = if let Some(id) = hir_id {
254         match tcx.hir().get_by_hir_id(id) {
255             Node::ForeignItem(_) => true,
256             _ => false,
257         }
258     } else {
259         tcx.is_foreign_item(def_id)
260     };
261
262     let attrs = tcx.codegen_fn_attrs(def_id);
263     if is_foreign {
264         if let Some(name) = attrs.link_name {
265             return name.as_interned_str();
266         }
267         // Don't mangle foreign items.
268         return tcx.item_name(def_id).as_interned_str();
269     }
270
271     if let Some(name) = &attrs.export_name {
272         // Use provided name
273         return name.as_interned_str();
274     }
275
276     if attrs.flags.contains(CodegenFnAttrFlags::NO_MANGLE) {
277         // Don't mangle
278         return tcx.item_name(def_id).as_interned_str();
279     }
280
281     // We want to compute the "type" of this item. Unfortunately, some
282     // kinds of items (e.g., closures) don't have an entry in the
283     // item-type array. So walk back up the find the closest parent
284     // that DOES have an entry.
285     let mut ty_def_id = def_id;
286     let instance_ty;
287     loop {
288         let key = tcx.def_key(ty_def_id);
289         match key.disambiguated_data.data {
290             DefPathData::TypeNs(_) | DefPathData::ValueNs(_) => {
291                 instance_ty = tcx.type_of(ty_def_id);
292                 break;
293             }
294             _ => {
295                 // if we're making a symbol for something, there ought
296                 // to be a value or type-def or something in there
297                 // *somewhere*
298                 ty_def_id.index = key.parent.unwrap_or_else(|| {
299                     bug!(
300                         "finding type for {:?}, encountered def-id {:?} with no \
301                          parent",
302                         def_id,
303                         ty_def_id
304                     );
305                 });
306             }
307         }
308     }
309
310     // Erase regions because they may not be deterministic when hashed
311     // and should not matter anyhow.
312     let instance_ty = tcx.erase_regions(&instance_ty);
313
314     let hash = get_symbol_hash(tcx, def_id, instance, instance_ty, substs);
315
316     let mut printer = SymbolPrinter {
317         tcx,
318         path: SymbolPath::new(),
319         keep_within_component: false,
320     }.print_def_path(def_id, &[]).unwrap();
321
322     if instance.is_vtable_shim() {
323         let _ = printer.write_str("{{vtable-shim}}");
324     }
325
326     InternedString::intern(&printer.path.finish(hash))
327 }
328
329 // Follow C++ namespace-mangling style, see
330 // http://en.wikipedia.org/wiki/Name_mangling for more info.
331 //
332 // It turns out that on macOS you can actually have arbitrary symbols in
333 // function names (at least when given to LLVM), but this is not possible
334 // when using unix's linker. Perhaps one day when we just use a linker from LLVM
335 // we won't need to do this name mangling. The problem with name mangling is
336 // that it seriously limits the available characters. For example we can't
337 // have things like &T in symbol names when one would theoretically
338 // want them for things like impls of traits on that type.
339 //
340 // To be able to work on all platforms and get *some* reasonable output, we
341 // use C++ name-mangling.
342 #[derive(Debug)]
343 struct SymbolPath {
344     result: String,
345     temp_buf: String,
346 }
347
348 impl SymbolPath {
349     fn new() -> Self {
350         let mut result = SymbolPath {
351             result: String::with_capacity(64),
352             temp_buf: String::with_capacity(16),
353         };
354         result.result.push_str("_ZN"); // _Z == Begin name-sequence, N == nested
355         result
356     }
357
358     fn finalize_pending_component(&mut self) {
359         if !self.temp_buf.is_empty() {
360             let _ = write!(self.result, "{}{}", self.temp_buf.len(), self.temp_buf);
361             self.temp_buf.clear();
362         }
363     }
364
365     fn finish(mut self, hash: u64) -> String {
366         self.finalize_pending_component();
367         // E = end name-sequence
368         let _ = write!(self.result, "17h{:016x}E", hash);
369         self.result
370     }
371 }
372
373 struct SymbolPrinter<'a, 'tcx> {
374     tcx: TyCtxt<'a, 'tcx, 'tcx>,
375     path: SymbolPath,
376
377     // When `true`, `finalize_pending_component` isn't used.
378     // This is needed when recursing into `path_qualified`,
379     // or `path_generic_args`, as any nested paths are
380     // logically within one component.
381     keep_within_component: bool,
382 }
383
384 // HACK(eddyb) this relies on using the `fmt` interface to get
385 // `PrettyPrinter` aka pretty printing of e.g. types in paths,
386 // symbol names should have their own printing machinery.
387
388 impl Printer<'tcx, 'tcx> for SymbolPrinter<'_, 'tcx> {
389     type Error = fmt::Error;
390
391     type Path = Self;
392     type Region = Self;
393     type Type = Self;
394     type DynExistential = Self;
395     type Const = Self;
396
397     fn tcx(&'a self) -> TyCtxt<'a, 'tcx, 'tcx> {
398         self.tcx
399     }
400
401     fn print_region(
402         self,
403         _region: ty::Region<'_>,
404     ) -> Result<Self::Region, Self::Error> {
405         Ok(self)
406     }
407
408     fn print_type(
409         self,
410         ty: Ty<'tcx>,
411     ) -> Result<Self::Type, Self::Error> {
412         match ty.sty {
413             // Print all nominal types as paths (unlike `pretty_print_type`).
414             ty::FnDef(def_id, substs) |
415             ty::Opaque(def_id, substs) |
416             ty::Projection(ty::ProjectionTy { item_def_id: def_id, substs }) |
417             ty::UnnormalizedProjection(ty::ProjectionTy { item_def_id: def_id, substs }) |
418             ty::Closure(def_id, ty::ClosureSubsts { substs }) |
419             ty::Generator(def_id, ty::GeneratorSubsts { substs }, _) => {
420                 self.print_def_path(def_id, substs)
421             }
422             _ => self.pretty_print_type(ty),
423         }
424     }
425
426     fn print_dyn_existential(
427         mut self,
428         predicates: &'tcx ty::List<ty::ExistentialPredicate<'tcx>>,
429     ) -> Result<Self::DynExistential, Self::Error> {
430         let mut first = false;
431         for p in predicates {
432             if !first {
433                 write!(self, "+")?;
434             }
435             first = false;
436             self = p.print(self)?;
437         }
438         Ok(self)
439     }
440
441     fn print_const(
442         mut self,
443         ct: &'tcx ty::Const<'tcx>,
444     ) -> Result<Self::Const, Self::Error> {
445         // only print integers
446         if let ConstValue::Scalar(Scalar::Raw { .. }) = ct.val {
447             if ct.ty.is_integral() {
448                 return self.pretty_print_const(ct);
449             }
450         }
451         self.write_str("_")?;
452         Ok(self)
453     }
454
455     fn path_crate(
456         mut self,
457         cnum: CrateNum,
458     ) -> Result<Self::Path, Self::Error> {
459         self.write_str(&self.tcx.original_crate_name(cnum).as_str())?;
460         Ok(self)
461     }
462     fn path_qualified(
463         self,
464         self_ty: Ty<'tcx>,
465         trait_ref: Option<ty::TraitRef<'tcx>>,
466     ) -> Result<Self::Path, Self::Error> {
467         // Similar to `pretty_path_qualified`, but for the other
468         // types that are printed as paths (see `print_type` above).
469         match self_ty.sty {
470             ty::FnDef(..) |
471             ty::Opaque(..) |
472             ty::Projection(_) |
473             ty::UnnormalizedProjection(_) |
474             ty::Closure(..) |
475             ty::Generator(..)
476                 if trait_ref.is_none() =>
477             {
478                 self.print_type(self_ty)
479             }
480
481             _ => self.pretty_path_qualified(self_ty, trait_ref)
482         }
483     }
484
485     fn path_append_impl(
486         self,
487         print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
488         _disambiguated_data: &DisambiguatedDefPathData,
489         self_ty: Ty<'tcx>,
490         trait_ref: Option<ty::TraitRef<'tcx>>,
491     ) -> Result<Self::Path, Self::Error> {
492         self.pretty_path_append_impl(
493             |mut cx| {
494                 cx = print_prefix(cx)?;
495
496                 if cx.keep_within_component {
497                     // HACK(eddyb) print the path similarly to how `FmtPrinter` prints it.
498                     cx.write_str("::")?;
499                 } else {
500                     cx.path.finalize_pending_component();
501                 }
502
503                 Ok(cx)
504             },
505             self_ty,
506             trait_ref,
507         )
508     }
509     fn path_append(
510         mut self,
511         print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
512         disambiguated_data: &DisambiguatedDefPathData,
513     ) -> Result<Self::Path, Self::Error> {
514         self = print_prefix(self)?;
515
516         // Skip `::{{constructor}}` on tuple/unit structs.
517         match disambiguated_data.data {
518             DefPathData::Ctor => return Ok(self),
519             _ => {}
520         }
521
522         if self.keep_within_component {
523             // HACK(eddyb) print the path similarly to how `FmtPrinter` prints it.
524             self.write_str("::")?;
525         } else {
526             self.path.finalize_pending_component();
527         }
528
529         self.write_str(&disambiguated_data.data.as_interned_str().as_str())?;
530         Ok(self)
531     }
532     fn path_generic_args(
533         mut self,
534         print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
535         args: &[Kind<'tcx>],
536     )  -> Result<Self::Path, Self::Error> {
537         self = print_prefix(self)?;
538
539         let args = args.iter().cloned().filter(|arg| {
540             match arg.unpack() {
541                 UnpackedKind::Lifetime(_) => false,
542                 _ => true,
543             }
544         });
545
546         if args.clone().next().is_some() {
547             self.generic_delimiters(|cx| cx.comma_sep(args))
548         } else {
549             Ok(self)
550         }
551     }
552 }
553
554 impl PrettyPrinter<'tcx, 'tcx> for SymbolPrinter<'_, 'tcx> {
555     fn region_should_not_be_omitted(
556         &self,
557         _region: ty::Region<'_>,
558     ) -> bool {
559         false
560     }
561     fn comma_sep<T>(
562         mut self,
563         mut elems: impl Iterator<Item = T>,
564     ) -> Result<Self, Self::Error>
565         where T: Print<'tcx, 'tcx, Self, Output = Self, Error = Self::Error>
566     {
567         if let Some(first) = elems.next() {
568             self = first.print(self)?;
569             for elem in elems {
570                 self.write_str(",")?;
571                 self = elem.print(self)?;
572             }
573         }
574         Ok(self)
575     }
576
577     fn generic_delimiters(
578         mut self,
579         f: impl FnOnce(Self) -> Result<Self, Self::Error>,
580     ) -> Result<Self, Self::Error> {
581         write!(self, "<")?;
582
583         let kept_within_component =
584             mem::replace(&mut self.keep_within_component, true);
585         self = f(self)?;
586         self.keep_within_component = kept_within_component;
587
588         write!(self, ">")?;
589
590         Ok(self)
591     }
592 }
593
594 impl fmt::Write for SymbolPrinter<'_, '_> {
595     fn write_str(&mut self, s: &str) -> fmt::Result {
596         // Name sanitation. LLVM will happily accept identifiers with weird names, but
597         // gas doesn't!
598         // gas accepts the following characters in symbols: a-z, A-Z, 0-9, ., _, $
599         // NVPTX assembly has more strict naming rules than gas, so additionally, dots
600         // are replaced with '$' there.
601
602         for c in s.chars() {
603             if self.path.temp_buf.is_empty() {
604                 match c {
605                     'a'..='z' | 'A'..='Z' | '_' => {}
606                     _ => {
607                         // Underscore-qualify anything that didn't start as an ident.
608                         self.path.temp_buf.push('_');
609                     }
610                 }
611             }
612             match c {
613                 // Escape these with $ sequences
614                 '@' => self.path.temp_buf.push_str("$SP$"),
615                 '*' => self.path.temp_buf.push_str("$BP$"),
616                 '&' => self.path.temp_buf.push_str("$RF$"),
617                 '<' => self.path.temp_buf.push_str("$LT$"),
618                 '>' => self.path.temp_buf.push_str("$GT$"),
619                 '(' => self.path.temp_buf.push_str("$LP$"),
620                 ')' => self.path.temp_buf.push_str("$RP$"),
621                 ',' => self.path.temp_buf.push_str("$C$"),
622
623                 '-' | ':' | '.' if self.tcx.has_strict_asm_symbol_naming() => {
624                     // NVPTX doesn't support these characters in symbol names.
625                     self.path.temp_buf.push('$')
626                 }
627
628                 // '.' doesn't occur in types and functions, so reuse it
629                 // for ':' and '-'
630                 '-' | ':' => self.path.temp_buf.push('.'),
631
632                 // Avoid segmentation fault on some platforms, see #60925.
633                 'm' if self.path.temp_buf.ends_with(".llv") => self.path.temp_buf.push_str("$6d$"),
634
635                 // These are legal symbols
636                 'a'..='z' | 'A'..='Z' | '0'..='9' | '_' | '.' | '$' => self.path.temp_buf.push(c),
637
638                 _ => {
639                     self.path.temp_buf.push('$');
640                     for c in c.escape_unicode().skip(1) {
641                         match c {
642                             '{' => {}
643                             '}' => self.path.temp_buf.push('$'),
644                             c => self.path.temp_buf.push(c),
645                         }
646                     }
647                 }
648             }
649         }
650
651         Ok(())
652     }
653 }