Skip to content

Commit e867567

Browse files
committed
Use write_str() instead of write!() when possible
Reduces code size
1 parent a167cbd commit e867567

File tree

58 files changed

+243
-243
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+243
-243
lines changed

compiler/rustc_ast/src/util/literal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl fmt::Display for LitKind {
210210
LitKind::Err => {
211211
// This only shows up in places like `-Zunpretty=hir` output, so we
212212
// don't bother to produce something useful.
213-
write!(f, "<bad-literal>")?;
213+
f.write_str("<bad-literal>")?;
214214
}
215215
}
216216

compiler/rustc_const_eval/src/const_eval/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ impl fmt::Display for ConstEvalErrKind {
3737
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3838
use self::ConstEvalErrKind::*;
3939
match self {
40-
ConstAccessesStatic => write!(f, "constant accesses static"),
40+
ConstAccessesStatic => f.write_str("constant accesses static"),
4141
ModifiedGlobal => {
42-
write!(f, "modifying a static's initial value from another static's initializer")
42+
f.write_str("modifying a static's initial value from another static's initializer")
4343
}
4444
AssertFailure(msg) => write!(f, "{:?}", msg),
4545
Panic { msg, line, col, file } => {

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ pub enum MemoryKind {
147147
impl fmt::Display for MemoryKind {
148148
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
149149
match self {
150-
MemoryKind::Heap => write!(f, "heap allocation"),
150+
MemoryKind::Heap => f.write_str("heap allocation"),
151151
}
152152
}
153153
}

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl<'tcx> fmt::Display for FrameInfo<'tcx> {
265265
if tcx.def_key(self.instance.def_id()).disambiguated_data.data
266266
== DefPathData::ClosureExpr
267267
{
268-
write!(f, "inside closure")
268+
f.write_str("inside closure")
269269
} else {
270270
// Note: this triggers a `good_path_bug` state, which means that if we ever get here
271271
// we must emit a diagnostic. We should never display a `FrameInfo` unless we
@@ -987,12 +987,12 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> std::fmt::Debug
987987
if frame != self.ecx.frame_idx() {
988988
write!(fmt, " ({} frames up)", self.ecx.frame_idx() - frame)?;
989989
}
990-
write!(fmt, ":")?;
990+
fmt.write_str(":")?;
991991

992992
match self.ecx.stack()[frame].locals[local].value {
993-
LocalValue::Dead => write!(fmt, " is dead")?,
993+
LocalValue::Dead => fmt.write_str(" is dead")?,
994994
LocalValue::Live(Operand::Immediate(Immediate::Uninit)) => {
995-
write!(fmt, " is uninitialized")?
995+
fmt.write_str(" is uninitialized")?
996996
}
997997
LocalValue::Live(Operand::Indirect(mplace)) => {
998998
write!(

compiler/rustc_const_eval/src/interpret/memory.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ impl<T: MayLeak> MayLeak for MemoryKind<T> {
5050
impl<T: fmt::Display> fmt::Display for MemoryKind<T> {
5151
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5252
match self {
53-
MemoryKind::Stack => write!(f, "stack variable"),
54-
MemoryKind::CallerLocation => write!(f, "caller location"),
53+
MemoryKind::Stack => f.write_str("stack variable"),
54+
MemoryKind::CallerLocation => f.write_str("caller location"),
5555
MemoryKind::Machine(m) => write!(f, "{}", m),
5656
}
5757
}
@@ -893,7 +893,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> std::fmt::Debug for DumpAllocs<'a,
893893
// global alloc
894894
match self.ecx.tcx.try_get_global_alloc(id) {
895895
Some(GlobalAlloc::Memory(alloc)) => {
896-
write!(fmt, " (unchanged global, ")?;
896+
fmt.write_str(" (unchanged global, ")?;
897897
write_allocation_track_relocs(
898898
&mut *fmt,
899899
*self.ecx.tcx,
@@ -914,7 +914,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> std::fmt::Debug for DumpAllocs<'a,
914914
write!(fmt, " (static: {})", self.ecx.tcx.def_path_str(did))?;
915915
}
916916
None => {
917-
write!(fmt, " (deallocated)")?;
917+
fmt.write_str(" (deallocated)")?;
918918
}
919919
}
920920
}

compiler/rustc_driver_impl/src/args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub enum Error {
4141
impl fmt::Display for Error {
4242
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
4343
match self {
44-
Error::Utf8Error(None) => write!(fmt, "Utf8 error"),
44+
Error::Utf8Error(None) => fmt.write_str("Utf8 error"),
4545
Error::Utf8Error(Some(path)) => write!(fmt, "Utf8 error in {path}"),
4646
Error::IOError(path, err) => write!(fmt, "IO Error: {path}: {err}"),
4747
}

compiler/rustc_error_messages/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ impl fmt::Display for TranslationBundleError {
7474
write!(f, "could not parse ftl file: {}", e)
7575
}
7676
TranslationBundleError::AddResource(e) => write!(f, "failed to add resource: {}", e),
77-
TranslationBundleError::MissingLocale => write!(f, "missing locale directory"),
77+
TranslationBundleError::MissingLocale => f.write_str("missing locale directory"),
7878
TranslationBundleError::ReadLocalesDir(e) => {
7979
write!(f, "could not read locales dir: {}", e)
8080
}
8181
TranslationBundleError::ReadLocalesDirEntry(e) => {
8282
write!(f, "could not read locales dir entry: {}", e)
8383
}
8484
TranslationBundleError::LocaleIsNotDir => {
85-
write!(f, "`$sysroot/share/locales/$locale` is not a directory")
85+
f.write_str("`$sysroot/share/locales/$locale` is not a directory")
8686
}
8787
}
8888
}

compiler/rustc_expand/src/mbe/macro_parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl Display for MatcherLoc {
157157
if let Some(kind) = kind {
158158
write!(f, ":{}", kind)?;
159159
}
160-
write!(f, "`")?;
160+
f.write_str("`")?;
161161
Ok(())
162162
}
163163
MatcherLoc::Eof => f.write_str("end of macro"),

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl std::fmt::Debug for AttributeGate {
7272
Self::Gated(ref stab, name, expl, _) => {
7373
write!(fmt, "Gated({stab:?}, {name}, {expl})")
7474
}
75-
Self::Ungated => write!(fmt, "Ungated"),
75+
Self::Ungated => fmt.write_str("Ungated"),
7676
}
7777
}
7878
}

compiler/rustc_feature/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ pub enum State {
3838
impl fmt::Debug for State {
3939
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
4040
match self {
41-
State::Accepted { .. } => write!(f, "accepted"),
42-
State::Active { .. } => write!(f, "active"),
43-
State::Removed { .. } => write!(f, "removed"),
44-
State::Stabilized { .. } => write!(f, "stabilized"),
41+
State::Accepted { .. } => f.write_str("accepted"),
42+
State::Active { .. } => f.write_str("active"),
43+
State::Removed { .. } => f.write_str("removed"),
44+
State::Stabilized { .. } => f.write_str("stabilized"),
4545
}
4646
}
4747
}

0 commit comments

Comments
 (0)