Skip to content

Commit

Permalink
Rollup merge of rust-lang#89797 - jkugelman:must-use-is_condition-tes…
Browse files Browse the repository at this point in the history
…ts, 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`
  • Loading branch information
matthiaskrgr authored Oct 12, 2021
2 parents eb45d11 + 01b439e commit 4c4652d
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 0 deletions.
6 changes: 6 additions & 0 deletions library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,7 @@ impl Metadata {
/// Ok(())
/// }
/// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_dir(&self) -> bool {
self.file_type().is_dir()
Expand Down Expand Up @@ -1033,6 +1034,7 @@ impl Metadata {
/// Ok(())
/// }
/// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_file(&self) -> bool {
self.file_type().is_file()
Expand All @@ -1059,6 +1061,7 @@ impl Metadata {
/// Ok(())
/// }
/// ```
#[must_use]
#[unstable(feature = "is_symlink", issue = "85748")]
pub fn is_symlink(&self) -> bool {
self.file_type().is_symlink()
Expand Down Expand Up @@ -1307,6 +1310,7 @@ impl FileType {
/// Ok(())
/// }
/// ```
#[must_use]
#[stable(feature = "file_type", since = "1.1.0")]
pub fn is_dir(&self) -> bool {
self.0.is_dir()
Expand Down Expand Up @@ -1339,6 +1343,7 @@ impl FileType {
/// Ok(())
/// }
/// ```
#[must_use]
#[stable(feature = "file_type", since = "1.1.0")]
pub fn is_file(&self) -> bool {
self.0.is_file()
Expand Down Expand Up @@ -1374,6 +1379,7 @@ impl FileType {
/// Ok(())
/// }
/// ```
#[must_use]
#[stable(feature = "file_type", since = "1.1.0")]
pub fn is_symlink(&self) -> bool {
self.0.is_symlink()
Expand Down
2 changes: 2 additions & 0 deletions library/std/src/net/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ impl SocketAddr {
/// assert_eq!(socket.is_ipv4(), true);
/// assert_eq!(socket.is_ipv6(), false);
/// ```
#[must_use]
#[stable(feature = "sockaddr_checker", since = "1.16.0")]
#[rustc_const_unstable(feature = "const_socketaddr", issue = "82485")]
pub const fn is_ipv4(&self) -> bool {
Expand All @@ -253,6 +254,7 @@ impl SocketAddr {
/// assert_eq!(socket.is_ipv4(), false);
/// assert_eq!(socket.is_ipv6(), true);
/// ```
#[must_use]
#[stable(feature = "sockaddr_checker", since = "1.16.0")]
#[rustc_const_unstable(feature = "const_socketaddr", issue = "82485")]
pub const fn is_ipv6(&self) -> bool {
Expand Down
29 changes: 29 additions & 0 deletions library/std/src/net/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ impl IpAddr {
/// ```
#[rustc_const_stable(feature = "const_ip", since = "1.50.0")]
#[stable(feature = "ip_shared", since = "1.12.0")]
#[must_use]
#[inline]
pub const fn is_unspecified(&self) -> bool {
match self {
Expand All @@ -256,6 +257,7 @@ impl IpAddr {
/// ```
#[rustc_const_stable(feature = "const_ip", since = "1.50.0")]
#[stable(feature = "ip_shared", since = "1.12.0")]
#[must_use]
#[inline]
pub const fn is_loopback(&self) -> bool {
match self {
Expand All @@ -281,6 +283,7 @@ impl IpAddr {
/// ```
#[rustc_const_unstable(feature = "const_ip", issue = "76205")]
#[unstable(feature = "ip", issue = "27709")]
#[must_use]
#[inline]
pub const fn is_global(&self) -> bool {
match self {
Expand All @@ -304,6 +307,7 @@ impl IpAddr {
/// ```
#[rustc_const_stable(feature = "const_ip", since = "1.50.0")]
#[stable(feature = "ip_shared", since = "1.12.0")]
#[must_use]
#[inline]
pub const fn is_multicast(&self) -> bool {
match self {
Expand Down Expand Up @@ -332,6 +336,7 @@ impl IpAddr {
/// ```
#[rustc_const_unstable(feature = "const_ip", issue = "76205")]
#[unstable(feature = "ip", issue = "27709")]
#[must_use]
#[inline]
pub const fn is_documentation(&self) -> bool {
match self {
Expand All @@ -356,6 +361,7 @@ impl IpAddr {
/// assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0x2, 0, 0, 0, 0, 0, 0)).is_benchmarking(), true);
/// ```
#[unstable(feature = "ip", issue = "27709")]
#[must_use]
#[inline]
pub const fn is_benchmarking(&self) -> bool {
match self {
Expand All @@ -379,6 +385,7 @@ impl IpAddr {
/// ```
#[rustc_const_stable(feature = "const_ip", since = "1.50.0")]
#[stable(feature = "ipaddr_checker", since = "1.16.0")]
#[must_use]
#[inline]
pub const fn is_ipv4(&self) -> bool {
matches!(self, IpAddr::V4(_))
Expand All @@ -399,6 +406,7 @@ impl IpAddr {
/// ```
#[rustc_const_stable(feature = "const_ip", since = "1.50.0")]
#[stable(feature = "ipaddr_checker", since = "1.16.0")]
#[must_use]
#[inline]
pub const fn is_ipv6(&self) -> bool {
matches!(self, IpAddr::V6(_))
Expand Down Expand Up @@ -527,6 +535,7 @@ impl Ipv4Addr {
/// ```
#[rustc_const_stable(feature = "const_ipv4", since = "1.32.0")]
#[stable(feature = "ip_shared", since = "1.12.0")]
#[must_use]
#[inline]
pub const fn is_unspecified(&self) -> bool {
self.inner.s_addr == 0
Expand All @@ -548,6 +557,7 @@ impl Ipv4Addr {
/// ```
#[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")]
#[stable(since = "1.7.0", feature = "ip_17")]
#[must_use]
#[inline]
pub const fn is_loopback(&self) -> bool {
self.octets()[0] == 127
Expand Down Expand Up @@ -578,6 +588,7 @@ impl Ipv4Addr {
/// ```
#[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")]
#[stable(since = "1.7.0", feature = "ip_17")]
#[must_use]
#[inline]
pub const fn is_private(&self) -> bool {
match self.octets() {
Expand Down Expand Up @@ -605,6 +616,7 @@ impl Ipv4Addr {
/// ```
#[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")]
#[stable(since = "1.7.0", feature = "ip_17")]
#[must_use]
#[inline]
pub const fn is_link_local(&self) -> bool {
matches!(self.octets(), [169, 254, ..])
Expand Down Expand Up @@ -680,6 +692,7 @@ impl Ipv4Addr {
/// ```
#[rustc_const_unstable(feature = "const_ipv4", issue = "76205")]
#[unstable(feature = "ip", issue = "27709")]
#[must_use]
#[inline]
pub const fn is_global(&self) -> bool {
// check if this address is 192.0.0.9 or 192.0.0.10. These addresses are the only two
Expand Down Expand Up @@ -720,6 +733,7 @@ impl Ipv4Addr {
/// ```
#[rustc_const_unstable(feature = "const_ipv4", issue = "76205")]
#[unstable(feature = "ip", issue = "27709")]
#[must_use]
#[inline]
pub const fn is_shared(&self) -> bool {
self.octets()[0] == 100 && (self.octets()[1] & 0b1100_0000 == 0b0100_0000)
Expand All @@ -745,6 +759,7 @@ impl Ipv4Addr {
/// ```
#[rustc_const_unstable(feature = "const_ipv4", issue = "76205")]
#[unstable(feature = "ip", issue = "27709")]
#[must_use]
#[inline]
pub const fn is_benchmarking(&self) -> bool {
self.octets()[0] == 198 && (self.octets()[1] & 0xfe) == 18
Expand Down Expand Up @@ -779,6 +794,7 @@ impl Ipv4Addr {
/// ```
#[rustc_const_unstable(feature = "const_ipv4", issue = "76205")]
#[unstable(feature = "ip", issue = "27709")]
#[must_use]
#[inline]
pub const fn is_reserved(&self) -> bool {
self.octets()[0] & 240 == 240 && !self.is_broadcast()
Expand All @@ -802,6 +818,7 @@ impl Ipv4Addr {
/// ```
#[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")]
#[stable(since = "1.7.0", feature = "ip_17")]
#[must_use]
#[inline]
pub const fn is_multicast(&self) -> bool {
self.octets()[0] >= 224 && self.octets()[0] <= 239
Expand All @@ -823,6 +840,7 @@ impl Ipv4Addr {
/// ```
#[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")]
#[stable(since = "1.7.0", feature = "ip_17")]
#[must_use]
#[inline]
pub const fn is_broadcast(&self) -> bool {
u32::from_be_bytes(self.octets()) == u32::from_be_bytes(Self::BROADCAST.octets())
Expand Down Expand Up @@ -850,6 +868,7 @@ impl Ipv4Addr {
/// ```
#[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")]
#[stable(since = "1.7.0", feature = "ip_17")]
#[must_use]
#[inline]
pub const fn is_documentation(&self) -> bool {
match self.octets() {
Expand Down Expand Up @@ -1291,6 +1310,7 @@ impl Ipv6Addr {
/// ```
#[rustc_const_stable(feature = "const_ipv6", since = "1.50.0")]
#[stable(since = "1.7.0", feature = "ip_17")]
#[must_use]
#[inline]
pub const fn is_unspecified(&self) -> bool {
u128::from_be_bytes(self.octets()) == u128::from_be_bytes(Ipv6Addr::UNSPECIFIED.octets())
Expand All @@ -1314,6 +1334,7 @@ impl Ipv6Addr {
/// ```
#[rustc_const_stable(feature = "const_ipv6", since = "1.50.0")]
#[stable(since = "1.7.0", feature = "ip_17")]
#[must_use]
#[inline]
pub const fn is_loopback(&self) -> bool {
u128::from_be_bytes(self.octets()) == u128::from_be_bytes(Ipv6Addr::LOCALHOST.octets())
Expand All @@ -1340,6 +1361,7 @@ impl Ipv6Addr {
/// ```
#[rustc_const_unstable(feature = "const_ipv6", issue = "76205")]
#[unstable(feature = "ip", issue = "27709")]
#[must_use]
#[inline]
pub const fn is_global(&self) -> bool {
match self.multicast_scope() {
Expand Down Expand Up @@ -1367,6 +1389,7 @@ impl Ipv6Addr {
/// ```
#[rustc_const_unstable(feature = "const_ipv6", issue = "76205")]
#[unstable(feature = "ip", issue = "27709")]
#[must_use]
#[inline]
pub const fn is_unique_local(&self) -> bool {
(self.segments()[0] & 0xfe00) == 0xfc00
Expand Down Expand Up @@ -1395,6 +1418,7 @@ impl Ipv6Addr {
/// ```
#[rustc_const_unstable(feature = "const_ipv6", issue = "76205")]
#[unstable(feature = "ip", issue = "27709")]
#[must_use]
#[inline]
pub const fn is_unicast(&self) -> bool {
!self.is_multicast()
Expand Down Expand Up @@ -1446,6 +1470,7 @@ impl Ipv6Addr {
/// ```
#[rustc_const_unstable(feature = "const_ipv6", issue = "76205")]
#[unstable(feature = "ip", issue = "27709")]
#[must_use]
#[inline]
pub const fn is_unicast_link_local(&self) -> bool {
(self.segments()[0] & 0xffc0) == 0xfe80
Expand All @@ -1470,6 +1495,7 @@ impl Ipv6Addr {
/// ```
#[rustc_const_unstable(feature = "const_ipv6", issue = "76205")]
#[unstable(feature = "ip", issue = "27709")]
#[must_use]
#[inline]
pub const fn is_documentation(&self) -> bool {
(self.segments()[0] == 0x2001) && (self.segments()[1] == 0xdb8)
Expand All @@ -1492,6 +1518,7 @@ impl Ipv6Addr {
/// assert_eq!(Ipv6Addr::new(0x2001, 0x2, 0, 0, 0, 0, 0, 0).is_benchmarking(), true);
/// ```
#[unstable(feature = "ip", issue = "27709")]
#[must_use]
#[inline]
pub const fn is_benchmarking(&self) -> bool {
(self.segments()[0] == 0x2001) && (self.segments()[1] == 0x2) && (self.segments()[2] == 0)
Expand Down Expand Up @@ -1529,6 +1556,7 @@ impl Ipv6Addr {
/// ```
#[rustc_const_unstable(feature = "const_ipv6", issue = "76205")]
#[unstable(feature = "ip", issue = "27709")]
#[must_use]
#[inline]
pub const fn is_unicast_global(&self) -> bool {
self.is_unicast()
Expand Down Expand Up @@ -1590,6 +1618,7 @@ impl Ipv6Addr {
/// ```
#[rustc_const_stable(feature = "const_ipv6", since = "1.50.0")]
#[stable(since = "1.7.0", feature = "ip_17")]
#[must_use]
#[inline]
pub const fn is_multicast(&self) -> bool {
(self.segments()[0] & 0xff00) == 0xff00
Expand Down
1 change: 1 addition & 0 deletions library/std/src/os/unix/net/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ impl SocketAddr {
/// Ok(())
/// }
/// ```
#[must_use]
#[stable(feature = "unix_socket", since = "1.10.0")]
pub fn is_unnamed(&self) -> bool {
if let AddressKind::Unnamed = self.address() { true } else { false }
Expand Down
8 changes: 8 additions & 0 deletions library/std/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ impl<'a> Prefix<'a> {
/// assert!(!Disk(b'C').is_verbatim());
/// ```
#[inline]
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_verbatim(&self) -> bool {
use self::Prefix::*;
Expand Down Expand Up @@ -247,6 +248,7 @@ impl<'a> Prefix<'a> {
/// assert!(path::is_separator('/')); // '/' works for both Unix and Windows
/// assert!(!path::is_separator('❤'));
/// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_separator(c: char) -> bool {
c.is_ascii() && is_sep_byte(c as u8)
Expand Down Expand Up @@ -2016,6 +2018,7 @@ impl Path {
///
/// [`has_root`]: Path::has_root
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use]
#[allow(deprecated)]
pub fn is_absolute(&self) -> bool {
if cfg!(target_os = "redox") {
Expand All @@ -2040,6 +2043,7 @@ impl Path {
///
/// [`is_absolute`]: Path::is_absolute
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use]
#[inline]
pub fn is_relative(&self) -> bool {
!self.is_absolute()
Expand All @@ -2066,6 +2070,7 @@ impl Path {
/// assert!(Path::new("/etc/passwd").has_root());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use]
#[inline]
pub fn has_root(&self) -> bool {
self.components().has_root()
Expand Down Expand Up @@ -2705,6 +2710,7 @@ impl Path {
/// a Unix-like system for example. See [`fs::File::open`] or
/// [`fs::OpenOptions::open`] for more information.
#[stable(feature = "path_ext", since = "1.5.0")]
#[must_use]
pub fn is_file(&self) -> bool {
fs::metadata(self).map(|m| m.is_file()).unwrap_or(false)
}
Expand All @@ -2731,6 +2737,7 @@ impl Path {
/// check errors, call [`fs::metadata`] and handle its [`Result`]. Then call
/// [`fs::Metadata::is_dir`] if it was [`Ok`].
#[stable(feature = "path_ext", since = "1.5.0")]
#[must_use]
pub fn is_dir(&self) -> bool {
fs::metadata(self).map(|m| m.is_dir()).unwrap_or(false)
}
Expand All @@ -2757,6 +2764,7 @@ impl Path {
/// assert_eq!(link_path.exists(), false);
/// ```
#[unstable(feature = "is_symlink", issue = "85748")]
#[must_use]
pub fn is_symlink(&self) -> bool {
fs::symlink_metadata(self).map(|m| m.is_symlink()).unwrap_or(false)
}
Expand Down
1 change: 1 addition & 0 deletions library/std/src/sync/barrier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ impl BarrierWaitResult {
/// println!("{:?}", barrier_wait_result.is_leader());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use]
pub fn is_leader(&self) -> bool {
self.0
}
Expand Down

0 comments on commit 4c4652d

Please sign in to comment.