Skip to content

Commit 27c50a0

Browse files
committed
Remove all no longer necessary uses of fmt::Write.
1 parent df0a459 commit 27c50a0

File tree

28 files changed

+8
-96
lines changed

28 files changed

+8
-96
lines changed

compiler/rustc_ast/src/ast.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2003,7 +2003,6 @@ impl fmt::Display for InlineAsmTemplatePiece {
20032003
impl InlineAsmTemplatePiece {
20042004
/// Rebuilds the asm template string from its pieces.
20052005
pub fn to_string(s: &[Self]) -> String {
2006-
use fmt::Write;
20072006
let mut out = String::new();
20082007
for p in s.iter() {
20092008
let _ = write!(out, "{}", p);

compiler/rustc_ast_lowering/src/expr.rs

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned};
1414
use rustc_span::symbol::{sym, Ident, Symbol};
1515
use rustc_target::asm;
1616
use std::collections::hash_map::Entry;
17-
use std::fmt::Write;
1817

1918
impl<'hir> LoweringContext<'_, 'hir> {
2019
fn lower_exprs(&mut self, exprs: &[AstP<Expr>]) -> &'hir [hir::Expr<'hir>] {

compiler/rustc_builtin_macros/src/format_foreign.rs

-3
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ pub mod printf {
7171
/// Returns `None` in cases where the `printf` directive does not have an exact Rust
7272
/// equivalent, rather than guessing.
7373
pub fn translate(&self) -> Option<String> {
74-
use std::fmt::Write;
75-
7674
let (c_alt, c_zero, c_left, c_plus) = {
7775
let mut c_alt = false;
7876
let mut c_zero = false;
@@ -245,7 +243,6 @@ pub mod printf {
245243
}
246244

247245
fn translate(&self, s: &mut String) -> std::fmt::Result {
248-
use std::fmt::Write;
249246
match *self {
250247
Num::Num(n) => write!(s, "{}", n),
251248
Num::Arg(n) => {

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use tracing::debug;
4545

4646
use libc::{c_longlong, c_uint};
4747
use std::collections::hash_map::Entry;
48-
use std::fmt::{self, Write};
48+
use std::fmt;
4949
use std::hash::{Hash, Hasher};
5050
use std::iter;
5151
use std::path::{Path, PathBuf};

compiler/rustc_codegen_llvm/src/type_of.rs

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ use rustc_target::abi::{Int, Pointer, F32, F64};
1111
use rustc_target::abi::{LayoutOf, PointeeInfo, Scalar, Size, TyAndLayoutMethods, Variants};
1212
use tracing::debug;
1313

14-
use std::fmt::Write;
15-
1614
fn uncached_llvm_type<'a, 'tcx>(
1715
cx: &CodegenCx<'a, 'tcx>,
1816
layout: TyAndLayout<'tcx>,

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ use rustc_hir as hir;
55
use rustc_hir::def_id::DefId;
66
use rustc_middle::ty::{self, subst::SubstsRef, Ty, TyCtxt};
77

8-
use std::fmt::Write;
9-
108
// Compute the name of the type as it should be stored in debuginfo. Does not do
119
// any caching, i.e., calling the function twice with the same type will also do
1210
// the work twice. The `qualified` parameter only affects the first level of the

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_middle::ty::print::{FmtPrinter, Print, RegionHighlightMode};
1111
use rustc_middle::ty::subst::SubstsRef;
1212
use rustc_middle::ty::{self, TyCtxt};
1313

14-
use std::fmt::{self, Write};
14+
use std::fmt;
1515

1616
impl NiceRegionError<'me, 'tcx> {
1717
/// When given a `ConcreteFailure` for a function with arguments containing a named region and

compiler/rustc_lint/src/builtin.rs

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ use rustc_trait_selection::traits::misc::can_type_implement_copy;
5454

5555
use crate::nonstandard_style::{method_context, MethodLateContext};
5656

57-
use std::fmt::Write;
5857
use tracing::{debug, trace};
5958

6059
// hardwired lints from librustc_middle

compiler/rustc_middle/src/mir/mono.rs

-2
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,6 @@ impl CodegenUnitNameBuilder<'tcx> {
453453
C: fmt::Display,
454454
S: fmt::Display,
455455
{
456-
use std::fmt::Write;
457-
458456
let mut cgu_name = String::with_capacity(64);
459457

460458
// Start out with the crate name and disambiguator

compiler/rustc_mir/src/interpret/validity.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
//! to be const-safe.
66
77
use std::convert::TryFrom;
8-
use std::fmt::Write;
98
use std::num::NonZeroUsize;
109
use std::ops::RangeInclusive;
1110

compiler/rustc_mir/src/util/pretty.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::collections::BTreeSet;
2-
use std::fmt::Write as _;
32
use std::fmt::{Debug, Display};
43
use std::fs;
54
use std::io::{self, Write};

compiler/rustc_symbol_mangling/src/v0.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst};
99
use rustc_middle::ty::{self, Instance, Ty, TyCtxt, TypeFoldable};
1010
use rustc_target::spec::abi::Abi;
1111

12-
use std::fmt::Write;
1312
use std::ops::Range;
1413

1514
pub(super) fn mangle(

compiler/rustc_trait_selection/src/traits/specialize/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,6 @@ fn report_conflicting_impls(
462462
/// Recovers the "impl X for Y" signature from `impl_def_id` and returns it as a
463463
/// string.
464464
fn to_pretty_impl_header(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Option<String> {
465-
use std::fmt::Write;
466-
467465
let trait_ref = tcx.impl_trait_ref(impl_def_id)?;
468466
let mut w = "impl".to_owned();
469467

library/alloc/src/string.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2206,7 +2206,6 @@ impl<T: fmt::Display + ?Sized> ToString for T {
22062206
// to try to remove it.
22072207
#[inline]
22082208
default fn to_string(&self) -> String {
2209-
use fmt::Write;
22102209
let mut buf = String::new();
22112210
buf.write_fmt(format_args!("{}", self))
22122211
.expect("a Display implementation returned an error unexpectedly");

library/core/src/fmt/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1048,11 +1048,8 @@ pub trait UpperExp {
10481048
/// Please note that using [`write!`] might be preferable. Example:
10491049
///
10501050
/// ```
1051-
/// use std::fmt::Write;
1052-
///
10531051
/// let mut output = String::new();
1054-
/// write!(&mut output, "Hello {}!", "world")
1055-
/// .expect("Error occurred while trying to write in String");
1052+
/// write!(&mut output, "Hello {}!", "world");
10561053
/// assert_eq!(output, "Hello world!");
10571054
/// ```
10581055
///

library/core/src/macros/mod.rs

-38
Original file line numberDiff line numberDiff line change
@@ -348,25 +348,6 @@ macro_rules! r#try {
348348
/// }
349349
/// ```
350350
///
351-
/// A module can import both `std::fmt::Write` and `std::io::Write` and call `write!` on objects
352-
/// implementing either, as objects do not typically implement both. However, the module must
353-
/// import the traits qualified so their names do not conflict:
354-
///
355-
/// ```
356-
/// use std::fmt::Write as FmtWrite;
357-
/// use std::io::Write as IoWrite;
358-
///
359-
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
360-
/// let mut s = String::new();
361-
/// let mut v = Vec::new();
362-
///
363-
/// write!(&mut s, "{} {}", "abc", 123)?; // uses fmt::Write::write_fmt
364-
/// write!(&mut v, "s = {:?}", s)?; // uses io::Write::write_fmt
365-
/// assert_eq!(v, b"s = \"abc 123\"");
366-
/// Ok(())
367-
/// }
368-
/// ```
369-
///
370351
/// Note: This macro can be used in `no_std` setups as well.
371352
/// In a `no_std` setup you are responsible for the implementation details of the components.
372353
///
@@ -416,25 +397,6 @@ macro_rules! write {
416397
/// Ok(())
417398
/// }
418399
/// ```
419-
///
420-
/// A module can import both `std::fmt::Write` and `std::io::Write` and call `write!` on objects
421-
/// implementing either, as objects do not typically implement both. However, the module must
422-
/// import the traits qualified so their names do not conflict:
423-
///
424-
/// ```
425-
/// use std::fmt::Write as FmtWrite;
426-
/// use std::io::Write as IoWrite;
427-
///
428-
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
429-
/// let mut s = String::new();
430-
/// let mut v = Vec::new();
431-
///
432-
/// writeln!(&mut s, "{} {}", "abc", 123)?; // uses fmt::Write::write_fmt
433-
/// writeln!(&mut v, "s = {:?}", s)?; // uses io::Write::write_fmt
434-
/// assert_eq!(v, b"s = \"abc 123\\n\"\n");
435-
/// Ok(())
436-
/// }
437-
/// ```
438400
#[macro_export]
439401
#[stable(feature = "rust1", since = "1.0.0")]
440402
#[allow_internal_unstable(format_args_nl)]

library/core/tests/fmt/builders.rs

-2
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,6 @@ mod debug_map {
398398
#[test]
399399
fn test_entry_err() {
400400
// Ensure errors in a map entry don't trigger panics (#65231)
401-
use std::fmt::Write;
402-
403401
struct ErrorFmt;
404402

405403
impl fmt::Debug for ErrorFmt {

library/std/src/panicking.rs

-2
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,6 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
452452
}
453453

454454
fn fill(&mut self) -> &mut String {
455-
use crate::fmt::Write;
456-
457455
let inner = self.inner;
458456
// Lazily, the first time this gets called, run the actual string formatting.
459457
self.string.get_or_insert_with(|| {

library/test/src/bench.rs

-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ pub struct BenchSamples {
5555
}
5656

5757
pub fn fmt_bench_samples(bs: &BenchSamples) -> String {
58-
use std::fmt::Write;
5958
let mut output = String::new();
6059

6160
let median = bs.ns_iter_summ.median as usize;
@@ -76,7 +75,6 @@ pub fn fmt_bench_samples(bs: &BenchSamples) -> String {
7675

7776
// Format a number with thousands separators
7877
fn fmt_thousands_sep(mut n: usize, sep: char) -> String {
79-
use std::fmt::Write;
8078
let mut output = String::new();
8179
let mut trailing = false;
8280
for &pow in &[9, 6, 3, 0] {

src/bootstrap/setup.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::{t, VERSION};
2+
#[allow(unused_imports)]
23
use std::fmt::Write as _;
34
use std::path::{Path, PathBuf};
45
use std::process::Command;

src/librustdoc/html/format.rs

-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ impl Buffer {
9292
// the fmt::Result return type imposed by fmt::Write (and avoiding the trait
9393
// import).
9494
crate fn write_fmt(&mut self, v: fmt::Arguments<'_>) {
95-
use fmt::Write;
9695
self.buffer.write_fmt(v).unwrap();
9796
}
9897

src/librustdoc/html/highlight.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
use crate::html::escape::Escape;
99

10-
use std::fmt::{Display, Write};
10+
use std::fmt::Display;
1111
use std::iter::Peekable;
1212

1313
use rustc_lexer::{LiteralKind, TokenKind};

src/librustdoc/html/markdown.rs

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use rustc_span::Span;
2929
use std::borrow::Cow;
3030
use std::collections::VecDeque;
3131
use std::default::Default;
32-
use std::fmt::Write;
3332
use std::ops::Range;
3433
use std::str;
3534

src/librustdoc/html/render/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use std::cmp::Ordering;
3636
use std::collections::{BTreeMap, VecDeque};
3737
use std::default::Default;
3838
use std::ffi::OsStr;
39-
use std::fmt::{self, Write};
39+
use std::fmt;
4040
use std::fs::{self, File};
4141
use std::io::prelude::*;
4242
use std::io::{self, BufReader};

src/test/ui/impl-trait/example-calendar.rs

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
//!
1212
//! Originally converted to Rust by [Daniel Keep](https://github.com/DanielKeep).
1313
14-
use std::fmt::Write;
15-
1614
/// Date representation.
1715
#[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
1816
struct NaiveDate(i32, u32, u32);

src/test/ui/macros/must-use-in-macro-55516.rs

-10
This file was deleted.

src/test/ui/macros/must-use-in-macro-55516.stderr

-12
This file was deleted.

src/tools/compiletest/src/runtest.rs

+2
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ pub fn make_diff(expected: &str, actual: &str, context_size: usize) -> Vec<Misma
179179
}
180180

181181
fn write_diff(expected: &str, actual: &str, context_size: usize) -> String {
182+
#[allow(unused_imports)]
182183
use std::fmt::Write;
183184
let mut output = String::new();
184185
let diff_results = make_diff(expected, actual, context_size);
@@ -3300,6 +3301,7 @@ impl<'test> TestCx<'test> {
33003301
let after = self.normalize_output(&after, &[]);
33013302
let mut dumped_string = String::new();
33023303
for result in diff::lines(&before, &after) {
3304+
#[allow(unused_imports)]
33033305
use std::fmt::Write;
33043306
match result {
33053307
diff::Result::Left(s) => writeln!(dumped_string, "- {}", s).unwrap(),

0 commit comments

Comments
 (0)