Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4aecfa9

Browse files
committed
introduce Mutability::ptr_str
1 parent 8bc5491 commit 4aecfa9

File tree

4 files changed

+12
-24
lines changed

4 files changed

+12
-24
lines changed

‎compiler/rustc_ast_ir/src/lib.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ impl Mutability {
5151
}
5252
}
5353

54+
/// Returns `"const"` or `"mut"` depending on the mutability.
55+
pub fn ptr_str(self) -> &'static str {
56+
match self {
57+
Mutability::Not => "const",
58+
Mutability::Mut => "mut",
59+
}
60+
}
61+
5462
/// Returns `""` (empty string) or `"mutably "` depending on the mutability.
5563
pub fn mutably_str(self) -> &'static str {
5664
match self {

‎compiler/rustc_middle/src/mir/pretty.rs‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -978,12 +978,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
978978
CopyForDeref(ref place) => write!(fmt, "deref_copy {place:#?}"),
979979

980980
AddressOf(mutability, ref place) => {
981-
let kind_str = match mutability {
982-
Mutability::Mut => "mut",
983-
Mutability::Not => "const",
984-
};
985-
986-
write!(fmt, "&raw {kind_str} {place:?}")
981+
write!(fmt, "&raw {mut_str} {place:?}", mut_str = mutability.ptr_str())
987982
}
988983

989984
Aggregate(ref kind, ref places) => {

‎compiler/rustc_middle/src/ty/print/pretty.rs‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -668,13 +668,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
668668
ty::Uint(t) => p!(write("{}", t.name_str())),
669669
ty::Float(t) => p!(write("{}", t.name_str())),
670670
ty::RawPtr(ty, mutbl) => {
671-
p!(write(
672-
"*{} ",
673-
match mutbl {
674-
hir::Mutability::Mut => "mut",
675-
hir::Mutability::Not => "const",
676-
}
677-
));
671+
p!(write("*{} ", mutbl.ptr_str()));
678672
p!(print(ty))
679673
}
680674
ty::Ref(r, ty, mutbl) => {

‎compiler/rustc_type_ir/src/ty_kind.rs‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -363,17 +363,8 @@ impl<I: Interner> DebugWithInfcx<I> for TyKind<I> {
363363
Str => write!(f, "str"),
364364
Array(t, c) => write!(f, "[{:?}; {:?}]", &this.wrap(t), &this.wrap(c)),
365365
Slice(t) => write!(f, "[{:?}]", &this.wrap(t)),
366-
RawPtr(ty, mutbl) => {
367-
match mutbl {
368-
Mutability::Mut => write!(f, "*mut "),
369-
Mutability::Not => write!(f, "*const "),
370-
}?;
371-
write!(f, "{:?}", &this.wrap(ty))
372-
}
373-
Ref(r, t, m) => match m {
374-
Mutability::Mut => write!(f, "&{:?} mut {:?}", &this.wrap(r), &this.wrap(t)),
375-
Mutability::Not => write!(f, "&{:?} {:?}", &this.wrap(r), &this.wrap(t)),
376-
},
366+
RawPtr(ty, mutbl) => write!(f, "*{} {:?}", mutbl.ptr_str(), this.wrap(ty)),
367+
Ref(r, t, m) => write!(f, "&{:?} {}{:?}", this.wrap(r), m.prefix_str(), this.wrap(t)),
377368
FnDef(d, s) => f.debug_tuple("FnDef").field(d).field(&this.wrap(s)).finish(),
378369
FnPtr(s) => write!(f, "{:?}", &this.wrap(s)),
379370
Dynamic(p, r, repr) => match repr {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /