Skip to content

Commit

Permalink
Rollup merge of #87582 - tmiasko:symbol-printer, r=michaelwoerister
Browse files Browse the repository at this point in the history
Implement `Printer` for `&mut SymbolPrinter`

to avoid passing `SymbolPrinter` by value.
  • Loading branch information
JohnTitor authored Aug 10, 2021
2 parents 3b41447 + 38c07c7 commit 43b7cad
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions compiler/rustc_symbol_mangling/src/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ pub(super) fn mangle(

let hash = get_symbol_hash(tcx, instance, instance_ty, instantiating_crate);

let mut printer = SymbolPrinter { tcx, path: SymbolPath::new(), keep_within_component: false }
let mut printer = SymbolPrinter { tcx, path: SymbolPath::new(), keep_within_component: false };
printer
.print_def_path(
def_id,
if let ty::InstanceDef::DropGlue(_, _) = instance.def {
Expand Down Expand Up @@ -198,7 +199,7 @@ struct SymbolPrinter<'tcx> {
// `PrettyPrinter` aka pretty printing of e.g. types in paths,
// symbol names should have their own printing machinery.

impl Printer<'tcx> for SymbolPrinter<'tcx> {
impl Printer<'tcx> for &mut SymbolPrinter<'tcx> {
type Error = fmt::Error;

type Path = Self;
Expand Down Expand Up @@ -242,7 +243,7 @@ impl Printer<'tcx> for SymbolPrinter<'tcx> {
Ok(self)
}

fn print_const(mut self, ct: &'tcx ty::Const<'tcx>) -> Result<Self::Const, Self::Error> {
fn print_const(self, ct: &'tcx ty::Const<'tcx>) -> Result<Self::Const, Self::Error> {
// only print integers
if let ty::ConstKind::Value(ConstValue::Scalar(Scalar::Int { .. })) = ct.val {
if ct.ty.is_integral() {
Expand All @@ -253,7 +254,7 @@ impl Printer<'tcx> for SymbolPrinter<'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.write_str(&self.tcx.crate_name(cnum).as_str())?;
Ok(self)
}
Expand Down Expand Up @@ -344,7 +345,7 @@ impl Printer<'tcx> for SymbolPrinter<'tcx> {
}
}

impl PrettyPrinter<'tcx> for SymbolPrinter<'tcx> {
impl PrettyPrinter<'tcx> for &mut SymbolPrinter<'tcx> {
fn region_should_not_be_omitted(&self, _region: ty::Region<'_>) -> bool {
false
}
Expand Down

0 comments on commit 43b7cad

Please sign in to comment.