Skip to content

Commit

Permalink
Rollup merge of rust-lang#107180 - nvzqz:rm-fmt-ref, r=joshtriplett
Browse files Browse the repository at this point in the history
Remove unnecessary `&format!`

These were likely from before the `PartialEq<str>` impl for `&String`.
  • Loading branch information
matthiaskrgr authored Jan 22, 2023
2 parents 8a22521 + 734a913 commit 2f7a3a1
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 41 deletions.
60 changes: 30 additions & 30 deletions library/core/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1355,11 +1355,11 @@ impl<'a> Formatter<'a> {
/// }
/// }
///
/// assert_eq!(&format!("{}", Foo::new(2)), "2");
/// assert_eq!(&format!("{}", Foo::new(-1)), "-1");
/// assert_eq!(&format!("{}", Foo::new(0)), "0");
/// assert_eq!(&format!("{:#}", Foo::new(-1)), "-Foo 1");
/// assert_eq!(&format!("{:0>#8}", Foo::new(-1)), "00-Foo 1");
/// assert_eq!(format!("{}", Foo::new(2)), "2");
/// assert_eq!(format!("{}", Foo::new(-1)), "-1");
/// assert_eq!(format!("{}", Foo::new(0)), "0");
/// assert_eq!(format!("{:#}", Foo::new(-1)), "-Foo 1");
/// assert_eq!(format!("{:0>#8}", Foo::new(-1)), "00-Foo 1");
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn pad_integral(&mut self, is_nonnegative: bool, prefix: &str, buf: &str) -> Result {
Expand Down Expand Up @@ -1452,8 +1452,8 @@ impl<'a> Formatter<'a> {
/// }
/// }
///
/// assert_eq!(&format!("{Foo:<4}"), "Foo ");
/// assert_eq!(&format!("{Foo:0>4}"), "0Foo");
/// assert_eq!(format!("{Foo:<4}"), "Foo ");
/// assert_eq!(format!("{Foo:0>4}"), "0Foo");
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn pad(&mut self, s: &str) -> Result {
Expand Down Expand Up @@ -1636,8 +1636,8 @@ impl<'a> Formatter<'a> {
/// }
/// }
///
/// assert_eq!(&format!("{Foo}"), "Foo");
/// assert_eq!(&format!("{Foo:0>8}"), "Foo");
/// assert_eq!(format!("{Foo}"), "Foo");
/// assert_eq!(format!("{Foo:0>8}"), "Foo");
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn write_str(&mut self, data: &str) -> Result {
Expand All @@ -1659,8 +1659,8 @@ impl<'a> Formatter<'a> {
/// }
/// }
///
/// assert_eq!(&format!("{}", Foo(-1)), "Foo -1");
/// assert_eq!(&format!("{:0>8}", Foo(2)), "Foo 2");
/// assert_eq!(format!("{}", Foo(-1)), "Foo -1");
/// assert_eq!(format!("{:0>8}", Foo(2)), "Foo 2");
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result {
Expand Down Expand Up @@ -1703,8 +1703,8 @@ impl<'a> Formatter<'a> {
/// }
///
/// // We set alignment to the right with ">".
/// assert_eq!(&format!("{Foo:G>3}"), "GGG");
/// assert_eq!(&format!("{Foo:t>6}"), "tttttt");
/// assert_eq!(format!("{Foo:G>3}"), "GGG");
/// assert_eq!(format!("{Foo:t>6}"), "tttttt");
/// ```
#[must_use]
#[stable(feature = "fmt_flags", since = "1.5.0")]
Expand Down Expand Up @@ -1738,10 +1738,10 @@ impl<'a> Formatter<'a> {
/// }
/// }
///
/// assert_eq!(&format!("{Foo:<}"), "left");
/// assert_eq!(&format!("{Foo:>}"), "right");
/// assert_eq!(&format!("{Foo:^}"), "center");
/// assert_eq!(&format!("{Foo}"), "into the void");
/// assert_eq!(format!("{Foo:<}"), "left");
/// assert_eq!(format!("{Foo:>}"), "right");
/// assert_eq!(format!("{Foo:^}"), "center");
/// assert_eq!(format!("{Foo}"), "into the void");
/// ```
#[must_use]
#[stable(feature = "fmt_flags_align", since = "1.28.0")]
Expand All @@ -1767,16 +1767,16 @@ impl<'a> Formatter<'a> {
/// fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
/// if let Some(width) = formatter.width() {
/// // If we received a width, we use it
/// write!(formatter, "{:width$}", &format!("Foo({})", self.0), width = width)
/// write!(formatter, "{:width$}", format!("Foo({})", self.0), width = width)
/// } else {
/// // Otherwise we do nothing special
/// write!(formatter, "Foo({})", self.0)
/// }
/// }
/// }
///
/// assert_eq!(&format!("{:10}", Foo(23)), "Foo(23) ");
/// assert_eq!(&format!("{}", Foo(23)), "Foo(23)");
/// assert_eq!(format!("{:10}", Foo(23)), "Foo(23) ");
/// assert_eq!(format!("{}", Foo(23)), "Foo(23)");
/// ```
#[must_use]
#[stable(feature = "fmt_flags", since = "1.5.0")]
Expand Down Expand Up @@ -1806,8 +1806,8 @@ impl<'a> Formatter<'a> {
/// }
/// }
///
/// assert_eq!(&format!("{:.4}", Foo(23.2)), "Foo(23.2000)");
/// assert_eq!(&format!("{}", Foo(23.2)), "Foo(23.20)");
/// assert_eq!(format!("{:.4}", Foo(23.2)), "Foo(23.2000)");
/// assert_eq!(format!("{}", Foo(23.2)), "Foo(23.20)");
/// ```
#[must_use]
#[stable(feature = "fmt_flags", since = "1.5.0")]
Expand Down Expand Up @@ -1837,9 +1837,9 @@ impl<'a> Formatter<'a> {
/// }
/// }
///
/// assert_eq!(&format!("{:+}", Foo(23)), "Foo(+23)");
/// assert_eq!(&format!("{:+}", Foo(-23)), "Foo(-23)");
/// assert_eq!(&format!("{}", Foo(23)), "Foo(23)");
/// assert_eq!(format!("{:+}", Foo(23)), "Foo(+23)");
/// assert_eq!(format!("{:+}", Foo(-23)), "Foo(-23)");
/// assert_eq!(format!("{}", Foo(23)), "Foo(23)");
/// ```
#[must_use]
#[stable(feature = "fmt_flags", since = "1.5.0")]
Expand Down Expand Up @@ -1867,8 +1867,8 @@ impl<'a> Formatter<'a> {
/// }
/// }
///
/// assert_eq!(&format!("{:-}", Foo(23)), "-Foo(23)");
/// assert_eq!(&format!("{}", Foo(23)), "Foo(23)");
/// assert_eq!(format!("{:-}", Foo(23)), "-Foo(23)");
/// assert_eq!(format!("{}", Foo(23)), "Foo(23)");
/// ```
#[must_use]
#[stable(feature = "fmt_flags", since = "1.5.0")]
Expand All @@ -1895,8 +1895,8 @@ impl<'a> Formatter<'a> {
/// }
/// }
///
/// assert_eq!(&format!("{:#}", Foo(23)), "Foo(23)");
/// assert_eq!(&format!("{}", Foo(23)), "23");
/// assert_eq!(format!("{:#}", Foo(23)), "Foo(23)");
/// assert_eq!(format!("{}", Foo(23)), "23");
/// ```
#[must_use]
#[stable(feature = "fmt_flags", since = "1.5.0")]
Expand All @@ -1922,7 +1922,7 @@ impl<'a> Formatter<'a> {
/// }
/// }
///
/// assert_eq!(&format!("{:04}", Foo(23)), "23");
/// assert_eq!(format!("{:04}", Foo(23)), "23");
/// ```
#[must_use]
#[stable(feature = "fmt_flags", since = "1.5.0")]
Expand Down
2 changes: 1 addition & 1 deletion library/core/tests/num/dec2flt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ macro_rules! test_literal {
for input in inputs {
assert_eq!(input.parse(), Ok(x64));
assert_eq!(input.parse(), Ok(x32));
let neg_input = &format!("-{input}");
let neg_input = format!("-{input}");
assert_eq!(neg_input.parse(), Ok(-x64));
assert_eq!(neg_input.parse(), Ok(-x32));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn dot(x: &[f64], y: &[f64]) -> f64 {
#[cfg(test)]
#[test]
fn test() {
assert_eq!(&format!("{:.9}", spectral_norm(100)), "1.274219991");
assert_eq!(format!("{:.9}", spectral_norm(100)), "1.274219991");
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/io/error/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,5 @@ fn test_std_io_error_downcast() {
let io_error = io_error.downcast::<E>().unwrap_err();

assert_eq!(SIMPLE_MESSAGE.kind, io_error.kind());
assert_eq!(SIMPLE_MESSAGE.message, &*format!("{io_error}"));
assert_eq!(SIMPLE_MESSAGE.message, format!("{io_error}"));
}
8 changes: 4 additions & 4 deletions library/std/src/net/ip_addr/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ fn ipv4_addr_to_string() {
assert_eq!(Ipv4Addr::new(127, 127, 127, 127).to_string(), "127.127.127.127");

// Test padding
assert_eq!(&format!("{:16}", Ipv4Addr::new(1, 1, 1, 1)), "1.1.1.1 ");
assert_eq!(&format!("{:>16}", Ipv4Addr::new(1, 1, 1, 1)), " 1.1.1.1");
assert_eq!(format!("{:16}", Ipv4Addr::new(1, 1, 1, 1)), "1.1.1.1 ");
assert_eq!(format!("{:>16}", Ipv4Addr::new(1, 1, 1, 1)), " 1.1.1.1");
}

#[test]
Expand All @@ -148,8 +148,8 @@ fn ipv6_addr_to_string() {
"1111:2222:3333:4444:5555:6666:7777:8888"
);
// padding
assert_eq!(&format!("{:20}", Ipv6Addr::new(1, 2, 3, 4, 5, 6, 7, 8)), "1:2:3:4:5:6:7:8 ");
assert_eq!(&format!("{:>20}", Ipv6Addr::new(1, 2, 3, 4, 5, 6, 7, 8)), " 1:2:3:4:5:6:7:8");
assert_eq!(format!("{:20}", Ipv6Addr::new(1, 2, 3, 4, 5, 6, 7, 8)), "1:2:3:4:5:6:7:8 ");
assert_eq!(format!("{:>20}", Ipv6Addr::new(1, 2, 3, 4, 5, 6, 7, 8)), " 1:2:3:4:5:6:7:8");

// reduce a single run of zeros
assert_eq!(
Expand Down
8 changes: 4 additions & 4 deletions library/std/src/net/socket_addr/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ fn ipv4_socket_addr_to_string() {

// Test padding.
assert_eq!(
&format!("{:16}", SocketAddrV4::new(Ipv4Addr::new(1, 1, 1, 1), 53)),
format!("{:16}", SocketAddrV4::new(Ipv4Addr::new(1, 1, 1, 1), 53)),
"1.1.1.1:53 "
);
assert_eq!(
&format!("{:>16}", SocketAddrV4::new(Ipv4Addr::new(1, 1, 1, 1), 53)),
format!("{:>16}", SocketAddrV4::new(Ipv4Addr::new(1, 1, 1, 1), 53)),
" 1.1.1.1:53"
);
}
Expand Down Expand Up @@ -111,11 +111,11 @@ fn ipv6_socket_addr_to_string() {

// Test padding.
assert_eq!(
&format!("{:22}", SocketAddrV6::new(Ipv6Addr::new(1, 2, 3, 4, 5, 6, 7, 8), 9, 0, 0)),
format!("{:22}", SocketAddrV6::new(Ipv6Addr::new(1, 2, 3, 4, 5, 6, 7, 8), 9, 0, 0)),
"[1:2:3:4:5:6:7:8]:9 "
);
assert_eq!(
&format!("{:>22}", SocketAddrV6::new(Ipv6Addr::new(1, 2, 3, 4, 5, 6, 7, 8), 9, 0, 0)),
format!("{:>22}", SocketAddrV6::new(Ipv6Addr::new(1, 2, 3, 4, 5, 6, 7, 8), 9, 0, 0)),
" [1:2:3:4:5:6:7:8]:9"
);
}
Expand Down

0 comments on commit 2f7a3a1

Please sign in to comment.