introduce Mutability::ptr_str
This commit is contained in:
parent
db3a5c5873
commit
277e61854e
@ -51,6 +51,14 @@ impl Mutability {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns `"const"` or `"mut"` depending on the mutability.
|
||||||
|
pub fn ptr_str(self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Mutability::Not => "const",
|
||||||
|
Mutability::Mut => "mut",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns `""` (empty string) or `"mutably "` depending on the mutability.
|
/// Returns `""` (empty string) or `"mutably "` depending on the mutability.
|
||||||
pub fn mutably_str(self) -> &'static str {
|
pub fn mutably_str(self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
|
@ -978,12 +978,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
|
|||||||
CopyForDeref(ref place) => write!(fmt, "deref_copy {place:#?}"),
|
CopyForDeref(ref place) => write!(fmt, "deref_copy {place:#?}"),
|
||||||
|
|
||||||
AddressOf(mutability, ref place) => {
|
AddressOf(mutability, ref place) => {
|
||||||
let kind_str = match mutability {
|
write!(fmt, "&raw {mut_str} {place:?}", mut_str = mutability.ptr_str())
|
||||||
Mutability::Mut => "mut",
|
|
||||||
Mutability::Not => "const",
|
|
||||||
};
|
|
||||||
|
|
||||||
write!(fmt, "&raw {kind_str} {place:?}")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Aggregate(ref kind, ref places) => {
|
Aggregate(ref kind, ref places) => {
|
||||||
|
@ -671,13 +671,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
|
|||||||
p!("(", print(ty), ") is ", write("{pat:?}"))
|
p!("(", print(ty), ") is ", write("{pat:?}"))
|
||||||
}
|
}
|
||||||
ty::RawPtr(ty, mutbl) => {
|
ty::RawPtr(ty, mutbl) => {
|
||||||
p!(write(
|
p!(write("*{} ", mutbl.ptr_str()));
|
||||||
"*{} ",
|
|
||||||
match mutbl {
|
|
||||||
hir::Mutability::Mut => "mut",
|
|
||||||
hir::Mutability::Not => "const",
|
|
||||||
}
|
|
||||||
));
|
|
||||||
p!(print(ty))
|
p!(print(ty))
|
||||||
}
|
}
|
||||||
ty::Ref(r, ty, mutbl) => {
|
ty::Ref(r, ty, mutbl) => {
|
||||||
|
@ -373,17 +373,8 @@ impl<I: Interner> DebugWithInfcx<I> for TyKind<I> {
|
|||||||
Array(t, c) => write!(f, "[{:?}; {:?}]", &this.wrap(t), &this.wrap(c)),
|
Array(t, c) => write!(f, "[{:?}; {:?}]", &this.wrap(t), &this.wrap(c)),
|
||||||
Pat(t, p) => write!(f, "pattern_type!({:?} is {:?})", &this.wrap(t), &this.wrap(p)),
|
Pat(t, p) => write!(f, "pattern_type!({:?} is {:?})", &this.wrap(t), &this.wrap(p)),
|
||||||
Slice(t) => write!(f, "[{:?}]", &this.wrap(t)),
|
Slice(t) => write!(f, "[{:?}]", &this.wrap(t)),
|
||||||
RawPtr(ty, mutbl) => {
|
RawPtr(ty, mutbl) => write!(f, "*{} {:?}", mutbl.ptr_str(), this.wrap(ty)),
|
||||||
match mutbl {
|
Ref(r, t, m) => write!(f, "&{:?} {}{:?}", this.wrap(r), m.prefix_str(), this.wrap(t)),
|
||||||
Mutability::Mut => write!(f, "*mut "),
|
|
||||||
Mutability::Not => write!(f, "*const "),
|
|
||||||
}?;
|
|
||||||
write!(f, "{:?}", &this.wrap(ty))
|
|
||||||
}
|
|
||||||
Ref(r, t, m) => match m {
|
|
||||||
Mutability::Mut => write!(f, "&{:?} mut {:?}", &this.wrap(r), &this.wrap(t)),
|
|
||||||
Mutability::Not => write!(f, "&{:?} {:?}", &this.wrap(r), &this.wrap(t)),
|
|
||||||
},
|
|
||||||
FnDef(d, s) => f.debug_tuple("FnDef").field(d).field(&this.wrap(s)).finish(),
|
FnDef(d, s) => f.debug_tuple("FnDef").field(d).field(&this.wrap(s)).finish(),
|
||||||
FnPtr(s) => write!(f, "{:?}", &this.wrap(s)),
|
FnPtr(s) => write!(f, "{:?}", &this.wrap(s)),
|
||||||
Dynamic(p, r, repr) => match repr {
|
Dynamic(p, r, repr) => match repr {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user