about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2021-07-29 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2021-07-29 13:30:40 +0200
commit0eabbf84babbf9302285a4cb2ea54a9d67f13945 (patch)
treec88a33ae27868a0c6d69a9c3d82e9a566c2488c9
parent0ce8001a473e049a74f424d765b90f83f5dc76c4 (diff)
downloadrust-0eabbf84babbf9302285a4cb2ea54a9d67f13945.tar.gz
rust-0eabbf84babbf9302285a4cb2ea54a9d67f13945.zip
Implement `Printer` for `&mut SymbolMangler`
to avoid passing the symbol mangler by value.
-rw-r--r--compiler/rustc_symbol_mangling/src/v0.rs28
1 files changed, 14 insertions, 14 deletions
diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs
index 6a1360da4ee..c4c1ec8ce4e 100644
--- a/compiler/rustc_symbol_mangling/src/v0.rs
+++ b/compiler/rustc_symbol_mangling/src/v0.rs
@@ -23,7 +23,7 @@ pub(super) fn mangle(
     let substs = tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), instance.substs);
 
     let prefix = "_R";
-    let mut cx = SymbolMangler {
+    let mut cx = &mut SymbolMangler {
         tcx,
         start_offset: prefix.len(),
         paths: FxHashMap::default(),
@@ -49,7 +49,7 @@ pub(super) fn mangle(
     if let Some(instantiating_crate) = instantiating_crate {
         cx = cx.print_def_path(instantiating_crate.as_def_id(), &[]).unwrap();
     }
-    cx.out
+    std::mem::take(&mut cx.out)
 }
 
 struct BinderLevel {
@@ -153,13 +153,13 @@ impl SymbolMangler<'tcx> {
         self.push(ident);
     }
 
-    fn path_append_ns(
-        mut self,
-        print_prefix: impl FnOnce(Self) -> Result<Self, !>,
+    fn path_append_ns<'a>(
+        mut self: &'a mut Self,
+        print_prefix: impl FnOnce(&'a mut Self) -> Result<&'a mut Self, !>,
         ns: char,
         disambiguator: u64,
         name: &str,
-    ) -> Result<Self, !> {
+    ) -> Result<&'a mut Self, !> {
         self.push("N");
         self.out.push(ns);
         self = print_prefix(self)?;
@@ -168,17 +168,17 @@ impl SymbolMangler<'tcx> {
         Ok(self)
     }
 
-    fn print_backref(mut self, i: usize) -> Result<Self, !> {
+    fn print_backref(&mut self, i: usize) -> Result<&mut Self, !> {
         self.push("B");
         self.push_integer_62((i - self.start_offset) as u64);
         Ok(self)
     }
 
-    fn in_binder<T>(
-        mut self,
+    fn in_binder<'a, T>(
+        mut self: &'a mut Self,
         value: &ty::Binder<'tcx, T>,
-        print_value: impl FnOnce(Self, &T) -> Result<Self, !>,
-    ) -> Result<Self, !>
+        print_value: impl FnOnce(&'a mut Self, &T) -> Result<&'a mut Self, !>,
+    ) -> Result<&'a mut Self, !>
     where
         T: TypeFoldable<'tcx>,
     {
@@ -211,7 +211,7 @@ impl SymbolMangler<'tcx> {
     }
 }
 
-impl Printer<'tcx> for SymbolMangler<'tcx> {
+impl Printer<'tcx> for &mut SymbolMangler<'tcx> {
     type Error = !;
 
     type Path = Self;
@@ -303,7 +303,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
         Ok(self)
     }
 
-    fn print_region(mut self, region: ty::Region<'_>) -> Result<Self::Region, Self::Error> {
+    fn print_region(self, region: ty::Region<'_>) -> Result<Self::Region, Self::Error> {
         let i = match *region {
             // Erased lifetimes use the index 0, for a
             // shorter mangling of `L_`.
@@ -577,7 +577,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
         Ok(self)
     }
 
-    fn path_crate(mut self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
+    fn path_crate(self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
         self.push("C");
         let stable_crate_id = self.tcx.def_path_hash(cnum.as_def_id()).stable_crate_id();
         self.push_disambiguator(stable_crate_id.to_u64());