Fix pretty printing of unsafe binders

This commit is contained in:
Michael Goulet 2025-03-01 19:28:04 +00:00
parent f4a216d28e
commit 83fa2faf23
5 changed files with 130 additions and 41 deletions

View file

@ -12,7 +12,7 @@ use rustc_hir::def_id::{CrateNum, DefId};
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
use rustc_middle::bug;
use rustc_middle::ty::layout::IntegerExt;
use rustc_middle::ty::print::{Print, PrintError, Printer};
use rustc_middle::ty::print::{Print, PrintError, Printer, WrapBinderMode};
use rustc_middle::ty::{
self, FloatTy, GenericArg, GenericArgKind, Instance, IntTy, ReifyReason, Ty, TyCtxt,
TypeVisitable, TypeVisitableExt, UintTy,
@ -172,6 +172,7 @@ impl<'tcx> SymbolMangler<'tcx> {
fn in_binder<T>(
&mut self,
value: &ty::Binder<'tcx, T>,
_mode: WrapBinderMode,
print_value: impl FnOnce(&mut Self, &T) -> Result<(), PrintError>,
) -> Result<(), PrintError>
where
@ -471,7 +472,7 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
ty::FnPtr(sig_tys, hdr) => {
let sig = sig_tys.with(hdr);
self.push("F");
self.in_binder(&sig, |cx, sig| {
self.in_binder(&sig, WrapBinderMode::ForAll, |cx, sig| {
if sig.safety.is_unsafe() {
cx.push("U");
}
@ -554,7 +555,7 @@ impl<'tcx> Printer<'tcx> for 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.in_binder(&predicates[0], |cx, _| {
self.in_binder(&predicates[0], WrapBinderMode::ForAll, |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