Skip to content

Commit 413e4b4

Browse files
authored
Rollup merge of rust-lang#89797 - jkugelman:must-use-is_condition-tests, r=joshtriplett
Add #[must_use] to is_condition tests I threw in `std::path::Path::has_root` for funsies. A continuation of rust-lang#89718. Parent issue: rust-lang#89692 r? ``@joshtriplett``
2 parents efad99d + 01b439e commit 413e4b4

File tree

6 files changed

+47
-0
lines changed

6 files changed

+47
-0
lines changed

Diff for: library/std/src/fs.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,7 @@ impl Metadata {
10051005
/// Ok(())
10061006
/// }
10071007
/// ```
1008+
#[must_use]
10081009
#[stable(feature = "rust1", since = "1.0.0")]
10091010
pub fn is_dir(&self) -> bool {
10101011
self.file_type().is_dir()
@@ -1033,6 +1034,7 @@ impl Metadata {
10331034
/// Ok(())
10341035
/// }
10351036
/// ```
1037+
#[must_use]
10361038
#[stable(feature = "rust1", since = "1.0.0")]
10371039
pub fn is_file(&self) -> bool {
10381040
self.file_type().is_file()
@@ -1059,6 +1061,7 @@ impl Metadata {
10591061
/// Ok(())
10601062
/// }
10611063
/// ```
1064+
#[must_use]
10621065
#[unstable(feature = "is_symlink", issue = "85748")]
10631066
pub fn is_symlink(&self) -> bool {
10641067
self.file_type().is_symlink()
@@ -1307,6 +1310,7 @@ impl FileType {
13071310
/// Ok(())
13081311
/// }
13091312
/// ```
1313+
#[must_use]
13101314
#[stable(feature = "file_type", since = "1.1.0")]
13111315
pub fn is_dir(&self) -> bool {
13121316
self.0.is_dir()
@@ -1339,6 +1343,7 @@ impl FileType {
13391343
/// Ok(())
13401344
/// }
13411345
/// ```
1346+
#[must_use]
13421347
#[stable(feature = "file_type", since = "1.1.0")]
13431348
pub fn is_file(&self) -> bool {
13441349
self.0.is_file()
@@ -1374,6 +1379,7 @@ impl FileType {
13741379
/// Ok(())
13751380
/// }
13761381
/// ```
1382+
#[must_use]
13771383
#[stable(feature = "file_type", since = "1.1.0")]
13781384
pub fn is_symlink(&self) -> bool {
13791385
self.0.is_symlink()

Diff for: library/std/src/net/addr.rs

+2
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ impl SocketAddr {
232232
/// assert_eq!(socket.is_ipv4(), true);
233233
/// assert_eq!(socket.is_ipv6(), false);
234234
/// ```
235+
#[must_use]
235236
#[stable(feature = "sockaddr_checker", since = "1.16.0")]
236237
#[rustc_const_unstable(feature = "const_socketaddr", issue = "82485")]
237238
pub const fn is_ipv4(&self) -> bool {
@@ -253,6 +254,7 @@ impl SocketAddr {
253254
/// assert_eq!(socket.is_ipv4(), false);
254255
/// assert_eq!(socket.is_ipv6(), true);
255256
/// ```
257+
#[must_use]
256258
#[stable(feature = "sockaddr_checker", since = "1.16.0")]
257259
#[rustc_const_unstable(feature = "const_socketaddr", issue = "82485")]
258260
pub const fn is_ipv6(&self) -> bool {

Diff for: library/std/src/net/ip.rs

+29
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ impl IpAddr {
233233
/// ```
234234
#[rustc_const_stable(feature = "const_ip", since = "1.50.0")]
235235
#[stable(feature = "ip_shared", since = "1.12.0")]
236+
#[must_use]
236237
#[inline]
237238
pub const fn is_unspecified(&self) -> bool {
238239
match self {
@@ -256,6 +257,7 @@ impl IpAddr {
256257
/// ```
257258
#[rustc_const_stable(feature = "const_ip", since = "1.50.0")]
258259
#[stable(feature = "ip_shared", since = "1.12.0")]
260+
#[must_use]
259261
#[inline]
260262
pub const fn is_loopback(&self) -> bool {
261263
match self {
@@ -281,6 +283,7 @@ impl IpAddr {
281283
/// ```
282284
#[rustc_const_unstable(feature = "const_ip", issue = "76205")]
283285
#[unstable(feature = "ip", issue = "27709")]
286+
#[must_use]
284287
#[inline]
285288
pub const fn is_global(&self) -> bool {
286289
match self {
@@ -304,6 +307,7 @@ impl IpAddr {
304307
/// ```
305308
#[rustc_const_stable(feature = "const_ip", since = "1.50.0")]
306309
#[stable(feature = "ip_shared", since = "1.12.0")]
310+
#[must_use]
307311
#[inline]
308312
pub const fn is_multicast(&self) -> bool {
309313
match self {
@@ -332,6 +336,7 @@ impl IpAddr {
332336
/// ```
333337
#[rustc_const_unstable(feature = "const_ip", issue = "76205")]
334338
#[unstable(feature = "ip", issue = "27709")]
339+
#[must_use]
335340
#[inline]
336341
pub const fn is_documentation(&self) -> bool {
337342
match self {
@@ -356,6 +361,7 @@ impl IpAddr {
356361
/// assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0x2, 0, 0, 0, 0, 0, 0)).is_benchmarking(), true);
357362
/// ```
358363
#[unstable(feature = "ip", issue = "27709")]
364+
#[must_use]
359365
#[inline]
360366
pub const fn is_benchmarking(&self) -> bool {
361367
match self {
@@ -379,6 +385,7 @@ impl IpAddr {
379385
/// ```
380386
#[rustc_const_stable(feature = "const_ip", since = "1.50.0")]
381387
#[stable(feature = "ipaddr_checker", since = "1.16.0")]
388+
#[must_use]
382389
#[inline]
383390
pub const fn is_ipv4(&self) -> bool {
384391
matches!(self, IpAddr::V4(_))
@@ -399,6 +406,7 @@ impl IpAddr {
399406
/// ```
400407
#[rustc_const_stable(feature = "const_ip", since = "1.50.0")]
401408
#[stable(feature = "ipaddr_checker", since = "1.16.0")]
409+
#[must_use]
402410
#[inline]
403411
pub const fn is_ipv6(&self) -> bool {
404412
matches!(self, IpAddr::V6(_))
@@ -527,6 +535,7 @@ impl Ipv4Addr {
527535
/// ```
528536
#[rustc_const_stable(feature = "const_ipv4", since = "1.32.0")]
529537
#[stable(feature = "ip_shared", since = "1.12.0")]
538+
#[must_use]
530539
#[inline]
531540
pub const fn is_unspecified(&self) -> bool {
532541
self.inner.s_addr == 0
@@ -548,6 +557,7 @@ impl Ipv4Addr {
548557
/// ```
549558
#[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")]
550559
#[stable(since = "1.7.0", feature = "ip_17")]
560+
#[must_use]
551561
#[inline]
552562
pub const fn is_loopback(&self) -> bool {
553563
self.octets()[0] == 127
@@ -578,6 +588,7 @@ impl Ipv4Addr {
578588
/// ```
579589
#[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")]
580590
#[stable(since = "1.7.0", feature = "ip_17")]
591+
#[must_use]
581592
#[inline]
582593
pub const fn is_private(&self) -> bool {
583594
match self.octets() {
@@ -605,6 +616,7 @@ impl Ipv4Addr {
605616
/// ```
606617
#[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")]
607618
#[stable(since = "1.7.0", feature = "ip_17")]
619+
#[must_use]
608620
#[inline]
609621
pub const fn is_link_local(&self) -> bool {
610622
matches!(self.octets(), [169, 254, ..])
@@ -680,6 +692,7 @@ impl Ipv4Addr {
680692
/// ```
681693
#[rustc_const_unstable(feature = "const_ipv4", issue = "76205")]
682694
#[unstable(feature = "ip", issue = "27709")]
695+
#[must_use]
683696
#[inline]
684697
pub const fn is_global(&self) -> bool {
685698
// check if this address is 192.0.0.9 or 192.0.0.10. These addresses are the only two
@@ -720,6 +733,7 @@ impl Ipv4Addr {
720733
/// ```
721734
#[rustc_const_unstable(feature = "const_ipv4", issue = "76205")]
722735
#[unstable(feature = "ip", issue = "27709")]
736+
#[must_use]
723737
#[inline]
724738
pub const fn is_shared(&self) -> bool {
725739
self.octets()[0] == 100 && (self.octets()[1] & 0b1100_0000 == 0b0100_0000)
@@ -745,6 +759,7 @@ impl Ipv4Addr {
745759
/// ```
746760
#[rustc_const_unstable(feature = "const_ipv4", issue = "76205")]
747761
#[unstable(feature = "ip", issue = "27709")]
762+
#[must_use]
748763
#[inline]
749764
pub const fn is_benchmarking(&self) -> bool {
750765
self.octets()[0] == 198 && (self.octets()[1] & 0xfe) == 18
@@ -779,6 +794,7 @@ impl Ipv4Addr {
779794
/// ```
780795
#[rustc_const_unstable(feature = "const_ipv4", issue = "76205")]
781796
#[unstable(feature = "ip", issue = "27709")]
797+
#[must_use]
782798
#[inline]
783799
pub const fn is_reserved(&self) -> bool {
784800
self.octets()[0] & 240 == 240 && !self.is_broadcast()
@@ -802,6 +818,7 @@ impl Ipv4Addr {
802818
/// ```
803819
#[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")]
804820
#[stable(since = "1.7.0", feature = "ip_17")]
821+
#[must_use]
805822
#[inline]
806823
pub const fn is_multicast(&self) -> bool {
807824
self.octets()[0] >= 224 && self.octets()[0] <= 239
@@ -823,6 +840,7 @@ impl Ipv4Addr {
823840
/// ```
824841
#[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")]
825842
#[stable(since = "1.7.0", feature = "ip_17")]
843+
#[must_use]
826844
#[inline]
827845
pub const fn is_broadcast(&self) -> bool {
828846
u32::from_be_bytes(self.octets()) == u32::from_be_bytes(Self::BROADCAST.octets())
@@ -850,6 +868,7 @@ impl Ipv4Addr {
850868
/// ```
851869
#[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")]
852870
#[stable(since = "1.7.0", feature = "ip_17")]
871+
#[must_use]
853872
#[inline]
854873
pub const fn is_documentation(&self) -> bool {
855874
match self.octets() {
@@ -1291,6 +1310,7 @@ impl Ipv6Addr {
12911310
/// ```
12921311
#[rustc_const_stable(feature = "const_ipv6", since = "1.50.0")]
12931312
#[stable(since = "1.7.0", feature = "ip_17")]
1313+
#[must_use]
12941314
#[inline]
12951315
pub const fn is_unspecified(&self) -> bool {
12961316
u128::from_be_bytes(self.octets()) == u128::from_be_bytes(Ipv6Addr::UNSPECIFIED.octets())
@@ -1314,6 +1334,7 @@ impl Ipv6Addr {
13141334
/// ```
13151335
#[rustc_const_stable(feature = "const_ipv6", since = "1.50.0")]
13161336
#[stable(since = "1.7.0", feature = "ip_17")]
1337+
#[must_use]
13171338
#[inline]
13181339
pub const fn is_loopback(&self) -> bool {
13191340
u128::from_be_bytes(self.octets()) == u128::from_be_bytes(Ipv6Addr::LOCALHOST.octets())
@@ -1340,6 +1361,7 @@ impl Ipv6Addr {
13401361
/// ```
13411362
#[rustc_const_unstable(feature = "const_ipv6", issue = "76205")]
13421363
#[unstable(feature = "ip", issue = "27709")]
1364+
#[must_use]
13431365
#[inline]
13441366
pub const fn is_global(&self) -> bool {
13451367
match self.multicast_scope() {
@@ -1367,6 +1389,7 @@ impl Ipv6Addr {
13671389
/// ```
13681390
#[rustc_const_unstable(feature = "const_ipv6", issue = "76205")]
13691391
#[unstable(feature = "ip", issue = "27709")]
1392+
#[must_use]
13701393
#[inline]
13711394
pub const fn is_unique_local(&self) -> bool {
13721395
(self.segments()[0] & 0xfe00) == 0xfc00
@@ -1395,6 +1418,7 @@ impl Ipv6Addr {
13951418
/// ```
13961419
#[rustc_const_unstable(feature = "const_ipv6", issue = "76205")]
13971420
#[unstable(feature = "ip", issue = "27709")]
1421+
#[must_use]
13981422
#[inline]
13991423
pub const fn is_unicast(&self) -> bool {
14001424
!self.is_multicast()
@@ -1446,6 +1470,7 @@ impl Ipv6Addr {
14461470
/// ```
14471471
#[rustc_const_unstable(feature = "const_ipv6", issue = "76205")]
14481472
#[unstable(feature = "ip", issue = "27709")]
1473+
#[must_use]
14491474
#[inline]
14501475
pub const fn is_unicast_link_local(&self) -> bool {
14511476
(self.segments()[0] & 0xffc0) == 0xfe80
@@ -1470,6 +1495,7 @@ impl Ipv6Addr {
14701495
/// ```
14711496
#[rustc_const_unstable(feature = "const_ipv6", issue = "76205")]
14721497
#[unstable(feature = "ip", issue = "27709")]
1498+
#[must_use]
14731499
#[inline]
14741500
pub const fn is_documentation(&self) -> bool {
14751501
(self.segments()[0] == 0x2001) && (self.segments()[1] == 0xdb8)
@@ -1492,6 +1518,7 @@ impl Ipv6Addr {
14921518
/// assert_eq!(Ipv6Addr::new(0x2001, 0x2, 0, 0, 0, 0, 0, 0).is_benchmarking(), true);
14931519
/// ```
14941520
#[unstable(feature = "ip", issue = "27709")]
1521+
#[must_use]
14951522
#[inline]
14961523
pub const fn is_benchmarking(&self) -> bool {
14971524
(self.segments()[0] == 0x2001) && (self.segments()[1] == 0x2) && (self.segments()[2] == 0)
@@ -1529,6 +1556,7 @@ impl Ipv6Addr {
15291556
/// ```
15301557
#[rustc_const_unstable(feature = "const_ipv6", issue = "76205")]
15311558
#[unstable(feature = "ip", issue = "27709")]
1559+
#[must_use]
15321560
#[inline]
15331561
pub const fn is_unicast_global(&self) -> bool {
15341562
self.is_unicast()
@@ -1590,6 +1618,7 @@ impl Ipv6Addr {
15901618
/// ```
15911619
#[rustc_const_stable(feature = "const_ipv6", since = "1.50.0")]
15921620
#[stable(since = "1.7.0", feature = "ip_17")]
1621+
#[must_use]
15931622
#[inline]
15941623
pub const fn is_multicast(&self) -> bool {
15951624
(self.segments()[0] & 0xff00) == 0xff00

Diff for: library/std/src/os/unix/net/addr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ impl SocketAddr {
156156
/// Ok(())
157157
/// }
158158
/// ```
159+
#[must_use]
159160
#[stable(feature = "unix_socket", since = "1.10.0")]
160161
pub fn is_unnamed(&self) -> bool {
161162
if let AddressKind::Unnamed = self.address() { true } else { false }

Diff for: library/std/src/path.rs

+8
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ impl<'a> Prefix<'a> {
215215
/// assert!(!Disk(b'C').is_verbatim());
216216
/// ```
217217
#[inline]
218+
#[must_use]
218219
#[stable(feature = "rust1", since = "1.0.0")]
219220
pub fn is_verbatim(&self) -> bool {
220221
use self::Prefix::*;
@@ -247,6 +248,7 @@ impl<'a> Prefix<'a> {
247248
/// assert!(path::is_separator('/')); // '/' works for both Unix and Windows
248249
/// assert!(!path::is_separator('❤'));
249250
/// ```
251+
#[must_use]
250252
#[stable(feature = "rust1", since = "1.0.0")]
251253
pub fn is_separator(c: char) -> bool {
252254
c.is_ascii() && is_sep_byte(c as u8)
@@ -2016,6 +2018,7 @@ impl Path {
20162018
///
20172019
/// [`has_root`]: Path::has_root
20182020
#[stable(feature = "rust1", since = "1.0.0")]
2021+
#[must_use]
20192022
#[allow(deprecated)]
20202023
pub fn is_absolute(&self) -> bool {
20212024
if cfg!(target_os = "redox") {
@@ -2040,6 +2043,7 @@ impl Path {
20402043
///
20412044
/// [`is_absolute`]: Path::is_absolute
20422045
#[stable(feature = "rust1", since = "1.0.0")]
2046+
#[must_use]
20432047
#[inline]
20442048
pub fn is_relative(&self) -> bool {
20452049
!self.is_absolute()
@@ -2066,6 +2070,7 @@ impl Path {
20662070
/// assert!(Path::new("/etc/passwd").has_root());
20672071
/// ```
20682072
#[stable(feature = "rust1", since = "1.0.0")]
2073+
#[must_use]
20692074
#[inline]
20702075
pub fn has_root(&self) -> bool {
20712076
self.components().has_root()
@@ -2705,6 +2710,7 @@ impl Path {
27052710
/// a Unix-like system for example. See [`fs::File::open`] or
27062711
/// [`fs::OpenOptions::open`] for more information.
27072712
#[stable(feature = "path_ext", since = "1.5.0")]
2713+
#[must_use]
27082714
pub fn is_file(&self) -> bool {
27092715
fs::metadata(self).map(|m| m.is_file()).unwrap_or(false)
27102716
}
@@ -2731,6 +2737,7 @@ impl Path {
27312737
/// check errors, call [`fs::metadata`] and handle its [`Result`]. Then call
27322738
/// [`fs::Metadata::is_dir`] if it was [`Ok`].
27332739
#[stable(feature = "path_ext", since = "1.5.0")]
2740+
#[must_use]
27342741
pub fn is_dir(&self) -> bool {
27352742
fs::metadata(self).map(|m| m.is_dir()).unwrap_or(false)
27362743
}
@@ -2757,6 +2764,7 @@ impl Path {
27572764
/// assert_eq!(link_path.exists(), false);
27582765
/// ```
27592766
#[unstable(feature = "is_symlink", issue = "85748")]
2767+
#[must_use]
27602768
pub fn is_symlink(&self) -> bool {
27612769
fs::symlink_metadata(self).map(|m| m.is_symlink()).unwrap_or(false)
27622770
}

Diff for: library/std/src/sync/barrier.rs

+1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ impl BarrierWaitResult {
167167
/// println!("{:?}", barrier_wait_result.is_leader());
168168
/// ```
169169
#[stable(feature = "rust1", since = "1.0.0")]
170+
#[must_use]
170171
pub fn is_leader(&self) -> bool {
171172
self.0
172173
}

0 commit comments

Comments
 (0)