diff options
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/collections/hash/map.rs | 7 | ||||
| -rw-r--r-- | library/std/src/collections/hash/set.rs | 2 | ||||
| -rw-r--r-- | library/std/src/ffi/c_str.rs | 8 | ||||
| -rw-r--r-- | library/std/src/ffi/os_str.rs | 3 | ||||
| -rw-r--r-- | library/std/src/fs.rs | 2 | ||||
| -rw-r--r-- | library/std/src/io/buffered/bufreader.rs | 11 | ||||
| -rw-r--r-- | library/std/src/io/buffered/bufwriter.rs | 1 | ||||
| -rw-r--r-- | library/std/src/io/error.rs | 1 | ||||
| -rw-r--r-- | library/std/src/io/mod.rs | 1 | ||||
| -rw-r--r-- | library/std/src/io/stdio.rs | 1 | ||||
| -rw-r--r-- | library/std/src/lazy.rs | 1 | ||||
| -rw-r--r-- | library/std/src/net/addr.rs | 3 | ||||
| -rw-r--r-- | library/std/src/net/ip.rs | 2 | ||||
| -rw-r--r-- | library/std/src/net/tcp.rs | 1 | ||||
| -rw-r--r-- | library/std/src/os/unix/net/ancillary.rs | 1 | ||||
| -rw-r--r-- | library/std/src/path.rs | 5 | ||||
| -rw-r--r-- | library/std/src/sync/barrier.rs | 1 | ||||
| -rw-r--r-- | library/std/src/sync/condvar.rs | 1 | ||||
| -rw-r--r-- | library/std/src/sync/once.rs | 1 | ||||
| -rw-r--r-- | library/std/src/sys/windows/fs.rs | 4 | ||||
| -rw-r--r-- | library/std/src/sys/windows/stack_overflow.rs | 8 | ||||
| -rw-r--r-- | library/std/src/sys_common/backtrace.rs | 6 |
22 files changed, 54 insertions, 17 deletions
diff --git a/library/std/src/collections/hash/map.rs b/library/std/src/collections/hash/map.rs index 528bb1bf6e9..01019344f4f 100644 --- a/library/std/src/collections/hash/map.rs +++ b/library/std/src/collections/hash/map.rs @@ -223,6 +223,7 @@ impl<K, V> HashMap<K, V, RandomState> { /// let mut map: HashMap<&str, i32> = HashMap::new(); /// ``` #[inline] + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] pub fn new() -> HashMap<K, V, RandomState> { Default::default() @@ -240,6 +241,7 @@ impl<K, V> HashMap<K, V, RandomState> { /// let mut map: HashMap<&str, i32> = HashMap::with_capacity(10); /// ``` #[inline] + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] pub fn with_capacity(capacity: usize) -> HashMap<K, V, RandomState> { HashMap::with_capacity_and_hasher(capacity, Default::default()) @@ -1720,6 +1722,7 @@ impl<'a, K, V, S> RawOccupiedEntryMut<'a, K, V, S> { /// Converts the entry into a mutable reference to the key in the entry /// with a lifetime bound to the map itself. #[inline] + #[must_use = "`self` will be dropped if the result is not used"] #[unstable(feature = "hash_raw_entry", issue = "56167")] pub fn into_key(self) -> &'a mut K { self.base.into_key() @@ -1735,6 +1738,7 @@ impl<'a, K, V, S> RawOccupiedEntryMut<'a, K, V, S> { /// Converts the `OccupiedEntry` into a mutable reference to the value in the entry /// with a lifetime bound to the map itself. #[inline] + #[must_use = "`self` will be dropped if the result is not used"] #[unstable(feature = "hash_raw_entry", issue = "56167")] pub fn into_mut(self) -> &'a mut V { self.base.into_mut() @@ -1764,6 +1768,7 @@ impl<'a, K, V, S> RawOccupiedEntryMut<'a, K, V, S> { /// Converts the `OccupiedEntry` into a mutable reference to the key and value in the entry /// with a lifetime bound to the map itself. #[inline] + #[must_use = "`self` will be dropped if the result is not used"] #[unstable(feature = "hash_raw_entry", issue = "56167")] pub fn into_key_value(self) -> (&'a mut K, &'a mut V) { self.base.into_key_value() @@ -2891,6 +2896,7 @@ impl RandomState { #[inline] #[allow(deprecated)] // rand + #[must_use] #[stable(feature = "hashmap_build_hasher", since = "1.7.0")] pub fn new() -> RandomState { // Historically this function did not cache keys from the OS and instead @@ -2943,6 +2949,7 @@ impl DefaultHasher { /// instances created through `new` or `default`. #[stable(feature = "hashmap_default_hasher", since = "1.13.0")] #[allow(deprecated)] + #[must_use] pub fn new() -> DefaultHasher { DefaultHasher(SipHasher13::new_with_keys(0, 0)) } diff --git a/library/std/src/collections/hash/set.rs b/library/std/src/collections/hash/set.rs index dcfe3220950..5804701892e 100644 --- a/library/std/src/collections/hash/set.rs +++ b/library/std/src/collections/hash/set.rs @@ -126,6 +126,7 @@ impl<T> HashSet<T, RandomState> { /// let set: HashSet<i32> = HashSet::new(); /// ``` #[inline] + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] pub fn new() -> HashSet<T, RandomState> { Default::default() @@ -144,6 +145,7 @@ impl<T> HashSet<T, RandomState> { /// assert!(set.capacity() >= 10); /// ``` #[inline] + #[must_use] #[stable(feature = "rust1", since = "1.0.0")] pub fn with_capacity(capacity: usize) -> HashSet<T, RandomState> { HashSet { base: base::HashSet::with_capacity_and_hasher(capacity, Default::default()) } diff --git a/library/std/src/ffi/c_str.rs b/library/std/src/ffi/c_str.rs index fe1f28f00c4..6b488e49ed7 100644 --- a/library/std/src/ffi/c_str.rs +++ b/library/std/src/ffi/c_str.rs @@ -322,6 +322,7 @@ impl FromVecWithNulError { /// /// assert_eq!(bytes, value.unwrap_err().into_bytes()); /// ``` + #[must_use = "`self` will be dropped if the result is not used"] pub fn into_bytes(self) -> Vec<u8> { self.bytes } @@ -524,6 +525,7 @@ impl CString { /// } /// ``` #[inline] + #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "cstr_memory", since = "1.4.0")] pub fn into_raw(self) -> *mut c_char { Box::into_raw(self.into_inner()) as *mut c_char @@ -547,7 +549,6 @@ impl CString { /// let err = cstring.into_string().err().expect("into_string().err() failed"); /// assert_eq!(err.utf8_error().valid_up_to(), 1); /// ``` - #[stable(feature = "cstring_into", since = "1.7.0")] pub fn into_string(self) -> Result<String, IntoStringError> { String::from_utf8(self.into_bytes()).map_err(|e| IntoStringError { @@ -571,6 +572,7 @@ impl CString { /// let bytes = c_string.into_bytes(); /// assert_eq!(bytes, vec![b'f', b'o', b'o']); /// ``` + #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "cstring_into", since = "1.7.0")] pub fn into_bytes(self) -> Vec<u8> { let mut vec = self.into_inner().into_vec(); @@ -591,6 +593,7 @@ impl CString { /// let bytes = c_string.into_bytes_with_nul(); /// assert_eq!(bytes, vec![b'f', b'o', b'o', b'\0']); /// ``` + #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "cstring_into", since = "1.7.0")] pub fn into_bytes_with_nul(self) -> Vec<u8> { self.into_inner().into_vec() @@ -667,6 +670,7 @@ impl CString { /// assert_eq!(&*boxed, /// CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed")); /// ``` + #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "into_boxed_c_str", since = "1.20.0")] pub fn into_boxed_c_str(self) -> Box<CStr> { unsafe { Box::from_raw(Box::into_raw(self.into_inner()) as *mut CStr) } @@ -1018,6 +1022,7 @@ impl NulError { /// let nul_error = CString::new("foo\0bar").unwrap_err(); /// assert_eq!(nul_error.into_vec(), b"foo\0bar"); /// ``` + #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "rust1", since = "1.0.0")] pub fn into_vec(self) -> Vec<u8> { self.1 @@ -1092,6 +1097,7 @@ impl fmt::Display for FromVecWithNulError { impl IntoStringError { /// Consumes this error, returning original [`CString`] which generated the /// error. + #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "cstring_into", since = "1.7.0")] pub fn into_cstring(self) -> CString { self.inner diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index c305519dd44..de745f21649 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -119,6 +119,7 @@ impl OsString { /// let os_string = OsString::new(); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] #[inline] pub fn new() -> OsString { OsString { inner: Buf::from_string(String::new()) } @@ -199,6 +200,7 @@ impl OsString { /// assert_eq!(capacity, os_string.capacity()); /// ``` #[stable(feature = "osstring_simple_functions", since = "1.9.0")] + #[must_use] #[inline] pub fn with_capacity(capacity: usize) -> OsString { OsString { inner: Buf::with_capacity(capacity) } @@ -346,6 +348,7 @@ impl OsString { /// /// let b: Box<OsStr> = s.into_boxed_os_str(); /// ``` + #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "into_boxed_os_str", since = "1.20.0")] pub fn into_boxed_os_str(self) -> Box<OsStr> { let rw = Box::into_raw(self.inner.into_box()) as *mut OsStr; diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index 726c855c4fd..85d35072923 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -744,6 +744,7 @@ impl OpenOptions { /// let file = options.read(true).open("foo.txt"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] pub fn new() -> Self { OpenOptions(fs_imp::OpenOptions::new()) } @@ -2184,6 +2185,7 @@ impl DirBuilder { /// let builder = DirBuilder::new(); /// ``` #[stable(feature = "dir_builder", since = "1.6.0")] + #[must_use] pub fn new() -> DirBuilder { DirBuilder { inner: fs_imp::DirBuilder::new(), recursive: false } } diff --git a/library/std/src/io/buffered/bufreader.rs b/library/std/src/io/buffered/bufreader.rs index 243207a6065..2864e94f60f 100644 --- a/library/std/src/io/buffered/bufreader.rs +++ b/library/std/src/io/buffered/bufreader.rs @@ -242,14 +242,13 @@ impl<R: Seek> BufReader<R> { self.pos = new_pos as usize; return Ok(()); } - } else { - if let Some(new_pos) = pos.checked_add(offset as u64) { - if new_pos <= self.cap as u64 { - self.pos = new_pos as usize; - return Ok(()); - } + } else if let Some(new_pos) = pos.checked_add(offset as u64) { + if new_pos <= self.cap as u64 { + self.pos = new_pos as usize; + return Ok(()); } } + self.seek(SeekFrom::Current(offset)).map(drop) } } diff --git a/library/std/src/io/buffered/bufwriter.rs b/library/std/src/io/buffered/bufwriter.rs index ebbda7c1bf2..c7423e4d92a 100644 --- a/library/std/src/io/buffered/bufwriter.rs +++ b/library/std/src/io/buffered/bufwriter.rs @@ -476,6 +476,7 @@ pub struct WriterPanicked { impl WriterPanicked { /// Returns the perhaps-unwritten data. Some of this data may have been written by the /// panicking call(s) to the underlying writer, so simply writing it again is not a good idea. + #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "bufwriter_into_parts", since = "1.56.0")] pub fn into_inner(self) -> Vec<u8> { self.buf diff --git a/library/std/src/io/error.rs b/library/std/src/io/error.rs index 51666c0a3c7..6101260e149 100644 --- a/library/std/src/io/error.rs +++ b/library/std/src/io/error.rs @@ -657,6 +657,7 @@ impl Error { /// } /// ``` #[stable(feature = "io_error_inner", since = "1.3.0")] + #[must_use = "`self` will be dropped if the result is not used"] #[inline] pub fn into_inner(self) -> Option<Box<dyn error::Error + Send + Sync>> { match self.repr { diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index 8c71138aa23..abe29ba0f7c 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -1206,6 +1206,7 @@ impl<'a> IoSlice<'a> { /// /// Panics on Windows if the slice is larger than 4GB. #[stable(feature = "iovec", since = "1.36.0")] + #[must_use] #[inline] pub fn new(buf: &'a [u8]) -> IoSlice<'a> { IoSlice(sys::io::IoSlice::new(buf)) diff --git a/library/std/src/io/stdio.rs b/library/std/src/io/stdio.rs index 1ac3bbc95c6..9389501e012 100644 --- a/library/std/src/io/stdio.rs +++ b/library/std/src/io/stdio.rs @@ -464,6 +464,7 @@ impl Stdin { /// println!("got a line: {}", line.unwrap()); /// } /// ``` + #[must_use = "`self` will be dropped if the result is not used"] #[unstable(feature = "stdin_forwarders", issue = "87096")] pub fn lines(self) -> Lines<StdinLock<'static>> { self.into_locked().lines() diff --git a/library/std/src/lazy.rs b/library/std/src/lazy.rs index 5afdb799f0c..d7450962359 100644 --- a/library/std/src/lazy.rs +++ b/library/std/src/lazy.rs @@ -171,6 +171,7 @@ impl<T: Eq> Eq for SyncOnceCell<T> {} impl<T> SyncOnceCell<T> { /// Creates a new empty cell. #[unstable(feature = "once_cell", issue = "74465")] + #[must_use] pub const fn new() -> SyncOnceCell<T> { SyncOnceCell { once: Once::new(), diff --git a/library/std/src/net/addr.rs b/library/std/src/net/addr.rs index f4ebcd53a25..cd2007cc2cb 100644 --- a/library/std/src/net/addr.rs +++ b/library/std/src/net/addr.rs @@ -131,6 +131,7 @@ impl SocketAddr { /// assert_eq!(socket.port(), 8080); /// ``` #[stable(feature = "ip_addr", since = "1.7.0")] + #[must_use] pub fn new(ip: IpAddr, port: u16) -> SocketAddr { match ip { IpAddr::V4(a) => SocketAddr::V4(SocketAddrV4::new(a, port)), @@ -272,6 +273,7 @@ impl SocketAddrV4 { /// let socket = SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] pub fn new(ip: Ipv4Addr, port: u16) -> SocketAddrV4 { SocketAddrV4 { inner: c::sockaddr_in { @@ -368,6 +370,7 @@ impl SocketAddrV6 { /// let socket = SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 8080, 0, 0); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] pub fn new(ip: Ipv6Addr, port: u16, flowinfo: u32, scope_id: u32) -> SocketAddrV6 { SocketAddrV6 { inner: c::sockaddr_in6 { diff --git a/library/std/src/net/ip.rs b/library/std/src/net/ip.rs index c05a32742ba..99922eef61f 100644 --- a/library/std/src/net/ip.rs +++ b/library/std/src/net/ip.rs @@ -442,6 +442,7 @@ impl Ipv4Addr { /// ``` #[rustc_const_stable(feature = "const_ipv4", since = "1.32.0")] #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] #[inline] pub const fn new(a: u8, b: u8, c: u8, d: u8) -> Ipv4Addr { // `s_addr` is stored as BE on all machine and the array is in BE order. @@ -1192,6 +1193,7 @@ impl Ipv6Addr { /// ``` #[rustc_const_stable(feature = "const_ipv6", since = "1.32.0")] #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] #[inline] pub const fn new(a: u16, b: u16, c: u16, d: u16, e: u16, f: u16, g: u16, h: u16) -> Ipv6Addr { let addr16 = [ diff --git a/library/std/src/net/tcp.rs b/library/std/src/net/tcp.rs index 223726d45d7..2c6e3930059 100644 --- a/library/std/src/net/tcp.rs +++ b/library/std/src/net/tcp.rs @@ -883,6 +883,7 @@ impl TcpListener { /// Ok(()) /// } /// ``` + #[must_use = "`self` will be dropped if the result is not used"] #[unstable(feature = "tcplistener_into_incoming", issue = "88339")] pub fn into_incoming(self) -> IntoIncoming { IntoIncoming { listener: self } diff --git a/library/std/src/os/unix/net/ancillary.rs b/library/std/src/os/unix/net/ancillary.rs index 1f9d42812ec..57bb61903c1 100644 --- a/library/std/src/os/unix/net/ancillary.rs +++ b/library/std/src/os/unix/net/ancillary.rs @@ -189,6 +189,7 @@ impl SocketCred { /// /// PID, UID and GID is set to 0. #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] + #[must_use] pub fn new() -> SocketCred { SocketCred(libc::ucred { pid: 0, uid: 0, gid: 0 }) } diff --git a/library/std/src/path.rs b/library/std/src/path.rs index a45ecf6ea8c..a8a79fb9c8f 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -532,6 +532,7 @@ impl<'a> Component<'a> { /// let components: Vec<_> = path.components().map(|comp| comp.as_os_str()).collect(); /// assert_eq!(&components, &[".", "tmp", "foo", "bar.txt"]); /// ``` + #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "rust1", since = "1.0.0")] pub fn as_os_str(self) -> &'a OsStr { match self { @@ -1145,6 +1146,7 @@ impl PathBuf { /// let path = PathBuf::new(); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] #[inline] pub fn new() -> PathBuf { PathBuf { inner: OsString::new() } @@ -1169,6 +1171,7 @@ impl PathBuf { /// /// [`with_capacity`]: OsString::with_capacity #[stable(feature = "path_buf_capacity", since = "1.44.0")] + #[must_use] #[inline] pub fn with_capacity(capacity: usize) -> PathBuf { PathBuf { inner: OsString::with_capacity(capacity) } @@ -1428,6 +1431,7 @@ impl PathBuf { /// let os_str = p.into_os_string(); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[must_use = "`self` will be dropped if the result is not used"] #[inline] pub fn into_os_string(self) -> OsString { self.inner @@ -1435,6 +1439,7 @@ impl PathBuf { /// Converts this `PathBuf` into a [boxed](Box) [`Path`]. #[stable(feature = "into_boxed_path", since = "1.20.0")] + #[must_use = "`self` will be dropped if the result is not used"] #[inline] pub fn into_boxed_path(self) -> Box<Path> { let rw = Box::into_raw(self.inner.into_boxed_os_str()) as *mut Path; diff --git a/library/std/src/sync/barrier.rs b/library/std/src/sync/barrier.rs index a17b82f82e8..0e28a2d166f 100644 --- a/library/std/src/sync/barrier.rs +++ b/library/std/src/sync/barrier.rs @@ -80,6 +80,7 @@ impl Barrier { /// let barrier = Barrier::new(10); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] pub fn new(n: usize) -> Barrier { Barrier { lock: Mutex::new(BarrierState { count: 0, generation_id: 0 }), diff --git a/library/std/src/sync/condvar.rs b/library/std/src/sync/condvar.rs index 00a4afc5705..d8aca9651b8 100644 --- a/library/std/src/sync/condvar.rs +++ b/library/std/src/sync/condvar.rs @@ -121,6 +121,7 @@ impl Condvar { /// let condvar = Condvar::new(); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] pub fn new() -> Condvar { Condvar { inner: sys::Condvar::new() } } diff --git a/library/std/src/sync/once.rs b/library/std/src/sync/once.rs index a2e935a0ceb..1710c005393 100644 --- a/library/std/src/sync/once.rs +++ b/library/std/src/sync/once.rs @@ -186,6 +186,7 @@ impl Once { #[inline] #[stable(feature = "once_new", since = "1.2.0")] #[rustc_const_stable(feature = "const_once_new", since = "1.32.0")] + #[must_use] pub const fn new() -> Once { Once { state_and_queue: AtomicUsize::new(INCOMPLETE), _marker: marker::PhantomData } } diff --git a/library/std/src/sys/windows/fs.rs b/library/std/src/sys/windows/fs.rs index cc137771bb8..ad550a823ae 100644 --- a/library/std/src/sys/windows/fs.rs +++ b/library/std/src/sys/windows/fs.rs @@ -558,7 +558,7 @@ impl IntoInner<Handle> for File { impl FromInner<Handle> for File { fn from_inner(handle: Handle) -> File { - File { handle: handle } + File { handle } } } @@ -672,7 +672,7 @@ impl FilePermissions { impl FileType { fn new(attrs: c::DWORD, reparse_tag: c::DWORD) -> FileType { - FileType { attributes: attrs, reparse_tag: reparse_tag } + FileType { attributes: attrs, reparse_tag } } pub fn is_dir(&self) -> bool { !self.is_symlink() && self.is_directory() diff --git a/library/std/src/sys/windows/stack_overflow.rs b/library/std/src/sys/windows/stack_overflow.rs index 755dc0a6c8b..18a2a36ad25 100644 --- a/library/std/src/sys/windows/stack_overflow.rs +++ b/library/std/src/sys/windows/stack_overflow.rs @@ -9,10 +9,10 @@ impl Handler { pub unsafe fn new() -> Handler { // This API isn't available on XP, so don't panic in that case and just // pray it works out ok. - if c::SetThreadStackGuarantee(&mut 0x5000) == 0 { - if c::GetLastError() as u32 != c::ERROR_CALL_NOT_IMPLEMENTED as u32 { - panic!("failed to reserve stack space for exception handling"); - } + if c::SetThreadStackGuarantee(&mut 0x5000) == 0 + && c::GetLastError() as u32 != c::ERROR_CALL_NOT_IMPLEMENTED as u32 + { + panic!("failed to reserve stack space for exception handling"); } Handler } diff --git a/library/std/src/sys_common/backtrace.rs b/library/std/src/sys_common/backtrace.rs index e6a099f0e81..d5e8f12414f 100644 --- a/library/std/src/sys_common/backtrace.rs +++ b/library/std/src/sys_common/backtrace.rs @@ -93,10 +93,8 @@ unsafe fn _print_fmt(fmt: &mut fmt::Formatter<'_>, print_fmt: PrintFmt) -> fmt:: if stop { return false; } - if !hit { - if start { - res = bt_fmt.frame().print_raw(frame.ip(), None, None, None); - } + if !hit && start { + res = bt_fmt.frame().print_raw(frame.ip(), None, None, None); } idx += 1; |
