mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Rollup merge of #107180 - nvzqz:rm-fmt-ref, r=joshtriplett
Remove unnecessary `&format!` These were likely from before the `PartialEq<str>` impl for `&String`.
This commit is contained in:
commit
2f7a3a1f0a
@ -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 {
|
||||
@ -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 {
|
||||
@ -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 {
|
||||
@ -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 {
|
||||
@ -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")]
|
||||
@ -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")]
|
||||
@ -1767,7 +1767,7 @@ 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)
|
||||
@ -1775,8 +1775,8 @@ impl<'a> Formatter<'a> {
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// 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")]
|
||||
@ -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")]
|
||||
@ -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")]
|
||||
@ -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")]
|
||||
@ -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")]
|
||||
@ -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")]
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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}"));
|
||||
}
|
||||
|
@ -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]
|
||||
@ -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!(
|
||||
|
@ -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"
|
||||
);
|
||||
}
|
||||
@ -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"
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user