Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 4 pull requests #90437

Merged
merged 11 commits into from
Oct 31, 2021
Merged
2 changes: 2 additions & 0 deletions library/alloc/src/collections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,7 @@ impl<T> BinaryHeap<T> {
///
/// assert_eq!(heap.len(), 2);
/// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> usize {
self.data.len()
Expand All @@ -1075,6 +1076,7 @@ impl<T> BinaryHeap<T> {
///
/// assert!(!heap.is_empty());
/// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool {
self.len() == 0
Expand Down
2 changes: 2 additions & 0 deletions library/alloc/src/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2212,6 +2212,7 @@ impl<K, V> BTreeMap<K, V> {
/// a.insert(1, "a");
/// assert_eq!(a.len(), 1);
/// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
pub const fn len(&self) -> usize {
Expand All @@ -2232,6 +2233,7 @@ impl<K, V> BTreeMap<K, V> {
/// a.insert(1, "a");
/// assert!(!a.is_empty());
/// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
pub const fn is_empty(&self) -> bool {
Expand Down
2 changes: 2 additions & 0 deletions library/alloc/src/collections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,7 @@ impl<T> BTreeSet<T> {
/// v.insert(1);
/// assert_eq!(v.len(), 1);
/// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
pub const fn len(&self) -> usize {
Expand All @@ -1064,6 +1065,7 @@ impl<T> BTreeSet<T> {
/// v.insert(1);
/// assert!(!v.is_empty());
/// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_btree_new", issue = "71835")]
pub const fn is_empty(&self) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions library/alloc/src/collections/btree/set/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,8 @@ fn test_send() {
#[test]
fn test_ord_absence() {
fn set<K>(mut set: BTreeSet<K>) {
set.is_empty();
set.len();
let _ = set.is_empty();
let _ = set.len();
set.clear();
let _ = set.iter();
let _ = set.into_iter();
Expand Down
2 changes: 2 additions & 0 deletions library/alloc/src/collections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ impl<T> LinkedList<T> {
/// assert!(!dl.is_empty());
/// ```
#[inline]
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool {
self.head.is_none()
Expand All @@ -609,6 +610,7 @@ impl<T> LinkedList<T> {
/// assert_eq!(dl.len(), 3);
/// ```
#[inline]
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> usize {
self.len
Expand Down
2 changes: 2 additions & 0 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,7 @@ impl String {
/// assert_eq!(fancy_f.chars().count(), 3);
/// ```
#[inline]
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> usize {
self.vec.len()
Expand All @@ -1566,6 +1567,7 @@ impl String {
/// assert!(!v.is_empty());
/// ```
#[inline]
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool {
self.len() == 0
Expand Down
1 change: 1 addition & 0 deletions library/core/src/ptr/non_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ impl<T> NonNull<[T]> {
/// ```
#[unstable(feature = "slice_ptr_len", issue = "71146")]
#[rustc_const_unstable(feature = "const_slice_ptr_len", issue = "71146")]
#[must_use]
#[inline]
pub const fn len(self) -> usize {
self.as_ptr().len()
Expand Down
4 changes: 3 additions & 1 deletion library/core/src/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ impl str {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_str_len", since = "1.39.0")]
#[must_use]
#[inline]
pub const fn len(&self) -> usize {
self.as_bytes().len()
Expand All @@ -158,9 +159,10 @@ impl str {
/// let s = "not empty";
/// assert!(!s.is_empty());
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_str_is_empty", since = "1.39.0")]
#[must_use]
#[inline]
pub const fn is_empty(&self) -> bool {
self.len() == 0
}
Expand Down
3 changes: 3 additions & 0 deletions library/std/src/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ use crate::vec::Vec;
/// previous point in time. In some instances the `Backtrace` type may
/// internally be empty due to configuration. For more information see
/// `Backtrace::capture`.
#[must_use]
pub struct Backtrace {
inner: Inner,
}
Expand Down Expand Up @@ -355,6 +356,7 @@ impl Backtrace {
/// Returns the status of this backtrace, indicating whether this backtrace
/// request was unsupported, disabled, or a stack trace was actually
/// captured.
#[must_use]
pub fn status(&self) -> BacktraceStatus {
match self.inner {
Inner::Unsupported => BacktraceStatus::Unsupported,
Expand All @@ -366,6 +368,7 @@ impl Backtrace {

impl<'a> Backtrace {
/// Returns an iterator over the backtrace frames.
#[must_use]
#[unstable(feature = "backtrace_frames", issue = "79676")]
pub fn frames(&'a self) -> &'a [BacktraceFrame] {
if let Inner::Captured(c) = &self.inner { &c.force().frames } else { &[] }
Expand Down
5 changes: 5 additions & 0 deletions library/std/src/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1707,13 +1707,15 @@ impl<'a, K, V, S> RawEntryMut<'a, K, V, S> {
impl<'a, K, V, S> RawOccupiedEntryMut<'a, K, V, S> {
/// Gets a reference to the key in the entry.
#[inline]
#[must_use]
#[unstable(feature = "hash_raw_entry", issue = "56167")]
pub fn key(&self) -> &K {
self.base.key()
}

/// Gets a mutable reference to the key in the entry.
#[inline]
#[must_use]
#[unstable(feature = "hash_raw_entry", issue = "56167")]
pub fn key_mut(&mut self) -> &mut K {
self.base.key_mut()
Expand All @@ -1730,6 +1732,7 @@ impl<'a, K, V, S> RawOccupiedEntryMut<'a, K, V, S> {

/// Gets a reference to the value in the entry.
#[inline]
#[must_use]
#[unstable(feature = "hash_raw_entry", issue = "56167")]
pub fn get(&self) -> &V {
self.base.get()
Expand All @@ -1746,13 +1749,15 @@ impl<'a, K, V, S> RawOccupiedEntryMut<'a, K, V, S> {

/// Gets a mutable reference to the value in the entry.
#[inline]
#[must_use]
#[unstable(feature = "hash_raw_entry", issue = "56167")]
pub fn get_mut(&mut self) -> &mut V {
self.base.get_mut()
}

/// Gets a reference to the key and value in the entry.
#[inline]
#[must_use]
#[unstable(feature = "hash_raw_entry", issue = "56167")]
pub fn get_key_value(&mut self) -> (&K, &V) {
self.base.get_key_value()
Expand Down
8 changes: 8 additions & 0 deletions library/std/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ pub struct VarsOs {
/// ```
///
/// [`env::vars_os()`]: vars_os
#[must_use]
#[stable(feature = "env", since = "1.0.0")]
pub fn vars() -> Vars {
Vars { inner: vars_os() }
Expand Down Expand Up @@ -140,6 +141,7 @@ pub fn vars() -> Vars {
/// println!("{:?}: {:?}", key, value);
/// }
/// ```
#[must_use]
#[stable(feature = "env", since = "1.0.0")]
pub fn vars_os() -> VarsOs {
VarsOs { inner: os_imp::env() }
Expand Down Expand Up @@ -244,6 +246,7 @@ fn _var(key: &OsStr) -> Result<String, VarError> {
/// None => println!("{} is not defined in the environment.", key)
/// }
/// ```
#[must_use]
#[stable(feature = "env", since = "1.0.0")]
pub fn var_os<K: AsRef<OsStr>>(key: K) -> Option<OsString> {
_var_os(key.as_ref())
Expand Down Expand Up @@ -384,6 +387,7 @@ fn _remove_var(key: &OsStr) {
/// documentation for more.
///
/// [`env::split_paths()`]: split_paths
#[must_use = "iterators are lazy and do nothing unless consumed"]
#[stable(feature = "env", since = "1.0.0")]
pub struct SplitPaths<'a> {
inner: os_imp::SplitPaths<'a>,
Expand Down Expand Up @@ -564,6 +568,7 @@ impl Error for JoinPathsError {
reason = "This function's behavior is unexpected and probably not what you want. \
Consider using a crate from crates.io instead."
)]
#[must_use]
#[stable(feature = "env", since = "1.0.0")]
pub fn home_dir() -> Option<PathBuf> {
os_imp::home_dir()
Expand Down Expand Up @@ -603,6 +608,7 @@ pub fn home_dir() -> Option<PathBuf> {
/// println!("Temporary directory: {}", dir.display());
/// }
/// ```
#[must_use]
#[stable(feature = "env", since = "1.0.0")]
pub fn temp_dir() -> PathBuf {
os_imp::temp_dir()
Expand Down Expand Up @@ -690,6 +696,7 @@ pub fn current_exe() -> io::Result<PathBuf> {
/// should not be relied upon for security purposes.
///
/// [`env::args()`]: args
#[must_use = "iterators are lazy and do nothing unless consumed"]
#[stable(feature = "env", since = "1.0.0")]
pub struct Args {
inner: ArgsOs,
Expand All @@ -706,6 +713,7 @@ pub struct Args {
/// should not be relied upon for security purposes.
///
/// [`env::args_os()`]: args_os
#[must_use = "iterators are lazy and do nothing unless consumed"]
#[stable(feature = "env", since = "1.0.0")]
pub struct ArgsOs {
inner: sys::args::Args,
Expand Down
3 changes: 3 additions & 0 deletions library/std/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,7 @@ impl NulError {
/// let nul_error = CString::new("foo bar\0").unwrap_err();
/// assert_eq!(nul_error.nul_position(), 7);
/// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn nul_position(&self) -> usize {
self.0
Expand Down Expand Up @@ -1107,6 +1108,7 @@ impl IntoStringError {
}

/// Access the underlying UTF-8 error that was the cause of this error.
#[must_use]
#[stable(feature = "cstring_into", since = "1.7.0")]
pub fn utf8_error(&self) -> Utf8Error {
self.error
Expand Down Expand Up @@ -1456,6 +1458,7 @@ impl CStr {
/// let boxed = c_string.into_boxed_c_str();
/// assert_eq!(boxed.into_c_string(), CString::new("foo").expect("CString::new 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_c_string(self: Box<CStr>) -> CString {
let raw = Box::into_raw(self) as *mut [u8];
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/ffi/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ impl OsString {
/// assert!(os_string.capacity() >= 10);
/// ```
#[stable(feature = "osstring_simple_functions", since = "1.9.0")]
#[must_use]
#[inline]
pub fn capacity(&self) -> usize {
self.inner.capacity()
Expand Down Expand Up @@ -669,6 +670,7 @@ impl OsStr {
/// assert!(!os_str.is_empty());
/// ```
#[stable(feature = "osstring_simple_functions", since = "1.9.0")]
#[must_use]
#[inline]
pub fn is_empty(&self) -> bool {
self.inner.inner.is_empty()
Expand Down Expand Up @@ -700,13 +702,15 @@ impl OsStr {
/// assert_eq!(os_str.len(), 3);
/// ```
#[stable(feature = "osstring_simple_functions", since = "1.9.0")]
#[must_use]
#[inline]
pub fn len(&self) -> usize {
self.inner.inner.len()
}

/// Converts a <code>[Box]<[OsStr]></code> into an [`OsString`] without copying or allocating.
#[stable(feature = "into_boxed_os_str", since = "1.20.0")]
#[must_use = "`self` will be dropped if the result is not used"]
pub fn into_os_string(self: Box<OsStr>) -> OsString {
let boxed = unsafe { Box::from_raw(Box::into_raw(self) as *mut Slice) };
OsString { inner: Buf::from_box(boxed) }
Expand Down
7 changes: 7 additions & 0 deletions library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ impl File {
/// Ok(())
/// }
/// ```
#[must_use]
#[unstable(feature = "with_options", issue = "65439")]
pub fn with_options() -> OpenOptions {
OpenOptions::new()
Expand Down Expand Up @@ -983,6 +984,7 @@ impl Metadata {
/// Ok(())
/// }
/// ```
#[must_use]
#[stable(feature = "file_type", since = "1.1.0")]
pub fn file_type(&self) -> FileType {
FileType(self.0.file_type())
Expand Down Expand Up @@ -1080,6 +1082,7 @@ impl Metadata {
/// Ok(())
/// }
/// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> u64 {
self.0.size()
Expand All @@ -1099,6 +1102,7 @@ impl Metadata {
/// Ok(())
/// }
/// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn permissions(&self) -> Permissions {
Permissions(self.0.perm())
Expand Down Expand Up @@ -1246,6 +1250,7 @@ impl Permissions {
/// Ok(())
/// }
/// ```
#[must_use = "call `set_readonly` to modify the readonly flag"]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn readonly(&self) -> bool {
self.0.readonly()
Expand Down Expand Up @@ -1440,6 +1445,7 @@ impl DirEntry {
/// ```
///
/// The exact text, of course, depends on what files you have in `.`.
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn path(&self) -> PathBuf {
self.0.path()
Expand Down Expand Up @@ -1535,6 +1541,7 @@ impl DirEntry {
/// }
/// }
/// ```
#[must_use]
#[stable(feature = "dir_entry_ext", since = "1.1.0")]
pub fn file_name(&self) -> OsString {
self.0.file_name()
Expand Down
5 changes: 5 additions & 0 deletions library/std/src/io/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ impl Error {
/// println!("last OS error: {:?}", Error::last_os_error());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use]
#[inline]
pub fn last_os_error() -> Error {
Error::from_raw_os_error(sys::os::errno() as i32)
Expand Down Expand Up @@ -509,6 +510,7 @@ impl Error {
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use]
#[inline]
pub fn raw_os_error(&self) -> Option<i32> {
match self.repr {
Expand Down Expand Up @@ -547,6 +549,7 @@ impl Error {
/// }
/// ```
#[stable(feature = "io_error_inner", since = "1.3.0")]
#[must_use]
#[inline]
pub fn get_ref(&self) -> Option<&(dyn error::Error + Send + Sync + 'static)> {
match self.repr {
Expand Down Expand Up @@ -620,6 +623,7 @@ impl Error {
/// }
/// ```
#[stable(feature = "io_error_inner", since = "1.3.0")]
#[must_use]
#[inline]
pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error + Send + Sync + 'static)> {
match self.repr {
Expand Down Expand Up @@ -688,6 +692,7 @@ impl Error {
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use]
#[inline]
pub fn kind(&self) -> ErrorKind {
match self.repr {
Expand Down
Loading