Make ty::print::Printer
take &mut self
instead of self
This simplifies the code by removing all the `self` assignments and makes the flow of data clearer - always into the printer. Especially in v0 mangling, which already used `&mut self` in some places, it gets a lot more uniform.
This commit is contained in:
parent
45a45c6e60
commit
5acf26b97e
17 changed files with 615 additions and 592 deletions
|
@ -1210,35 +1210,35 @@ impl<'tcx> LateContext<'tcx> {
|
|||
self.tcx
|
||||
}
|
||||
|
||||
fn print_region(self, _region: ty::Region<'_>) -> Result<Self, PrintError> {
|
||||
Ok(self)
|
||||
fn print_region(&mut self, _region: ty::Region<'_>) -> Result<(), PrintError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn print_type(self, _ty: Ty<'tcx>) -> Result<Self, PrintError> {
|
||||
Ok(self)
|
||||
fn print_type(&mut self, _ty: Ty<'tcx>) -> Result<(), PrintError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn print_dyn_existential(
|
||||
self,
|
||||
&mut self,
|
||||
_predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
|
||||
) -> Result<Self, PrintError> {
|
||||
Ok(self)
|
||||
) -> Result<(), PrintError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn print_const(self, _ct: ty::Const<'tcx>) -> Result<Self, PrintError> {
|
||||
Ok(self)
|
||||
fn print_const(&mut self, _ct: ty::Const<'tcx>) -> Result<(), PrintError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn path_crate(mut self, cnum: CrateNum) -> Result<Self, PrintError> {
|
||||
fn path_crate(&mut self, cnum: CrateNum) -> Result<(), PrintError> {
|
||||
self.path = vec![self.tcx.crate_name(cnum)];
|
||||
Ok(self)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn path_qualified(
|
||||
mut self,
|
||||
&mut self,
|
||||
self_ty: Ty<'tcx>,
|
||||
trait_ref: Option<ty::TraitRef<'tcx>>,
|
||||
) -> Result<Self, PrintError> {
|
||||
) -> Result<(), PrintError> {
|
||||
if trait_ref.is_none() {
|
||||
if let ty::Adt(def, args) = self_ty.kind() {
|
||||
return self.print_def_path(def.did(), args);
|
||||
|
@ -1251,21 +1251,21 @@ impl<'tcx> LateContext<'tcx> {
|
|||
Some(trait_ref) => Symbol::intern(&format!("{trait_ref:?}")),
|
||||
None => Symbol::intern(&format!("<{self_ty}>")),
|
||||
}];
|
||||
Ok(self)
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
fn path_append_impl(
|
||||
self,
|
||||
print_prefix: impl FnOnce(Self) -> Result<Self, PrintError>,
|
||||
&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, PrintError> {
|
||||
let mut path = print_prefix(self)?;
|
||||
) -> Result<(), PrintError> {
|
||||
print_prefix(self)?;
|
||||
|
||||
// This shouldn't ever be needed, but just in case:
|
||||
path.path.push(match trait_ref {
|
||||
self.path.push(match trait_ref {
|
||||
Some(trait_ref) => {
|
||||
with_no_trimmed_paths!(Symbol::intern(&format!(
|
||||
"<impl {} for {}>",
|
||||
|
@ -1278,38 +1278,37 @@ impl<'tcx> LateContext<'tcx> {
|
|||
}
|
||||
});
|
||||
|
||||
Ok(path)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn path_append(
|
||||
self,
|
||||
print_prefix: impl FnOnce(Self) -> Result<Self, PrintError>,
|
||||
&mut self,
|
||||
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
|
||||
disambiguated_data: &DisambiguatedDefPathData,
|
||||
) -> Result<Self, PrintError> {
|
||||
let mut path = 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(path);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
path.path.push(Symbol::intern(&disambiguated_data.data.to_string()));
|
||||
Ok(path)
|
||||
self.path.push(Symbol::intern(&disambiguated_data.data.to_string()));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn path_generic_args(
|
||||
self,
|
||||
print_prefix: impl FnOnce(Self) -> Result<Self, PrintError>,
|
||||
&mut self,
|
||||
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
|
||||
_args: &[GenericArg<'tcx>],
|
||||
) -> Result<Self, PrintError> {
|
||||
) -> Result<(), PrintError> {
|
||||
print_prefix(self)
|
||||
}
|
||||
}
|
||||
|
||||
AbsolutePathPrinter { tcx: self.tcx, path: vec![] }
|
||||
.print_def_path(def_id, &[])
|
||||
.unwrap()
|
||||
.path
|
||||
let mut printer = AbsolutePathPrinter { tcx: self.tcx, path: vec![] };
|
||||
printer.print_def_path(def_id, &[]).unwrap();
|
||||
printer.path
|
||||
}
|
||||
|
||||
/// Returns the associated type `name` for `self_ty` as an implementation of `trait_id`.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue