]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_utils/symbol_names.rs
ebd48f0ae1e2b751a3fa63f9eb9a37fbaca47efb
[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::util::common::record_time;
100 use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
101 use rustc_mir::monomorphize::item::{InstantiationMode, MonoItem, MonoItemExt};
102 use rustc_mir::monomorphize::Instance;
103
104 use syntax_pos::symbol::Symbol;
105
106 use log::debug;
107
108 use std::fmt::{self, Write};
109 use std::mem::{self, discriminant};
110
111 pub fn provide(providers: &mut Providers<'_>) {
112     *providers = Providers {
113         def_symbol_name,
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 def_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> ty::SymbolName {
226     SymbolPrinter {
227         tcx,
228         path: SymbolPath::new(),
229         keep_within_component: false,
230     }.print_def_path(def_id, &[]).unwrap().path.into_interned()
231 }
232
233 fn symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance<'tcx>) -> ty::SymbolName {
234     ty::SymbolName {
235         name: Symbol::intern(&compute_symbol_name(tcx, instance)).as_interned_str(),
236     }
237 }
238
239 fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance<'tcx>) -> String {
240     let def_id = instance.def_id();
241     let substs = instance.substs;
242
243     debug!("symbol_name(def_id={:?}, substs={:?})", def_id, substs);
244
245     let hir_id = tcx.hir().as_local_hir_id(def_id);
246
247     if def_id.is_local() {
248         if tcx.plugin_registrar_fn(LOCAL_CRATE) == Some(def_id) {
249             let disambiguator = tcx.sess.local_crate_disambiguator();
250             return tcx.sess.generate_plugin_registrar_symbol(disambiguator);
251         }
252         if tcx.proc_macro_decls_static(LOCAL_CRATE) == Some(def_id) {
253             let disambiguator = tcx.sess.local_crate_disambiguator();
254             return tcx.sess.generate_proc_macro_decls_symbol(disambiguator);
255         }
256     }
257
258     // FIXME(eddyb) Precompute a custom symbol name based on attributes.
259     let is_foreign = if let Some(id) = hir_id {
260         match tcx.hir().get_by_hir_id(id) {
261             Node::ForeignItem(_) => true,
262             _ => false,
263         }
264     } else {
265         tcx.is_foreign_item(def_id)
266     };
267
268     let attrs = tcx.codegen_fn_attrs(def_id);
269     if is_foreign {
270         if let Some(name) = attrs.link_name {
271             return name.to_string();
272         }
273         // Don't mangle foreign items.
274         return tcx.item_name(def_id).to_string();
275     }
276
277     if let Some(name) = &attrs.export_name {
278         // Use provided name
279         return name.to_string();
280     }
281
282     if attrs.flags.contains(CodegenFnAttrFlags::NO_MANGLE) {
283         // Don't mangle
284         return tcx.item_name(def_id).to_string();
285     }
286
287     // We want to compute the "type" of this item. Unfortunately, some
288     // kinds of items (e.g., closures) don't have an entry in the
289     // item-type array. So walk back up the find the closest parent
290     // that DOES have an entry.
291     let mut ty_def_id = def_id;
292     let instance_ty;
293     loop {
294         let key = tcx.def_key(ty_def_id);
295         match key.disambiguated_data.data {
296             DefPathData::TypeNs(_) | DefPathData::ValueNs(_) => {
297                 instance_ty = tcx.type_of(ty_def_id);
298                 break;
299             }
300             _ => {
301                 // if we're making a symbol for something, there ought
302                 // to be a value or type-def or something in there
303                 // *somewhere*
304                 ty_def_id.index = key.parent.unwrap_or_else(|| {
305                     bug!(
306                         "finding type for {:?}, encountered def-id {:?} with no \
307                          parent",
308                         def_id,
309                         ty_def_id
310                     );
311                 });
312             }
313         }
314     }
315
316     // Erase regions because they may not be deterministic when hashed
317     // and should not matter anyhow.
318     let instance_ty = tcx.erase_regions(&instance_ty);
319
320     let hash = get_symbol_hash(tcx, def_id, instance, instance_ty, substs);
321
322     let mut printer = SymbolPrinter {
323         tcx,
324         path: SymbolPath::from_interned(tcx.def_symbol_name(def_id)),
325         keep_within_component: false,
326     };
327
328     if instance.is_vtable_shim() {
329         let _ = printer.write_str("{{vtable-shim}}");
330     }
331
332     printer.path.finish(hash)
333 }
334
335 // Follow C++ namespace-mangling style, see
336 // http://en.wikipedia.org/wiki/Name_mangling for more info.
337 //
338 // It turns out that on macOS you can actually have arbitrary symbols in
339 // function names (at least when given to LLVM), but this is not possible
340 // when using unix's linker. Perhaps one day when we just use a linker from LLVM
341 // we won't need to do this name mangling. The problem with name mangling is
342 // that it seriously limits the available characters. For example we can't
343 // have things like &T in symbol names when one would theoretically
344 // want them for things like impls of traits on that type.
345 //
346 // To be able to work on all platforms and get *some* reasonable output, we
347 // use C++ name-mangling.
348 #[derive(Debug)]
349 struct SymbolPath {
350     result: String,
351     temp_buf: String,
352 }
353
354 impl SymbolPath {
355     fn new() -> Self {
356         let mut result = SymbolPath {
357             result: String::with_capacity(64),
358             temp_buf: String::with_capacity(16),
359         };
360         result.result.push_str("_ZN"); // _Z == Begin name-sequence, N == nested
361         result
362     }
363
364     fn from_interned(symbol: ty::SymbolName) -> Self {
365         let mut result = SymbolPath {
366             result: String::with_capacity(64),
367             temp_buf: String::with_capacity(16),
368         };
369         result.result.push_str(&symbol.as_str());
370         result
371     }
372
373     fn into_interned(mut self) -> ty::SymbolName {
374         self.finalize_pending_component();
375         ty::SymbolName {
376             name: Symbol::intern(&self.result).as_interned_str(),
377         }
378     }
379
380     fn finalize_pending_component(&mut self) {
381         if !self.temp_buf.is_empty() {
382             let _ = write!(self.result, "{}{}", self.temp_buf.len(), self.temp_buf);
383             self.temp_buf.clear();
384         }
385     }
386
387     fn finish(mut self, hash: u64) -> String {
388         self.finalize_pending_component();
389         // E = end name-sequence
390         let _ = write!(self.result, "17h{:016x}E", hash);
391         self.result
392     }
393 }
394
395 struct SymbolPrinter<'a, 'tcx> {
396     tcx: TyCtxt<'a, 'tcx, 'tcx>,
397     path: SymbolPath,
398
399     // When `true`, `finalize_pending_component` isn't used.
400     // This is needed when recursing into `path_qualified`,
401     // or `path_generic_args`, as any nested paths are
402     // logically within one component.
403     keep_within_component: bool,
404 }
405
406 // HACK(eddyb) this relies on using the `fmt` interface to get
407 // `PrettyPrinter` aka pretty printing of e.g. types in paths,
408 // symbol names should have their own printing machinery.
409
410 impl Printer<'tcx, 'tcx> for SymbolPrinter<'_, 'tcx> {
411     type Error = fmt::Error;
412
413     type Path = Self;
414     type Region = Self;
415     type Type = Self;
416     type DynExistential = Self;
417
418     fn tcx(&'a self) -> TyCtxt<'a, 'tcx, 'tcx> {
419         self.tcx
420     }
421
422     fn print_region(
423         self,
424         _region: ty::Region<'_>,
425     ) -> Result<Self::Region, Self::Error> {
426         Ok(self)
427     }
428
429     fn print_type(
430         self,
431         ty: Ty<'tcx>,
432     ) -> Result<Self::Type, Self::Error> {
433         match ty.sty {
434             // Print all nominal types as paths (unlike `pretty_print_type`).
435             ty::FnDef(def_id, substs) |
436             ty::Opaque(def_id, substs) |
437             ty::Projection(ty::ProjectionTy { item_def_id: def_id, substs }) |
438             ty::UnnormalizedProjection(ty::ProjectionTy { item_def_id: def_id, substs }) |
439             ty::Closure(def_id, ty::ClosureSubsts { substs }) |
440             ty::Generator(def_id, ty::GeneratorSubsts { substs }, _) => {
441                 self.print_def_path(def_id, substs)
442             }
443             _ => self.pretty_print_type(ty),
444         }
445     }
446
447     fn print_dyn_existential(
448         mut self,
449         predicates: &'tcx ty::List<ty::ExistentialPredicate<'tcx>>,
450     ) -> Result<Self::DynExistential, Self::Error> {
451         let mut first = false;
452         for p in predicates {
453             if !first {
454                 write!(self, "+")?;
455             }
456             first = false;
457             self = p.print(self)?;
458         }
459         Ok(self)
460     }
461
462     fn path_crate(
463         mut self,
464         cnum: CrateNum,
465     ) -> Result<Self::Path, Self::Error> {
466         self.write_str(&self.tcx.original_crate_name(cnum).as_str())?;
467         Ok(self)
468     }
469     fn path_qualified(
470         self,
471         self_ty: Ty<'tcx>,
472         trait_ref: Option<ty::TraitRef<'tcx>>,
473     ) -> Result<Self::Path, Self::Error> {
474         // Similar to `pretty_path_qualified`, but for the other
475         // types that are printed as paths (see `print_type` above).
476         match self_ty.sty {
477             ty::FnDef(..) |
478             ty::Opaque(..) |
479             ty::Projection(_) |
480             ty::UnnormalizedProjection(_) |
481             ty::Closure(..) |
482             ty::Generator(..)
483                 if trait_ref.is_none() =>
484             {
485                 self.print_type(self_ty)
486             }
487
488             _ => self.pretty_path_qualified(self_ty, trait_ref)
489         }
490     }
491
492     fn path_append_impl(
493         self,
494         print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
495         _disambiguated_data: &DisambiguatedDefPathData,
496         self_ty: Ty<'tcx>,
497         trait_ref: Option<ty::TraitRef<'tcx>>,
498     ) -> Result<Self::Path, Self::Error> {
499         self.pretty_path_append_impl(
500             |mut cx| {
501                 cx = print_prefix(cx)?;
502
503                 if cx.keep_within_component {
504                     // HACK(eddyb) print the path similarly to how `FmtPrinter` prints it.
505                     cx.write_str("::")?;
506                 } else {
507                     cx.path.finalize_pending_component();
508                 }
509
510                 Ok(cx)
511             },
512             self_ty,
513             trait_ref,
514         )
515     }
516     fn path_append(
517         mut self,
518         print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
519         disambiguated_data: &DisambiguatedDefPathData,
520     ) -> Result<Self::Path, Self::Error> {
521         self = print_prefix(self)?;
522
523         // Skip `::{{constructor}}` on tuple/unit structs.
524         match disambiguated_data.data {
525             DefPathData::Ctor => return Ok(self),
526             _ => {}
527         }
528
529         if self.keep_within_component {
530             // HACK(eddyb) print the path similarly to how `FmtPrinter` prints it.
531             self.write_str("::")?;
532         } else {
533             self.path.finalize_pending_component();
534         }
535
536         self.write_str(&disambiguated_data.data.as_interned_str().as_str())?;
537         Ok(self)
538     }
539     fn path_generic_args(
540         mut self,
541         print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
542         args: &[Kind<'tcx>],
543     )  -> Result<Self::Path, Self::Error> {
544         self = print_prefix(self)?;
545
546         let args = args.iter().cloned().filter(|arg| {
547             match arg.unpack() {
548                 UnpackedKind::Lifetime(_) => false,
549                 _ => true,
550             }
551         });
552
553         if args.clone().next().is_some() {
554             self.generic_delimiters(|cx| cx.comma_sep(args))
555         } else {
556             Ok(self)
557         }
558     }
559 }
560
561 impl PrettyPrinter<'tcx, 'tcx> for SymbolPrinter<'_, 'tcx> {
562     fn region_should_not_be_omitted(
563         &self,
564         _region: ty::Region<'_>,
565     ) -> bool {
566         false
567     }
568     fn comma_sep<T>(
569         mut self,
570         mut elems: impl Iterator<Item = T>,
571     ) -> Result<Self, Self::Error>
572         where T: Print<'tcx, 'tcx, Self, Output = Self, Error = Self::Error>
573     {
574         if let Some(first) = elems.next() {
575             self = first.print(self)?;
576             for elem in elems {
577                 self.write_str(",")?;
578                 self = elem.print(self)?;
579             }
580         }
581         Ok(self)
582     }
583
584     fn generic_delimiters(
585         mut self,
586         f: impl FnOnce(Self) -> Result<Self, Self::Error>,
587     ) -> Result<Self, Self::Error> {
588         write!(self, "<")?;
589
590         let kept_within_component =
591             mem::replace(&mut self.keep_within_component, true);
592         self = f(self)?;
593         self.keep_within_component = kept_within_component;
594
595         write!(self, ">")?;
596
597         Ok(self)
598     }
599 }
600
601 impl fmt::Write for SymbolPrinter<'_, '_> {
602     fn write_str(&mut self, s: &str) -> fmt::Result {
603         // Name sanitation. LLVM will happily accept identifiers with weird names, but
604         // gas doesn't!
605         // gas accepts the following characters in symbols: a-z, A-Z, 0-9, ., _, $
606         // NVPTX assembly has more strict naming rules than gas, so additionally, dots
607         // are replaced with '$' there.
608
609         for c in s.chars() {
610             if self.path.temp_buf.is_empty() {
611                 match c {
612                     'a'..='z' | 'A'..='Z' | '_' => {}
613                     _ => {
614                         // Underscore-qualify anything that didn't start as an ident.
615                         self.path.temp_buf.push('_');
616                     }
617                 }
618             }
619             match c {
620                 // Escape these with $ sequences
621                 '@' => self.path.temp_buf.push_str("$SP$"),
622                 '*' => self.path.temp_buf.push_str("$BP$"),
623                 '&' => self.path.temp_buf.push_str("$RF$"),
624                 '<' => self.path.temp_buf.push_str("$LT$"),
625                 '>' => self.path.temp_buf.push_str("$GT$"),
626                 '(' => self.path.temp_buf.push_str("$LP$"),
627                 ')' => self.path.temp_buf.push_str("$RP$"),
628                 ',' => self.path.temp_buf.push_str("$C$"),
629
630                 '-' | ':' | '.' if self.tcx.has_strict_asm_symbol_naming() => {
631                     // NVPTX doesn't support these characters in symbol names.
632                     self.path.temp_buf.push('$')
633                 }
634
635                 // '.' doesn't occur in types and functions, so reuse it
636                 // for ':' and '-'
637                 '-' | ':' => self.path.temp_buf.push('.'),
638
639                 // These are legal symbols
640                 'a'..='z' | 'A'..='Z' | '0'..='9' | '_' | '.' | '$' => self.path.temp_buf.push(c),
641
642                 _ => {
643                     self.path.temp_buf.push('$');
644                     for c in c.escape_unicode().skip(1) {
645                         match c {
646                             '{' => {}
647                             '}' => self.path.temp_buf.push('$'),
648                             c => self.path.temp_buf.push(c),
649                         }
650                     }
651                 }
652             }
653         }
654
655         Ok(())
656     }
657 }