summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_symbol_mangling/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /compiler/rustc_symbol_mangling/src
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_symbol_mangling/src')
-rw-r--r--compiler/rustc_symbol_mangling/src/errors.rs40
-rw-r--r--compiler/rustc_symbol_mangling/src/legacy.rs104
-rw-r--r--compiler/rustc_symbol_mangling/src/lib.rs9
-rw-r--r--compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs12
-rw-r--r--compiler/rustc_symbol_mangling/src/v0.rs195
5 files changed, 178 insertions, 182 deletions
diff --git a/compiler/rustc_symbol_mangling/src/errors.rs b/compiler/rustc_symbol_mangling/src/errors.rs
index f4d0751f7..2e081e555 100644
--- a/compiler/rustc_symbol_mangling/src/errors.rs
+++ b/compiler/rustc_symbol_mangling/src/errors.rs
@@ -1,18 +1,32 @@
//! Errors emitted by symbol_mangling.
-use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
-use rustc_macros::Diagnostic;
+use rustc_errors::{ErrorGuaranteed, IntoDiagnostic};
use rustc_span::Span;
+use std::fmt;
-#[derive(Diagnostic)]
-#[diag(symbol_mangling_test_output)]
pub struct TestOutput {
- #[primary_span]
pub span: Span,
pub kind: Kind,
pub content: String,
}
+// This diagnostic doesn't need translation because (a) it doesn't contain any
+// natural language, and (b) it's only used in tests. So we construct it
+// manually and avoid the fluent machinery.
+impl IntoDiagnostic<'_> for TestOutput {
+ fn into_diagnostic(
+ self,
+ handler: &'_ rustc_errors::Handler,
+ ) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
+ let TestOutput { span, kind, content } = self;
+
+ #[allow(rustc::untranslatable_diagnostic)]
+ let mut diag = handler.struct_err(format!("{kind}({content})"));
+ diag.set_span(span);
+ diag
+ }
+}
+
pub enum Kind {
SymbolName,
Demangling,
@@ -20,15 +34,13 @@ pub enum Kind {
DefPath,
}
-impl IntoDiagnosticArg for Kind {
- fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
- let kind = match self {
- Kind::SymbolName => "symbol-name",
- Kind::Demangling => "demangling",
- Kind::DemanglingAlt => "demangling-alt",
- Kind::DefPath => "def-path",
+impl fmt::Display for Kind {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ match self {
+ Kind::SymbolName => write!(f, "symbol-name"),
+ Kind::Demangling => write!(f, "demangling"),
+ Kind::DemanglingAlt => write!(f, "demangling-alt"),
+ Kind::DefPath => write!(f, "def-path"),
}
- .into();
- DiagnosticArgValue::Str(kind)
}
}
diff --git a/compiler/rustc_symbol_mangling/src/legacy.rs b/compiler/rustc_symbol_mangling/src/legacy.rs
index 2fc102bda..53925eeaa 100644
--- a/compiler/rustc_symbol_mangling/src/legacy.rs
+++ b/compiler/rustc_symbol_mangling/src/legacy.rs
@@ -1,7 +1,7 @@
use rustc_data_structures::stable_hasher::{Hash64, HashStable, StableHasher};
use rustc_hir::def_id::CrateNum;
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
-use rustc_middle::ty::print::{PrettyPrinter, Print, Printer};
+use rustc_middle::ty::print::{PrettyPrinter, Print, PrintError, Printer};
use rustc_middle::ty::{self, Instance, Ty, TyCtxt, TypeVisitableExt};
use rustc_middle::ty::{GenericArg, GenericArgKind};
use rustc_middle::util::common::record_time;
@@ -199,46 +199,38 @@ struct SymbolPrinter<'tcx> {
// `PrettyPrinter` aka pretty printing of e.g. types in paths,
// symbol names should have their own printing machinery.
-impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
- type Error = fmt::Error;
-
- type Path = Self;
- type Region = Self;
- type Type = Self;
- type DynExistential = Self;
- type Const = Self;
-
+impl<'tcx> Printer<'tcx> for SymbolPrinter<'tcx> {
fn tcx(&self) -> TyCtxt<'tcx> {
self.tcx
}
- fn print_region(self, _region: ty::Region<'_>) -> Result<Self::Region, Self::Error> {
- Ok(self)
+ fn print_region(&mut self, _region: ty::Region<'_>) -> Result<(), PrintError> {
+ Ok(())
}
- fn print_type(mut self, ty: Ty<'tcx>) -> Result<Self::Type, Self::Error> {
+ fn print_type(&mut self, ty: Ty<'tcx>) -> Result<(), PrintError> {
match *ty.kind() {
// Print all nominal types as paths (unlike `pretty_print_type`).
ty::FnDef(def_id, args)
| ty::Alias(ty::Projection | ty::Opaque, ty::AliasTy { def_id, args, .. })
| ty::Closure(def_id, args)
- | ty::Generator(def_id, args, _) => self.print_def_path(def_id, args),
+ | ty::Coroutine(def_id, args, _) => self.print_def_path(def_id, args),
// The `pretty_print_type` formatting of array size depends on
// -Zverbose flag, so we cannot reuse it here.
ty::Array(ty, size) => {
self.write_str("[")?;
- self = self.print_type(ty)?;
+ self.print_type(ty)?;
self.write_str("; ")?;
if let Some(size) = size.try_to_target_usize(self.tcx()) {
write!(self, "{size}")?
} else if let ty::ConstKind::Param(param) = size.kind() {
- self = param.print(self)?
+ param.print(self)?
} else {
self.write_str("_")?
}
self.write_str("]")?;
- Ok(self)
+ Ok(())
}
ty::Alias(ty::Inherent, _) => panic!("unexpected inherent projection"),
@@ -248,21 +240,21 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
}
fn print_dyn_existential(
- mut self,
+ &mut self,
predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
- ) -> Result<Self::DynExistential, Self::Error> {
+ ) -> Result<(), PrintError> {
let mut first = true;
for p in predicates {
if !first {
write!(self, "+")?;
}
first = false;
- self = p.print(self)?;
+ p.print(self)?;
}
- Ok(self)
+ Ok(())
}
- fn print_const(self, ct: ty::Const<'tcx>) -> Result<Self::Const, Self::Error> {
+ fn print_const(&mut self, ct: ty::Const<'tcx>) -> Result<(), PrintError> {
// only print integers
match (ct.kind(), ct.ty().kind()) {
(ty::ConstKind::Value(ty::ValTree::Leaf(scalar)), ty::Int(_) | ty::Uint(_)) => {
@@ -277,22 +269,22 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
}
_ => self.write_str("_")?,
}
- Ok(self)
+ Ok(())
}
- fn path_crate(self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
+ fn path_crate(&mut self, cnum: CrateNum) -> Result<(), PrintError> {
self.write_str(self.tcx.crate_name(cnum).as_str())?;
- Ok(self)
+ Ok(())
}
fn path_qualified(
- self,
+ &mut self,
self_ty: Ty<'tcx>,
trait_ref: Option<ty::TraitRef<'tcx>>,
- ) -> Result<Self::Path, Self::Error> {
+ ) -> Result<(), PrintError> {
// Similar to `pretty_path_qualified`, but for the other
// types that are printed as paths (see `print_type` above).
match self_ty.kind() {
- ty::FnDef(..) | ty::Alias(..) | ty::Closure(..) | ty::Generator(..)
+ ty::FnDef(..) | ty::Alias(..) | ty::Closure(..) | ty::Coroutine(..)
if trait_ref.is_none() =>
{
self.print_type(self_ty)
@@ -303,15 +295,15 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
}
fn path_append_impl(
- self,
- print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
+ &mut self,
+ print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
_disambiguated_data: &DisambiguatedDefPathData,
self_ty: Ty<'tcx>,
trait_ref: Option<ty::TraitRef<'tcx>>,
- ) -> Result<Self::Path, Self::Error> {
+ ) -> Result<(), PrintError> {
self.pretty_path_append_impl(
- |mut cx| {
- cx = print_prefix(cx)?;
+ |cx| {
+ print_prefix(cx)?;
if cx.keep_within_component {
// HACK(eddyb) print the path similarly to how `FmtPrinter` prints it.
@@ -320,22 +312,22 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
cx.path.finalize_pending_component();
}
- Ok(cx)
+ Ok(())
},
self_ty,
trait_ref,
)
}
fn path_append(
- mut self,
- print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
+ &mut self,
+ print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
disambiguated_data: &DisambiguatedDefPathData,
- ) -> Result<Self::Path, Self::Error> {
- self = print_prefix(self)?;
+ ) -> Result<(), PrintError> {
+ print_prefix(self)?;
// Skip `::{{extern}}` blocks and `::{{constructor}}` on tuple/unit structs.
if let DefPathData::ForeignMod | DefPathData::Ctor = disambiguated_data.data {
- return Ok(self);
+ return Ok(());
}
if self.keep_within_component {
@@ -347,14 +339,14 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
write!(self, "{}", disambiguated_data.data)?;
- Ok(self)
+ Ok(())
}
fn path_generic_args(
- mut self,
- print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
+ &mut self,
+ print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
args: &[GenericArg<'tcx>],
- ) -> Result<Self::Path, Self::Error> {
- self = print_prefix(self)?;
+ ) -> Result<(), PrintError> {
+ print_prefix(self)?;
let args =
args.iter().cloned().filter(|arg| !matches!(arg.unpack(), GenericArgKind::Lifetime(_)));
@@ -362,42 +354,42 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
if args.clone().next().is_some() {
self.generic_delimiters(|cx| cx.comma_sep(args))
} else {
- Ok(self)
+ Ok(())
}
}
}
-impl<'tcx> PrettyPrinter<'tcx> for &mut SymbolPrinter<'tcx> {
+impl<'tcx> PrettyPrinter<'tcx> for SymbolPrinter<'tcx> {
fn should_print_region(&self, _region: ty::Region<'_>) -> bool {
false
}
- fn comma_sep<T>(mut self, mut elems: impl Iterator<Item = T>) -> Result<Self, Self::Error>
+ fn comma_sep<T>(&mut self, mut elems: impl Iterator<Item = T>) -> Result<(), PrintError>
where
- T: Print<'tcx, Self, Output = Self, Error = Self::Error>,
+ T: Print<'tcx, Self>,
{
if let Some(first) = elems.next() {
- self = first.print(self)?;
+ first.print(self)?;
for elem in elems {
self.write_str(",")?;
- self = elem.print(self)?;
+ elem.print(self)?;
}
}
- Ok(self)
+ Ok(())
}
fn generic_delimiters(
- mut self,
- f: impl FnOnce(Self) -> Result<Self, Self::Error>,
- ) -> Result<Self, Self::Error> {
+ &mut self,
+ f: impl FnOnce(&mut Self) -> Result<(), PrintError>,
+ ) -> Result<(), PrintError> {
write!(self, "<")?;
let kept_within_component = mem::replace(&mut self.keep_within_component, true);
- self = f(self)?;
+ f(self)?;
self.keep_within_component = kept_within_component;
write!(self, ">")?;
- Ok(self)
+ Ok(())
}
}
diff --git a/compiler/rustc_symbol_mangling/src/lib.rs b/compiler/rustc_symbol_mangling/src/lib.rs
index 535a3ea2d..14dd8b4e5 100644
--- a/compiler/rustc_symbol_mangling/src/lib.rs
+++ b/compiler/rustc_symbol_mangling/src/lib.rs
@@ -88,6 +88,9 @@
//! DefPaths which are much more robust in the face of changes to the code base.
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
+#![cfg_attr(not(bootstrap), doc(rust_logo))]
+#![cfg_attr(not(bootstrap), feature(rustdoc_internals))]
+#![cfg_attr(not(bootstrap), allow(internal_features))]
#![feature(never_type)]
#![recursion_limit = "256"]
#![allow(rustc::potential_query_instability)]
@@ -100,8 +103,6 @@ extern crate rustc_middle;
#[macro_use]
extern crate tracing;
-use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
-use rustc_fluent_macro::fluent_messages;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
@@ -118,8 +119,6 @@ pub mod errors;
pub mod test;
pub mod typeid;
-fluent_messages! { "../messages.ftl" }
-
/// This function computes the symbol name for the given `instance` and the
/// given instantiating crate. That is, if you know that instance X is
/// instantiated in crate Y, this is the symbol name this instance would have.
@@ -235,7 +234,7 @@ fn compute_symbol_name<'tcx>(
// and we want to be sure to avoid any symbol conflicts here.
let is_globally_shared_function = matches!(
tcx.def_kind(instance.def_id()),
- DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Generator | DefKind::Ctor(..)
+ DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Coroutine | DefKind::Ctor(..)
) && matches!(
MonoItem::Fn(instance).instantiation_mode(tcx),
InstantiationMode::GloballyShared { may_conflict: true }
diff --git a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs
index 6ad3e7155..5ce188488 100644
--- a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs
+++ b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs
@@ -639,7 +639,7 @@ fn encode_ty<'tcx>(
typeid.push_str(&s);
}
- ty::Generator(def_id, args, ..) => {
+ ty::Coroutine(def_id, args, ..) => {
// u<length><name>[I<element-type1..element-typeN>E], where <element-type> is <subst>,
// as vendor extended type.
let mut s = String::new();
@@ -648,7 +648,7 @@ fn encode_ty<'tcx>(
// Encode parent args only
s.push_str(&encode_args(
tcx,
- tcx.mk_args(args.as_generator().parent_args()),
+ tcx.mk_args(args.as_coroutine().parent_args()),
dict,
options,
));
@@ -719,7 +719,7 @@ fn encode_ty<'tcx>(
ty::Alias(..)
| ty::Bound(..)
| ty::Error(..)
- | ty::GeneratorWitness(..)
+ | ty::CoroutineWitness(..)
| ty::Infer(..)
| ty::Placeholder(..) => {
bug!("encode_ty: unexpected `{:?}`", ty.kind());
@@ -778,7 +778,7 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
| ty::Str
| ty::Never
| ty::Foreign(..)
- | ty::GeneratorWitness(..) => {}
+ | ty::CoroutineWitness(..) => {}
ty::Bool => {
if options.contains(EncodeTyOptions::NORMALIZE_INTEGERS) {
@@ -892,8 +892,8 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
ty = Ty::new_closure(tcx, *def_id, transform_args(tcx, args, options));
}
- ty::Generator(def_id, args, movability) => {
- ty = Ty::new_generator(tcx, *def_id, transform_args(tcx, args, options), *movability);
+ ty::Coroutine(def_id, args, movability) => {
+ ty = Ty::new_coroutine(tcx, *def_id, transform_args(tcx, args, options), *movability);
}
ty::Ref(region, ty0, ..) => {
diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs
index 82b1a772e..ad3d291df 100644
--- a/compiler/rustc_symbol_mangling/src/v0.rs
+++ b/compiler/rustc_symbol_mangling/src/v0.rs
@@ -6,7 +6,7 @@ use rustc_hir::def::CtorKind;
use rustc_hir::def_id::{CrateNum, DefId};
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
use rustc_middle::ty::layout::IntegerExt;
-use rustc_middle::ty::print::{Print, Printer};
+use rustc_middle::ty::print::{Print, PrintError, Printer};
use rustc_middle::ty::{
self, EarlyBinder, FloatTy, Instance, IntTy, Ty, TyCtxt, TypeVisitable, TypeVisitableExt,
UintTy,
@@ -30,7 +30,7 @@ pub(super) fn mangle<'tcx>(
let args = tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), instance.args);
let prefix = "_R";
- let mut cx = &mut SymbolMangler {
+ let mut cx: SymbolMangler<'_> = SymbolMangler {
tcx,
start_offset: prefix.len(),
paths: FxHashMap::default(),
@@ -49,13 +49,13 @@ pub(super) fn mangle<'tcx>(
_ => None,
};
- cx = if let Some(shim_kind) = shim_kind {
+ if let Some(shim_kind) = shim_kind {
cx.path_append_ns(|cx| cx.print_def_path(def_id, args), 'S', 0, shim_kind).unwrap()
} else {
cx.print_def_path(def_id, args).unwrap()
};
if let Some(instantiating_crate) = instantiating_crate {
- cx = cx.print_def_path(instantiating_crate.as_def_id(), &[]).unwrap();
+ cx.print_def_path(instantiating_crate.as_def_id(), &[]).unwrap();
}
std::mem::take(&mut cx.out)
}
@@ -65,7 +65,7 @@ pub(super) fn mangle_typeid_for_trait_ref<'tcx>(
trait_ref: ty::PolyExistentialTraitRef<'tcx>,
) -> String {
// FIXME(flip1995): See comment in `mangle_typeid_for_fnabi`.
- let mut cx = &mut SymbolMangler {
+ let mut cx = SymbolMangler {
tcx,
start_offset: 0,
paths: FxHashMap::default(),
@@ -74,7 +74,7 @@ pub(super) fn mangle_typeid_for_trait_ref<'tcx>(
binders: vec![],
out: String::new(),
};
- cx = cx.print_def_path(trait_ref.def_id(), &[]).unwrap();
+ cx.print_def_path(trait_ref.def_id(), &[]).unwrap();
std::mem::take(&mut cx.out)
}
@@ -179,32 +179,32 @@ impl<'tcx> SymbolMangler<'tcx> {
self.push(ident);
}
- fn path_append_ns<'a>(
- mut self: &'a mut Self,
- print_prefix: impl FnOnce(&'a mut Self) -> Result<&'a mut Self, !>,
+ fn path_append_ns(
+ &mut self,
+ print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
ns: char,
disambiguator: u64,
name: &str,
- ) -> Result<&'a mut Self, !> {
+ ) -> Result<(), PrintError> {
self.push("N");
self.out.push(ns);
- self = print_prefix(self)?;
+ print_prefix(self)?;
self.push_disambiguator(disambiguator as u64);
self.push_ident(name);
- Ok(self)
+ Ok(())
}
- fn print_backref(&mut self, i: usize) -> Result<&mut Self, !> {
+ fn print_backref(&mut self, i: usize) -> Result<(), PrintError> {
self.push("B");
self.push_integer_62((i - self.start_offset) as u64);
- Ok(self)
+ Ok(())
}
- fn in_binder<'a, T>(
- mut self: &'a mut Self,
+ fn in_binder<T>(
+ &mut self,
value: &ty::Binder<'tcx, T>,
- print_value: impl FnOnce(&'a mut Self, &T) -> Result<&'a mut Self, !>,
- ) -> Result<&'a mut Self, !>
+ print_value: impl FnOnce(&mut Self, &T) -> Result<(), PrintError>,
+ ) -> Result<(), PrintError>
where
T: TypeVisitable<TyCtxt<'tcx>>,
{
@@ -222,53 +222,45 @@ impl<'tcx> SymbolMangler<'tcx> {
lifetime_depths.end += lifetimes;
self.binders.push(BinderLevel { lifetime_depths });
- self = print_value(self, value.as_ref().skip_binder())?;
+ print_value(self, value.as_ref().skip_binder())?;
self.binders.pop();
- Ok(self)
+ Ok(())
}
}
-impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
- type Error = !;
-
- type Path = Self;
- type Region = Self;
- type Type = Self;
- type DynExistential = Self;
- type Const = Self;
-
+impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
fn tcx(&self) -> TyCtxt<'tcx> {
self.tcx
}
fn print_def_path(
- mut self,
+ &mut self,
def_id: DefId,
args: &'tcx [GenericArg<'tcx>],
- ) -> Result<Self::Path, Self::Error> {
+ ) -> Result<(), PrintError> {
if let Some(&i) = self.paths.get(&(def_id, args)) {
return self.print_backref(i);
}
let start = self.out.len();
- self = self.default_print_def_path(def_id, args)?;
+ self.default_print_def_path(def_id, args)?;
// Only cache paths that do not refer to an enclosing
// binder (which would change depending on context).
if !args.iter().any(|k| k.has_escaping_bound_vars()) {
self.paths.insert((def_id, args), start);
}
- Ok(self)
+ Ok(())
}
fn print_impl_path(
- mut self,
+ &mut self,
impl_def_id: DefId,
args: &'tcx [GenericArg<'tcx>],
mut self_ty: Ty<'tcx>,
mut impl_trait_ref: Option<ty::TraitRef<'tcx>>,
- ) -> Result<Self::Path, Self::Error> {
+ ) -> Result<(), PrintError> {
let key = self.tcx.def_key(impl_def_id);
let parent_def_id = DefId { index: key.parent.unwrap(), ..impl_def_id };
@@ -296,7 +288,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
// Encode impl generic params if the substitutions contain parameters (implying
// polymorphization is enabled) and this isn't an inherent impl.
if impl_trait_ref.is_some() && args.iter().any(|a| a.has_non_region_param()) {
- self = self.path_generic_args(
+ self.path_generic_args(
|this| {
this.path_append_ns(
|cx| cx.print_def_path(parent_def_id, &[]),
@@ -309,19 +301,19 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
)?;
} else {
self.push_disambiguator(key.disambiguated_data.disambiguator as u64);
- self = self.print_def_path(parent_def_id, &[])?;
+ self.print_def_path(parent_def_id, &[])?;
}
- self = self_ty.print(self)?;
+ self_ty.print(self)?;
if let Some(trait_ref) = impl_trait_ref {
- self = self.print_def_path(trait_ref.def_id, trait_ref.args)?;
+ self.print_def_path(trait_ref.def_id, trait_ref.args)?;
}
- Ok(self)
+ Ok(())
}
- fn print_region(self, region: ty::Region<'_>) -> Result<Self::Region, Self::Error> {
+ fn print_region(&mut self, region: ty::Region<'_>) -> Result<(), PrintError> {
let i = match *region {
// Erased lifetimes use the index 0, for a
// shorter mangling of `L_`.
@@ -340,10 +332,10 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
};
self.push("L");
self.push_integer_62(i as u64);
- Ok(self)
+ Ok(())
}
- fn print_type(mut self, ty: Ty<'tcx>) -> Result<Self::Type, Self::Error> {
+ fn print_type(&mut self, ty: Ty<'tcx>) -> Result<(), PrintError> {
// Basic types, never cached (single-character).
let basic_type = match ty.kind() {
ty::Bool => "b",
@@ -373,7 +365,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
};
if !basic_type.is_empty() {
self.push(basic_type);
- return Ok(self);
+ return Ok(());
}
if let Some(&i) = self.types.get(&ty) {
@@ -399,9 +391,9 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
hir::Mutability::Mut => "Q",
});
if !r.is_erased() {
- self = r.print(self)?;
+ r.print(self)?;
}
- self = ty.print(self)?;
+ ty.print(self)?;
}
ty::RawPtr(mt) => {
@@ -409,23 +401,23 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
hir::Mutability::Not => "P",
hir::Mutability::Mut => "O",
});
- self = mt.ty.print(self)?;
+ mt.ty.print(self)?;
}
ty::Array(ty, len) => {
self.push("A");
- self = ty.print(self)?;
- self = self.print_const(len)?;
+ ty.print(self)?;
+ self.print_const(len)?;
}
ty::Slice(ty) => {
self.push("S");
- self = ty.print(self)?;
+ ty.print(self)?;
}
ty::Tuple(tys) => {
self.push("T");
for ty in tys.iter() {
- self = ty.print(self)?;
+ ty.print(self)?;
}
self.push("E");
}
@@ -435,16 +427,16 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
| ty::FnDef(def_id, args)
| ty::Alias(ty::Projection | ty::Opaque, ty::AliasTy { def_id, args, .. })
| ty::Closure(def_id, args)
- | ty::Generator(def_id, args, _) => {
- self = self.print_def_path(def_id, args)?;
+ | ty::Coroutine(def_id, args, _) => {
+ self.print_def_path(def_id, args)?;
}
ty::Foreign(def_id) => {
- self = self.print_def_path(def_id, &[])?;
+ self.print_def_path(def_id, &[])?;
}
ty::FnPtr(sig) => {
self.push("F");
- self = self.in_binder(&sig, |mut cx, sig| {
+ self.in_binder(&sig, |cx, sig| {
if sig.unsafety == hir::Unsafety::Unsafe {
cx.push("U");
}
@@ -462,7 +454,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
}
}
for &ty in sig.inputs() {
- cx = ty.print(cx)?;
+ ty.print(cx)?;
}
if sig.c_variadic {
cx.push("v");
@@ -478,13 +470,13 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
// FIXME(dyn-star): need to update v0 mangling docs
ty::DynStar => "D*",
});
- self = self.print_dyn_existential(predicates)?;
- self = r.print(self)?;
+ self.print_dyn_existential(predicates)?;
+ r.print(self)?;
}
ty::Alias(ty::Inherent, _) => bug!("symbol_names: unexpected inherent projection"),
ty::Alias(ty::Weak, _) => bug!("symbol_names: unexpected weak projection"),
- ty::GeneratorWitness(..) => bug!("symbol_names: unexpected `GeneratorWitness`"),
+ ty::CoroutineWitness(..) => bug!("symbol_names: unexpected `CoroutineWitness`"),
}
// Only cache types that do not refer to an enclosing
@@ -492,13 +484,13 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
if !ty.has_escaping_bound_vars() {
self.types.insert(ty, start);
}
- Ok(self)
+ Ok(())
}
fn print_dyn_existential(
- mut self,
+ &mut self,
predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
- ) -> Result<Self::DynExistential, Self::Error> {
+ ) -> Result<(), PrintError> {
// Okay, so this is a bit tricky. Imagine we have a trait object like
// `dyn for<'a> Foo<'a, Bar = &'a ()>`. When we mangle this, the
// output looks really close to the syntax, where the `Bar = &'a ()` bit
@@ -525,7 +517,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
// [<Trait> [{<Projection>}]] [{<Auto>}]
// Since any predicates after the first one shouldn't change the binders,
// just put them all in the binders of the first.
- self = self.in_binder(&predicates[0], |mut cx, _| {
+ self.in_binder(&predicates[0], |cx, _| {
for predicate in predicates.iter() {
// It would be nice to be able to validate bound vars here, but
// projections can actually include bound vars from super traits
@@ -536,30 +528,30 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
// Use a type that can't appear in defaults of type parameters.
let dummy_self = Ty::new_fresh(cx.tcx, 0);
let trait_ref = trait_ref.with_self_ty(cx.tcx, dummy_self);
- cx = cx.print_def_path(trait_ref.def_id, trait_ref.args)?;
+ cx.print_def_path(trait_ref.def_id, trait_ref.args)?;
}
ty::ExistentialPredicate::Projection(projection) => {
let name = cx.tcx.associated_item(projection.def_id).name;
cx.push("p");
cx.push_ident(name.as_str());
- cx = match projection.term.unpack() {
+ match projection.term.unpack() {
ty::TermKind::Ty(ty) => ty.print(cx),
ty::TermKind::Const(c) => c.print(cx),
}?;
}
ty::ExistentialPredicate::AutoTrait(def_id) => {
- cx = cx.print_def_path(*def_id, &[])?;
+ cx.print_def_path(*def_id, &[])?;
}
}
}
- Ok(cx)
+ Ok(())
})?;
self.push("E");
- Ok(self)
+ Ok(())
}
- fn print_const(mut self, ct: ty::Const<'tcx>) -> Result<Self::Const, Self::Error> {
+ fn print_const(&mut self, ct: ty::Const<'tcx>) -> Result<(), PrintError> {
// We only mangle a typed value if the const can be evaluated.
let ct = ct.normalize(self.tcx, ty::ParamEnv::reveal_all());
match ct.kind() {
@@ -578,12 +570,13 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
| ty::ConstKind::Error(_) => {
// Never cached (single-character).
self.push("p");
- return Ok(self);
+ return Ok(());
}
}
if let Some(&i) = self.consts.get(&ct) {
- return self.print_backref(i);
+ self.print_backref(i)?;
+ return Ok(());
}
let start = self.out.len();
@@ -591,7 +584,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
match ty.kind() {
ty::Uint(_) | ty::Int(_) | ty::Bool | ty::Char => {
- self = ty.print(self)?;
+ ty.print(self)?;
let mut bits = ct.eval_bits(self.tcx, ty::ParamEnv::reveal_all());
@@ -653,7 +646,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
.ty;
// FIXME(const_generics): add an assert that we only do this for valtrees.
let dereferenced_const = self.tcx.mk_ct_from_kind(ct.kind(), pointee_ty);
- self = dereferenced_const.print(self)?;
+ dereferenced_const.print(self)?;
}
}
}
@@ -662,22 +655,22 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
let contents = self.tcx.destructure_const(ct);
let fields = contents.fields.iter().copied();
- let print_field_list = |mut this: Self| {
+ let print_field_list = |this: &mut Self| {
for field in fields.clone() {
- this = field.print(this)?;
+ field.print(this)?;
}
this.push("E");
- Ok(this)
+ Ok(())
};
match *ct.ty().kind() {
ty::Array(..) | ty::Slice(_) => {
self.push("A");
- self = print_field_list(self)?;
+ print_field_list(self)?;
}
ty::Tuple(..) => {
self.push("T");
- self = print_field_list(self)?;
+ print_field_list(self)?;
}
ty::Adt(def, args) => {
let variant_idx =
@@ -685,7 +678,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
let variant_def = &def.variant(variant_idx);
self.push("V");
- self = self.print_def_path(variant_def.def_id, args)?;
+ self.print_def_path(variant_def.def_id, args)?;
match variant_def.ctor_kind() {
Some(CtorKind::Const) => {
@@ -693,7 +686,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
}
Some(CtorKind::Fn) => {
self.push("T");
- self = print_field_list(self)?;
+ print_field_list(self)?;
}
None => {
self.push("S");
@@ -709,7 +702,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
);
self.push_ident(field_name.unwrap_or(kw::Empty).as_str());
- self = field.print(self)?;
+ field.print(self)?;
}
self.push("E");
}
@@ -728,47 +721,47 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
if !ct.has_escaping_bound_vars() {
self.consts.insert(ct, start);
}
- Ok(self)
+ Ok(())
}
- fn path_crate(self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
+ fn path_crate(&mut self, cnum: CrateNum) -> Result<(), PrintError> {
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.as_u64());
let name = self.tcx.crate_name(cnum);
self.push_ident(name.as_str());
- Ok(self)
+ Ok(())
}
fn path_qualified(
- mut self,
+ &mut self,
self_ty: Ty<'tcx>,
trait_ref: Option<ty::TraitRef<'tcx>>,
- ) -> Result<Self::Path, Self::Error> {
+ ) -> Result<(), PrintError> {
assert!(trait_ref.is_some());
let trait_ref = trait_ref.unwrap();
self.push("Y");
- self = self_ty.print(self)?;
+ self_ty.print(self)?;
self.print_def_path(trait_ref.def_id, trait_ref.args)
}
fn path_append_impl(
- self,
- _: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
+ &mut self,
+ _: impl FnOnce(&mut Self) -> Result<(), PrintError>,
_: &DisambiguatedDefPathData,
_: Ty<'tcx>,
_: Option<ty::TraitRef<'tcx>>,
- ) -> Result<Self::Path, Self::Error> {
+ ) -> Result<(), PrintError> {
// Inlined into `print_impl_path`
unreachable!()
}
fn path_append(
- self,
- print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
+ &mut self,
+ print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
disambiguated_data: &DisambiguatedDefPathData,
- ) -> Result<Self::Path, Self::Error> {
+ ) -> Result<(), PrintError> {
let ns = match disambiguated_data.data {
// Extern block segments can be skipped, names from extern blocks
// are effectively living in their parent modules.
@@ -805,10 +798,10 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
}
fn path_generic_args(
- mut self,
- print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
+ &mut self,
+ print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
args: &[GenericArg<'tcx>],
- ) -> Result<Self::Path, Self::Error> {
+ ) -> Result<(), PrintError> {
// Don't print any regions if they're all erased.
let print_regions = args.iter().any(|arg| match arg.unpack() {
GenericArgKind::Lifetime(r) => !r.is_erased(),
@@ -824,23 +817,23 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
}
self.push("I");
- self = print_prefix(self)?;
+ print_prefix(self)?;
for arg in args {
match arg.unpack() {
GenericArgKind::Lifetime(lt) => {
- self = lt.print(self)?;
+ lt.print(self)?;
}
GenericArgKind::Type(ty) => {
- self = ty.print(self)?;
+ ty.print(self)?;
}
GenericArgKind::Const(c) => {
self.push("K");
- self = c.print(self)?;
+ c.print(self)?;
}
}
}
self.push("E");
- Ok(self)
+ Ok(())
}
}