We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2337ab5 commit 9919a83Copy full SHA for 9919a83
alloc/src/collections/btree/map/tests.rs
@@ -1796,18 +1796,18 @@ fn test_ord_absence() {
1796
}
1797
1798
fn map_debug<K: Debug>(mut map: BTreeMap<K, ()>) {
1799
- format!("{map:?}");
1800
- format!("{:?}", map.iter());
1801
- format!("{:?}", map.iter_mut());
1802
- format!("{:?}", map.keys());
1803
- format!("{:?}", map.values());
1804
- format!("{:?}", map.values_mut());
+ let _ = format!("{map:?}");
+ let _ = format!("{:?}", map.iter());
+ let _ = format!("{:?}", map.iter_mut());
+ let _ = format!("{:?}", map.keys());
+ let _ = format!("{:?}", map.values());
+ let _ = format!("{:?}", map.values_mut());
1805
if true {
1806
- format!("{:?}", map.into_iter());
+ let _ = format!("{:?}", map.into_iter());
1807
} else if true {
1808
- format!("{:?}", map.into_keys());
+ let _ = format!("{:?}", map.into_keys());
1809
} else {
1810
- format!("{:?}", map.into_values());
+ let _ = format!("{:?}", map.into_values());
1811
1812
1813
alloc/src/collections/btree/set/tests.rs
@@ -705,9 +705,9 @@ fn test_ord_absence() {
705
706
707
fn set_debug<K: Debug>(set: BTreeSet<K>) {
708
- format!("{set:?}");
709
- format!("{:?}", set.iter());
710
- format!("{:?}", set.into_iter());
+ let _ = format!("{set:?}");
+ let _ = format!("{:?}", set.iter());
+ let _ = format!("{:?}", set.into_iter());
711
712
713
fn set_clone<K: Clone>(mut set: BTreeSet<K>) {
alloc/src/fmt.rs
@@ -12,6 +12,7 @@
12
//! Some examples of the [`format!`] extension are:
13
//!
14
//! ```
15
+//! # #![allow(unused_must_use)]
16
//! format!("Hello"); // => "Hello"
17
//! format!("Hello, {}!", "world"); // => "Hello, world!"
18
//! format!("The number is {}", 1); // => "The number is 1"
@@ -50,6 +51,7 @@
50
51
//! the iterator advances. This leads to behavior like this:
52
53
54
55
//! format!("{1} {} {0} {}", 1, 2); // => "2 1 1 2"
56
57
@@ -77,6 +79,7 @@
77
79
//! For example, the following [`format!`] expressions all use named arguments:
78
80
81
82
83
//! format!("{argument}", argument = "test"); // => "test"
84
//! format!("{name} {}", 1, name = 2); // => "2 1"
85
//! format!("{a} {c} {b}", a="a", b='b', c=3); // => "a 3 b"
@@ -86,6 +89,7 @@
86
89
//! reference a variable with that name in the current scope.
87
90
88
91
92
93
//! let argument = 2 + 2;
94
//! format!("{argument}"); // => "4"
95
alloc/src/lib.rs
@@ -256,6 +256,7 @@ pub mod vec;
256
#[unstable(feature = "liballoc_internals", issue = "none", reason = "implementation detail")]
257
pub mod __export {
258
pub use core::format_args;
259
+ pub use core::hint::must_use;
260
261
262
#[cfg(test)]
alloc/src/macros.rs
@@ -111,6 +111,7 @@ macro_rules! vec {
111
/// # Examples
112
///
113
/// ```
114
+/// # #![allow(unused_must_use)]
115
/// format!("test"); // => "test"
116
/// format!("hello {}", "world!"); // => "hello world!"
117
/// format!("x = {}, y = {val}", 10, val = 30); // => "x = 10, y = 30"
@@ -119,10 +120,13 @@ macro_rules! vec {
119
120
121
#[macro_export]
122
#[stable(feature = "rust1", since = "1.0.0")]
123
+#[allow_internal_unstable(hint_must_use, liballoc_internals)]
124
#[cfg_attr(not(test), rustc_diagnostic_item = "format_macro")]
125
macro_rules! format {
- ($($arg:tt)*) => {{
- let res = $crate::fmt::format($crate::__export::format_args!($($arg)*));
126
- res
127
- }}
+ ($($arg:tt)*) => {
+ $crate::__export::must_use({
128
+ let res = $crate::fmt::format($crate::__export::format_args!($($arg)*));
129
+ res
130
+ })
131
+ }
132
alloc/tests/fmt.rs
@@ -217,19 +217,19 @@ fn test_format_macro_interface() {
217
218
// make sure that format! doesn't move out of local variables
219
let a = Box::new(3);
220
- format!("{a}");
221
+ let _ = format!("{a}");
222
223
// make sure that format! doesn't cause spurious unused-unsafe warnings when
224
// it's inside of an outer unsafe block
225
unsafe {
226
let a: isize = ::std::mem::transmute(3_usize);
227
228
229
230
// test that trailing commas are acceptable
231
- format!("{}", "test",);
232
- format!("{foo}", foo = "test",);
+ let _ = format!("{}", "test",);
+ let _ = format!("{foo}", foo = "test",);
233
234
235
// Basic test to make sure that we can invoke the `write!` macro with an
core/tests/fmt/builders.rs
@@ -441,7 +441,7 @@ mod debug_map {
441
442
443
444
- format!("{Foo:?}");
+ let _ = format!("{Foo:?}");
445
446
447
#[test]
@@ -455,7 +455,7 @@ mod debug_map {
455
456
457
458
459
460
461
@@ -469,7 +469,7 @@ mod debug_map {
469
470
471
472
473
474
475
0 commit comments