Auto merge of #90434 - matthiaskrgr:rollup-xbn393a, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #89446 (Add paragraph to ControlFlow docs to menion it works with the ? operator (#88715)) - #89677 (Stabilize `is_symlink()` for `Metadata` and `Path`) - #89833 (Add #[must_use] to Rc::downgrade) - #89835 (Add #[must_use] to expensive computations) - #89839 (Add #[must_use] to mem/ptr functions) - #89897 (Add #[must_use] to remaining core functions) - #89951 (Stabilize `option_result_unwrap_unchecked`) - #90427 (Add #[must_use] to alloc functions that would leak memory) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
58899c4d9c
@ -81,6 +81,7 @@ pub use std::alloc::Global;
|
||||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "global_alloc", since = "1.28.0")]
|
||||
#[must_use = "losing the pointer will leak memory"]
|
||||
#[inline]
|
||||
pub unsafe fn alloc(layout: Layout) -> *mut u8 {
|
||||
unsafe { __rust_alloc(layout.size(), layout.align()) }
|
||||
@ -117,6 +118,7 @@ pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {
|
||||
///
|
||||
/// See [`GlobalAlloc::realloc`].
|
||||
#[stable(feature = "global_alloc", since = "1.28.0")]
|
||||
#[must_use = "losing the pointer will leak memory"]
|
||||
#[inline]
|
||||
pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
|
||||
unsafe { __rust_realloc(ptr, layout.size(), layout.align(), new_size) }
|
||||
@ -150,6 +152,7 @@ pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8
|
||||
/// }
|
||||
/// ```
|
||||
#[stable(feature = "global_alloc", since = "1.28.0")]
|
||||
#[must_use = "losing the pointer will leak memory"]
|
||||
#[inline]
|
||||
pub unsafe fn alloc_zeroed(layout: Layout) -> *mut u8 {
|
||||
unsafe { __rust_alloc_zeroed(layout.size(), layout.align()) }
|
||||
|
@ -137,6 +137,8 @@ pub struct Range<'a, T: 'a> {
|
||||
/// See its documentation for more.
|
||||
///
|
||||
/// [`difference`]: BTreeSet::difference
|
||||
#[must_use = "this returns the difference as an iterator, \
|
||||
without modifying either input set"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct Difference<'a, T: 'a> {
|
||||
inner: DifferenceInner<'a, T>,
|
||||
@ -169,6 +171,8 @@ impl<T: fmt::Debug> fmt::Debug for Difference<'_, T> {
|
||||
/// [`BTreeSet`]. See its documentation for more.
|
||||
///
|
||||
/// [`symmetric_difference`]: BTreeSet::symmetric_difference
|
||||
#[must_use = "this returns the difference as an iterator, \
|
||||
without modifying either input set"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct SymmetricDifference<'a, T: 'a>(MergeIterInner<Iter<'a, T>>);
|
||||
|
||||
@ -185,6 +189,8 @@ impl<T: fmt::Debug> fmt::Debug for SymmetricDifference<'_, T> {
|
||||
/// See its documentation for more.
|
||||
///
|
||||
/// [`intersection`]: BTreeSet::intersection
|
||||
#[must_use = "this returns the intersection as an iterator, \
|
||||
without modifying either input set"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct Intersection<'a, T: 'a> {
|
||||
inner: IntersectionInner<'a, T>,
|
||||
@ -217,6 +223,8 @@ impl<T: fmt::Debug> fmt::Debug for Intersection<'_, T> {
|
||||
/// See its documentation for more.
|
||||
///
|
||||
/// [`union`]: BTreeSet::union
|
||||
#[must_use = "this returns the union as an iterator, \
|
||||
without modifying either input set"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct Union<'a, T: 'a>(MergeIterInner<Iter<'a, T>>);
|
||||
|
||||
|
@ -112,7 +112,6 @@
|
||||
#![feature(maybe_uninit_slice)]
|
||||
#![cfg_attr(test, feature(new_uninit))]
|
||||
#![feature(nonnull_slice_from_raw_parts)]
|
||||
#![feature(option_result_unwrap_unchecked)]
|
||||
#![feature(pattern)]
|
||||
#![feature(ptr_internals)]
|
||||
#![feature(receiver_trait)]
|
||||
|
@ -41,7 +41,7 @@
|
||||
//! use std::rc::Rc;
|
||||
//!
|
||||
//! let my_rc = Rc::new(());
|
||||
//! Rc::downgrade(&my_rc);
|
||||
//! let my_weak = Rc::downgrade(&my_rc);
|
||||
//! ```
|
||||
//!
|
||||
//! `Rc<T>`'s implementations of traits like `Clone` may also be called using
|
||||
@ -889,6 +889,8 @@ impl<T: ?Sized> Rc<T> {
|
||||
///
|
||||
/// let weak_five = Rc::downgrade(&five);
|
||||
/// ```
|
||||
#[must_use = "this returns a new `Weak` pointer, \
|
||||
without modifying the original `Rc`"]
|
||||
#[stable(feature = "rc_weak", since = "1.4.0")]
|
||||
pub fn downgrade(this: &Self) -> Weak<T> {
|
||||
this.inner().inc_weak();
|
||||
|
@ -552,6 +552,7 @@ impl String {
|
||||
///
|
||||
/// assert_eq!("Hello <20>World", output);
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[cfg(not(no_global_oom_handling))]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn from_utf8_lossy(v: &[u8]) -> Cow<'_, str> {
|
||||
@ -646,6 +647,7 @@ impl String {
|
||||
/// String::from_utf16_lossy(v));
|
||||
/// ```
|
||||
#[cfg(not(no_global_oom_handling))]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn from_utf16_lossy(v: &[u16]) -> String {
|
||||
|
@ -804,6 +804,7 @@ impl<T: ?Sized> Arc<T> {
|
||||
/// let x_ptr = Arc::into_raw(x);
|
||||
/// assert_eq!(unsafe { &*x_ptr }, "hello");
|
||||
/// ```
|
||||
#[must_use = "losing the pointer will leak memory"]
|
||||
#[stable(feature = "rc_raw", since = "1.17.0")]
|
||||
pub fn into_raw(this: Self) -> *const T {
|
||||
let ptr = Self::as_ptr(&this);
|
||||
|
@ -1031,7 +1031,7 @@ fn test_split_at_mut() {
|
||||
#[should_panic]
|
||||
fn test_split_at_boundscheck() {
|
||||
let s = "ศไทย中华Việt Nam";
|
||||
s.split_at(1);
|
||||
let _ = s.split_at(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -104,6 +104,7 @@ impl Layout {
|
||||
/// The minimum size in bytes for a memory block of this layout.
|
||||
#[stable(feature = "alloc_layout", since = "1.28.0")]
|
||||
#[rustc_const_stable(feature = "const_alloc_layout", since = "1.50.0")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn size(&self) -> usize {
|
||||
self.size_
|
||||
@ -137,6 +138,7 @@ impl Layout {
|
||||
/// allocate backing structure for `T` (which could be a trait
|
||||
/// or other unsized type like a slice).
|
||||
#[stable(feature = "alloc_layout", since = "1.28.0")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub fn for_value<T: ?Sized>(t: &T) -> Self {
|
||||
let (size, align) = (mem::size_of_val(t), mem::align_of_val(t));
|
||||
@ -171,6 +173,7 @@ impl Layout {
|
||||
/// [trait object]: ../../book/ch17-02-trait-objects.html
|
||||
/// [extern type]: ../../unstable-book/language-features/extern-types.html
|
||||
#[unstable(feature = "layout_for_ptr", issue = "69835")]
|
||||
#[must_use]
|
||||
pub unsafe fn for_value_raw<T: ?Sized>(t: *const T) -> Self {
|
||||
// SAFETY: we pass along the prerequisites of these functions to the caller
|
||||
let (size, align) = unsafe { (mem::size_of_val_raw(t), mem::align_of_val_raw(t)) };
|
||||
@ -187,6 +190,7 @@ impl Layout {
|
||||
/// some other means.
|
||||
#[unstable(feature = "alloc_layout_extra", issue = "55724")]
|
||||
#[rustc_const_unstable(feature = "alloc_layout_extra", issue = "55724")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn dangling(&self) -> NonNull<u8> {
|
||||
// SAFETY: align is guaranteed to be non-zero
|
||||
|
@ -458,6 +458,7 @@ impl TypeId {
|
||||
/// assert_eq!(is_string(&0), false);
|
||||
/// assert_eq!(is_string(&"cookie monster".to_string()), true);
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_type_id", issue = "77125")]
|
||||
pub const fn of<T: ?Sized + 'static>() -> TypeId {
|
||||
@ -492,6 +493,7 @@ impl TypeId {
|
||||
/// "core::option::Option<alloc::string::String>",
|
||||
/// );
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[stable(feature = "type_name", since = "1.38.0")]
|
||||
#[rustc_const_unstable(feature = "const_type_name", issue = "63084")]
|
||||
pub const fn type_name<T: ?Sized>() -> &'static str {
|
||||
@ -534,6 +536,7 @@ pub const fn type_name<T: ?Sized>() -> &'static str {
|
||||
/// let y = 1.0;
|
||||
/// println!("{}", type_name_of_val(&y));
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[unstable(feature = "type_name_of_val", issue = "66359")]
|
||||
#[rustc_const_unstable(feature = "const_type_name", issue = "63084")]
|
||||
pub const fn type_name_of_val<T: ?Sized>(_val: &T) -> &'static str {
|
||||
|
@ -18,6 +18,7 @@ use crate::str::from_utf8_unchecked;
|
||||
///
|
||||
/// This `struct` is created by the [`escape_default`] function. See its
|
||||
/// documentation for more.
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[derive(Clone)]
|
||||
pub struct EscapeDefault {
|
||||
|
@ -1335,6 +1335,7 @@ impl<'b, T: ?Sized> Ref<'b, T> {
|
||||
/// with the widespread use of `r.borrow().clone()` to clone the contents of
|
||||
/// a `RefCell`.
|
||||
#[stable(feature = "cell_extras", since = "1.15.0")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub fn clone(orig: &Ref<'b, T>) -> Ref<'b, T> {
|
||||
Ref { value: orig.value, borrow: orig.borrow.clone() }
|
||||
|
@ -128,6 +128,7 @@ impl<I: Iterator<Item = u16>> Iterator for DecodeUtf16<I> {
|
||||
|
||||
impl DecodeUtf16Error {
|
||||
/// Returns the unpaired surrogate which caused this error.
|
||||
#[must_use]
|
||||
#[stable(feature = "decode_utf16", since = "1.9.0")]
|
||||
pub fn unpaired_surrogate(&self) -> u16 {
|
||||
self.code
|
||||
|
@ -155,6 +155,7 @@ pub trait Default: Sized {
|
||||
/// }
|
||||
/// ```
|
||||
#[unstable(feature = "default_free_fn", issue = "73014")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub fn default<T: Default>() -> T {
|
||||
Default::default()
|
||||
|
@ -1604,6 +1604,7 @@ impl<'a> Formatter<'a> {
|
||||
}
|
||||
|
||||
/// Flags for formatting
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_deprecated(
|
||||
since = "1.24.0",
|
||||
@ -1641,6 +1642,7 @@ impl<'a> Formatter<'a> {
|
||||
/// assert_eq!(&format!("{:G>3}", Foo), "GGG");
|
||||
/// assert_eq!(&format!("{:t>6}", Foo), "tttttt");
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[stable(feature = "fmt_flags", since = "1.5.0")]
|
||||
pub fn fill(&self) -> char {
|
||||
self.fill
|
||||
@ -1677,6 +1679,7 @@ impl<'a> Formatter<'a> {
|
||||
/// assert_eq!(&format!("{:^}", Foo), "center");
|
||||
/// assert_eq!(&format!("{}", Foo), "into the void");
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[stable(feature = "fmt_flags_align", since = "1.28.0")]
|
||||
pub fn align(&self) -> Option<Alignment> {
|
||||
match self.align {
|
||||
@ -1711,6 +1714,7 @@ impl<'a> Formatter<'a> {
|
||||
/// assert_eq!(&format!("{:10}", Foo(23)), "Foo(23) ");
|
||||
/// assert_eq!(&format!("{}", Foo(23)), "Foo(23)");
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[stable(feature = "fmt_flags", since = "1.5.0")]
|
||||
pub fn width(&self) -> Option<usize> {
|
||||
self.width
|
||||
@ -1741,6 +1745,7 @@ impl<'a> Formatter<'a> {
|
||||
/// assert_eq!(&format!("{:.4}", Foo(23.2)), "Foo(23.2000)");
|
||||
/// assert_eq!(&format!("{}", Foo(23.2)), "Foo(23.20)");
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[stable(feature = "fmt_flags", since = "1.5.0")]
|
||||
pub fn precision(&self) -> Option<usize> {
|
||||
self.precision
|
||||
@ -1771,6 +1776,7 @@ impl<'a> Formatter<'a> {
|
||||
/// assert_eq!(&format!("{:+}", Foo(23)), "Foo(+23)");
|
||||
/// assert_eq!(&format!("{}", Foo(23)), "Foo(23)");
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[stable(feature = "fmt_flags", since = "1.5.0")]
|
||||
pub fn sign_plus(&self) -> bool {
|
||||
self.flags & (1 << FlagV1::SignPlus as u32) != 0
|
||||
@ -1799,6 +1805,7 @@ impl<'a> Formatter<'a> {
|
||||
/// assert_eq!(&format!("{:-}", Foo(23)), "-Foo(23)");
|
||||
/// assert_eq!(&format!("{}", Foo(23)), "Foo(23)");
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[stable(feature = "fmt_flags", since = "1.5.0")]
|
||||
pub fn sign_minus(&self) -> bool {
|
||||
self.flags & (1 << FlagV1::SignMinus as u32) != 0
|
||||
@ -1826,6 +1833,7 @@ impl<'a> Formatter<'a> {
|
||||
/// assert_eq!(&format!("{:#}", Foo(23)), "Foo(23)");
|
||||
/// assert_eq!(&format!("{}", Foo(23)), "23");
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[stable(feature = "fmt_flags", since = "1.5.0")]
|
||||
pub fn alternate(&self) -> bool {
|
||||
self.flags & (1 << FlagV1::Alternate as u32) != 0
|
||||
@ -1851,6 +1859,7 @@ impl<'a> Formatter<'a> {
|
||||
///
|
||||
/// assert_eq!(&format!("{:04}", Foo(23)), "23");
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[stable(feature = "fmt_flags", since = "1.5.0")]
|
||||
pub fn sign_aware_zero_pad(&self) -> bool {
|
||||
self.flags & (1 << FlagV1::SignAwareZeroPad as u32) != 0
|
||||
|
@ -90,6 +90,7 @@ where
|
||||
#[lang = "get_context"]
|
||||
#[doc(hidden)]
|
||||
#[unstable(feature = "gen_future", issue = "50547")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub unsafe fn get_context<'a, 'b>(cx: ResumeTy) -> &'a mut Context<'b> {
|
||||
// SAFETY: the caller must guarantee that `cx.0` is a valid pointer
|
||||
|
@ -25,6 +25,7 @@ pub const fn empty<T>() -> Empty<T> {
|
||||
/// An iterator that yields nothing.
|
||||
///
|
||||
/// This `struct` is created by the [`empty()`] function. See its documentation for more.
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
#[stable(feature = "iter_empty", since = "1.2.0")]
|
||||
pub struct Empty<T>(marker::PhantomData<T>);
|
||||
|
||||
|
@ -296,6 +296,7 @@ pub fn forget_unsized<T: ?Sized>(t: T) {
|
||||
///
|
||||
/// [alignment]: align_of
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_promotable]
|
||||
#[rustc_const_stable(feature = "const_size_of", since = "1.24.0")]
|
||||
@ -324,6 +325,7 @@ pub const fn size_of<T>() -> usize {
|
||||
/// assert_eq!(13, mem::size_of_val(y));
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_size_of_val", issue = "46571")]
|
||||
#[cfg_attr(not(test), rustc_diagnostic_item = "mem_size_of_val")]
|
||||
@ -373,6 +375,7 @@ pub const fn size_of_val<T: ?Sized>(val: &T) -> usize {
|
||||
/// assert_eq!(13, unsafe { mem::size_of_val_raw(y) });
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[unstable(feature = "layout_for_ptr", issue = "69835")]
|
||||
#[rustc_const_unstable(feature = "const_size_of_val_raw", issue = "46571")]
|
||||
pub const unsafe fn size_of_val_raw<T: ?Sized>(val: *const T) -> usize {
|
||||
@ -397,6 +400,7 @@ pub const unsafe fn size_of_val_raw<T: ?Sized>(val: *const T) -> usize {
|
||||
/// assert_eq!(4, mem::min_align_of::<i32>());
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_deprecated(reason = "use `align_of` instead", since = "1.2.0")]
|
||||
pub fn min_align_of<T>() -> usize {
|
||||
@ -418,6 +422,7 @@ pub fn min_align_of<T>() -> usize {
|
||||
/// assert_eq!(4, mem::min_align_of_val(&5i32));
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_deprecated(reason = "use `align_of_val` instead", since = "1.2.0")]
|
||||
pub fn min_align_of_val<T: ?Sized>(val: &T) -> usize {
|
||||
@ -441,6 +446,7 @@ pub fn min_align_of_val<T: ?Sized>(val: &T) -> usize {
|
||||
/// assert_eq!(4, mem::align_of::<i32>());
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_promotable]
|
||||
#[rustc_const_stable(feature = "const_align_of", since = "1.24.0")]
|
||||
@ -462,6 +468,7 @@ pub const fn align_of<T>() -> usize {
|
||||
/// assert_eq!(4, mem::align_of_val(&5i32));
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_align_of_val", issue = "46571")]
|
||||
#[allow(deprecated)]
|
||||
@ -507,6 +514,7 @@ pub const fn align_of_val<T: ?Sized>(val: &T) -> usize {
|
||||
/// assert_eq!(4, unsafe { mem::align_of_val_raw(&5i32) });
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[unstable(feature = "layout_for_ptr", issue = "69835")]
|
||||
#[rustc_const_unstable(feature = "const_align_of_val_raw", issue = "46571")]
|
||||
pub const unsafe fn align_of_val_raw<T: ?Sized>(val: *const T) -> usize {
|
||||
@ -571,6 +579,7 @@ pub const unsafe fn align_of_val_raw<T: ?Sized>(val: *const T) -> usize {
|
||||
/// }
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "needs_drop", since = "1.21.0")]
|
||||
#[rustc_const_stable(feature = "const_needs_drop", since = "1.36.0")]
|
||||
#[rustc_diagnostic_item = "needs_drop"]
|
||||
@ -618,6 +627,7 @@ pub const fn needs_drop<T>() -> bool {
|
||||
/// let _y: fn() = unsafe { mem::zeroed() }; // And again!
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[allow(deprecated_in_future)]
|
||||
#[allow(deprecated)]
|
||||
@ -653,6 +663,7 @@ pub unsafe fn zeroed<T>() -> T {
|
||||
/// [assume_init]: MaybeUninit::assume_init
|
||||
/// [inv]: MaybeUninit#initialization-invariant
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
#[rustc_deprecated(since = "1.39.0", reason = "use `mem::MaybeUninit` instead")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[allow(deprecated_in_future)]
|
||||
@ -938,6 +949,7 @@ pub fn drop<T>(_x: T) {}
|
||||
/// assert_eq!(foo_array, [10]);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_transmute_copy", issue = "83165")]
|
||||
pub const unsafe fn transmute_copy<T, U>(src: &T) -> U {
|
||||
@ -1051,6 +1063,7 @@ pub const fn discriminant<T>(v: &T) -> Discriminant<T> {
|
||||
/// assert_eq!(mem::variant_count::<Result<!, !>>(), 2);
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
#[unstable(feature = "variant_count", issue = "73662")]
|
||||
#[rustc_const_unstable(feature = "variant_count", issue = "73662")]
|
||||
#[rustc_diagnostic_item = "mem_variant_count"]
|
||||
|
@ -115,6 +115,7 @@ pub enum IntErrorKind {
|
||||
|
||||
impl ParseIntError {
|
||||
/// Outputs the detailed cause of parsing an integer failing.
|
||||
#[must_use]
|
||||
#[stable(feature = "int_error_matching", since = "1.55.0")]
|
||||
pub fn kind(&self) -> &IntErrorKind {
|
||||
&self.kind
|
||||
|
@ -980,6 +980,7 @@ impl f32 {
|
||||
/// # .all(|(a, b)| a.to_bits() == b.to_bits()))
|
||||
/// ```
|
||||
#[unstable(feature = "total_cmp", issue = "72599")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub fn total_cmp(&self, other: &Self) -> crate::cmp::Ordering {
|
||||
let mut left = self.to_bits() as i32;
|
||||
|
@ -996,6 +996,7 @@ impl f64 {
|
||||
/// # .all(|(a, b)| a.to_bits() == b.to_bits()))
|
||||
/// ```
|
||||
#[unstable(feature = "total_cmp", issue = "72599")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub fn total_cmp(&self, other: &Self) -> crate::cmp::Ordering {
|
||||
let mut left = self.to_bits() as i64;
|
||||
|
@ -7,6 +7,10 @@ use crate::{convert, ops};
|
||||
/// Having the enum makes it clearer -- no more wondering "wait, what did `false`
|
||||
/// mean again?" -- and allows including a value.
|
||||
///
|
||||
/// Similar to [`Option`] and [`Result`], this enum can be used with the `?` operator
|
||||
/// to return immediately if the [`Break`] variant is present or otherwise continue normally
|
||||
/// with the value inside the [`Continue`] variant.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Early-exiting from [`Iterator::try_for_each`]:
|
||||
@ -71,6 +75,9 @@ use crate::{convert, ops};
|
||||
/// assert_eq!(res, ControlFlow::Break(-1));
|
||||
/// assert_eq!(sum, 6);
|
||||
/// ```
|
||||
///
|
||||
/// [`Break`]: ControlFlow::Break
|
||||
/// [`Continue`]: ControlFlow::Continue
|
||||
#[stable(feature = "control_flow_enum_type", since = "1.55.0")]
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub enum ControlFlow<B, C = ()> {
|
||||
|
@ -743,6 +743,7 @@ impl<T: Clone> Bound<&T> {
|
||||
/// assert_eq!((1..12).start_bound(), Included(&1));
|
||||
/// assert_eq!((1..12).start_bound().cloned(), Included(1));
|
||||
/// ```
|
||||
#[must_use = "`self` will be dropped if the result is not used"]
|
||||
#[stable(feature = "bound_cloned", since = "1.55.0")]
|
||||
pub fn cloned(self) -> Bound<T> {
|
||||
match self {
|
||||
|
@ -800,19 +800,17 @@ impl<T> Option<T> {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(option_result_unwrap_unchecked)]
|
||||
/// let x = Some("air");
|
||||
/// assert_eq!(unsafe { x.unwrap_unchecked() }, "air");
|
||||
/// ```
|
||||
///
|
||||
/// ```no_run
|
||||
/// #![feature(option_result_unwrap_unchecked)]
|
||||
/// let x: Option<&str> = None;
|
||||
/// assert_eq!(unsafe { x.unwrap_unchecked() }, "air"); // Undefined behavior!
|
||||
/// ```
|
||||
#[inline]
|
||||
#[track_caller]
|
||||
#[unstable(feature = "option_result_unwrap_unchecked", reason = "newly added", issue = "81383")]
|
||||
#[stable(feature = "option_result_unwrap_unchecked", since = "1.58.0")]
|
||||
pub unsafe fn unwrap_unchecked(self) -> T {
|
||||
debug_assert!(self.is_some());
|
||||
match self {
|
||||
@ -1451,6 +1449,7 @@ impl<T: Copy> Option<&T> {
|
||||
/// let copied = opt_x.copied();
|
||||
/// assert_eq!(copied, Some(12));
|
||||
/// ```
|
||||
#[must_use = "`self` will be dropped if the result is not used"]
|
||||
#[stable(feature = "copied", since = "1.35.0")]
|
||||
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
|
||||
pub const fn copied(self) -> Option<T> {
|
||||
|
@ -79,6 +79,7 @@ impl<'a> Location<'a> {
|
||||
/// assert_ne!(this_location.line(), another_location.line());
|
||||
/// assert_ne!(this_location.column(), another_location.column());
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[stable(feature = "track_caller", since = "1.46.0")]
|
||||
#[rustc_const_unstable(feature = "const_caller_location", issue = "76156")]
|
||||
#[track_caller]
|
||||
@ -119,6 +120,7 @@ impl<'a> Location<'a> {
|
||||
///
|
||||
/// panic!("Normal panic");
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[stable(feature = "panic_hooks", since = "1.10.0")]
|
||||
pub fn file(&self) -> &str {
|
||||
self.file
|
||||
@ -141,6 +143,7 @@ impl<'a> Location<'a> {
|
||||
///
|
||||
/// panic!("Normal panic");
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[stable(feature = "panic_hooks", since = "1.10.0")]
|
||||
pub fn line(&self) -> u32 {
|
||||
self.line
|
||||
@ -163,6 +166,7 @@ impl<'a> Location<'a> {
|
||||
///
|
||||
/// panic!("Normal panic");
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[stable(feature = "panic_col", since = "1.25.0")]
|
||||
pub fn column(&self) -> u32 {
|
||||
self.col
|
||||
|
@ -81,6 +81,7 @@ impl<'a> PanicInfo<'a> {
|
||||
///
|
||||
/// panic!("Normal panic");
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[stable(feature = "panic_hooks", since = "1.10.0")]
|
||||
pub fn payload(&self) -> &(dyn Any + Send) {
|
||||
self.payload
|
||||
@ -89,6 +90,7 @@ impl<'a> PanicInfo<'a> {
|
||||
/// If the `panic!` macro from the `core` crate (not from `std`)
|
||||
/// was used with a formatting string and some additional arguments,
|
||||
/// returns that message ready to be used for example with [`fmt::write`]
|
||||
#[must_use]
|
||||
#[unstable(feature = "panic_info_message", issue = "66745")]
|
||||
pub fn message(&self) -> Option<&fmt::Arguments<'_>> {
|
||||
self.message
|
||||
@ -118,6 +120,7 @@ impl<'a> PanicInfo<'a> {
|
||||
///
|
||||
/// panic!("Normal panic");
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[stable(feature = "panic_hooks", since = "1.10.0")]
|
||||
pub fn location(&self) -> Option<&Location<'_>> {
|
||||
// NOTE: If this is changed to sometimes return None,
|
||||
|
@ -705,6 +705,7 @@ impl<'a, T: ?Sized> Pin<&'a T> {
|
||||
///
|
||||
/// ["pinning projections"]: self#projections-and-structural-pinning
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
|
||||
#[stable(feature = "pin", since = "1.33.0")]
|
||||
pub const fn get_ref(self) -> &'a T {
|
||||
|
@ -204,6 +204,7 @@ pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
|
||||
/// assert!(p.is_null());
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_promotable]
|
||||
#[rustc_const_stable(feature = "const_ptr_null", since = "1.24.0")]
|
||||
@ -223,6 +224,7 @@ pub const fn null<T>() -> *const T {
|
||||
/// assert!(p.is_null());
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_promotable]
|
||||
#[rustc_const_stable(feature = "const_ptr_null", since = "1.24.0")]
|
||||
|
@ -83,6 +83,7 @@ impl<T: Sized> NonNull<T> {
|
||||
/// ```
|
||||
#[stable(feature = "nonnull", since = "1.25.0")]
|
||||
#[rustc_const_stable(feature = "const_nonnull_dangling", since = "1.36.0")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn dangling() -> Self {
|
||||
// SAFETY: mem::align_of() returns a non-zero usize which is then casted
|
||||
@ -423,6 +424,7 @@ impl<T> NonNull<[T]> {
|
||||
/// but `let slice = NonNull::from(&x[..]);` would be a better way to write code like this.)
|
||||
#[unstable(feature = "nonnull_slice_from_raw_parts", issue = "71941")]
|
||||
#[rustc_const_unstable(feature = "const_nonnull_slice_from_raw_parts", issue = "71941")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn slice_from_raw_parts(data: NonNull<T>, len: usize) -> Self {
|
||||
// SAFETY: `data` is a `NonNull` pointer which is necessarily non-null
|
||||
|
@ -68,6 +68,7 @@ impl<T: Sized> Unique<T> {
|
||||
/// a `T`, which means this must not be used as a "not yet initialized"
|
||||
/// sentinel value. Types that lazily allocate must track initialization by
|
||||
/// some other means.
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn dangling() -> Self {
|
||||
// SAFETY: mem::align_of() returns a valid, non-null pointer. The
|
||||
|
@ -1096,19 +1096,17 @@ impl<T, E> Result<T, E> {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(option_result_unwrap_unchecked)]
|
||||
/// let x: Result<u32, &str> = Ok(2);
|
||||
/// assert_eq!(unsafe { x.unwrap_unchecked() }, 2);
|
||||
/// ```
|
||||
///
|
||||
/// ```no_run
|
||||
/// #![feature(option_result_unwrap_unchecked)]
|
||||
/// let x: Result<u32, &str> = Err("emergency failure");
|
||||
/// unsafe { x.unwrap_unchecked(); } // Undefined behavior!
|
||||
/// ```
|
||||
#[inline]
|
||||
#[track_caller]
|
||||
#[unstable(feature = "option_result_unwrap_unchecked", reason = "newly added", issue = "81383")]
|
||||
#[stable(feature = "option_result_unwrap_unchecked", since = "1.58.0")]
|
||||
pub unsafe fn unwrap_unchecked(self) -> T {
|
||||
debug_assert!(self.is_ok());
|
||||
match self {
|
||||
@ -1130,19 +1128,17 @@ impl<T, E> Result<T, E> {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// #![feature(option_result_unwrap_unchecked)]
|
||||
/// let x: Result<u32, &str> = Ok(2);
|
||||
/// unsafe { x.unwrap_err_unchecked() }; // Undefined behavior!
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(option_result_unwrap_unchecked)]
|
||||
/// let x: Result<u32, &str> = Err("emergency failure");
|
||||
/// assert_eq!(unsafe { x.unwrap_err_unchecked() }, "emergency failure");
|
||||
/// ```
|
||||
#[inline]
|
||||
#[track_caller]
|
||||
#[unstable(feature = "option_result_unwrap_unchecked", reason = "newly added", issue = "81383")]
|
||||
#[stable(feature = "option_result_unwrap_unchecked", since = "1.58.0")]
|
||||
pub unsafe fn unwrap_err_unchecked(self) -> E {
|
||||
debug_assert!(self.is_err());
|
||||
match self {
|
||||
|
@ -11,6 +11,7 @@ use crate::ops;
|
||||
impl [u8] {
|
||||
/// Checks if all bytes in this slice are within the ASCII range.
|
||||
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub fn is_ascii(&self) -> bool {
|
||||
is_ascii(self)
|
||||
@ -21,6 +22,7 @@ impl [u8] {
|
||||
/// Same as `to_ascii_lowercase(a) == to_ascii_lowercase(b)`,
|
||||
/// but without allocating and copying temporaries.
|
||||
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub fn eq_ignore_ascii_case(&self, other: &[u8]) -> bool {
|
||||
self.len() == other.len() && iter::zip(self, other).all(|(a, b)| a.eq_ignore_ascii_case(b))
|
||||
|
@ -1724,6 +1724,7 @@ impl<'a, T> ChunksExact<'a, T> {
|
||||
/// Returns the remainder of the original slice that is not going to be
|
||||
/// returned by the iterator. The returned slice has at most `chunk_size-1`
|
||||
/// elements.
|
||||
#[must_use]
|
||||
#[stable(feature = "chunks_exact", since = "1.31.0")]
|
||||
pub fn remainder(&self) -> &'a [T] {
|
||||
self.rem
|
||||
@ -2153,6 +2154,7 @@ impl<'a, T, const N: usize> ArrayChunks<'a, T, N> {
|
||||
/// Returns the remainder of the original slice that is not going to be
|
||||
/// returned by the iterator. The returned slice has at most `N-1`
|
||||
/// elements.
|
||||
#[must_use]
|
||||
#[unstable(feature = "array_chunks", issue = "74985")]
|
||||
pub fn remainder(&self) -> &'a [T] {
|
||||
self.rem
|
||||
@ -2728,6 +2730,7 @@ impl<'a, T> RChunksExact<'a, T> {
|
||||
/// Returns the remainder of the original slice that is not going to be
|
||||
/// returned by the iterator. The returned slice has at most `chunk_size-1`
|
||||
/// elements.
|
||||
#[must_use]
|
||||
#[stable(feature = "rchunks", since = "1.31.0")]
|
||||
pub fn remainder(&self) -> &'a [T] {
|
||||
self.rem
|
||||
|
@ -37,6 +37,7 @@ fn repeat_byte(b: u8) -> usize {
|
||||
}
|
||||
|
||||
/// Returns the first index matching the byte `x` in `text`.
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub fn memchr(x: u8, text: &[u8]) -> Option<usize> {
|
||||
// Fast path for small slices
|
||||
@ -91,6 +92,7 @@ fn memchr_general_case(x: u8, text: &[u8]) -> Option<usize> {
|
||||
}
|
||||
|
||||
/// Returns the last index matching the byte `x` in `text`.
|
||||
#[must_use]
|
||||
pub fn memrchr(x: u8, text: &[u8]) -> Option<usize> {
|
||||
// Scan for a single byte value by reading two `usize` words at a time.
|
||||
//
|
||||
|
@ -72,6 +72,7 @@ impl Utf8Error {
|
||||
/// assert_eq!(1, error.valid_up_to());
|
||||
/// ```
|
||||
#[stable(feature = "utf8_error", since = "1.5.0")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub fn valid_up_to(&self) -> usize {
|
||||
self.valid_up_to
|
||||
@ -93,6 +94,7 @@ impl Utf8Error {
|
||||
///
|
||||
/// [U+FFFD]: ../../std/char/constant.REPLACEMENT_CHARACTER.html
|
||||
#[stable(feature = "utf8_error_error_len", since = "1.20.0")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub fn error_len(&self) -> Option<usize> {
|
||||
self.error_len.map(|len| len as usize)
|
||||
|
@ -27,6 +27,7 @@ use super::{IsAsciiWhitespace, IsNotEmpty, IsWhitespace};
|
||||
/// [`char`]: prim@char
|
||||
/// [`chars`]: str::chars
|
||||
#[derive(Clone)]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct Chars<'a> {
|
||||
pub(super) iter: slice::Iter<'a, u8>,
|
||||
@ -125,6 +126,7 @@ impl<'a> Chars<'a> {
|
||||
/// [`char`]: prim@char
|
||||
/// [`char_indices`]: str::char_indices
|
||||
#[derive(Clone, Debug)]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct CharIndices<'a> {
|
||||
pub(super) front_offset: usize,
|
||||
@ -211,6 +213,7 @@ impl<'a> CharIndices<'a> {
|
||||
/// assert_eq!(chars.next(), None);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[unstable(feature = "char_indices_offset", issue = "83871")]
|
||||
pub fn offset(&self) -> usize {
|
||||
self.front_offset
|
||||
@ -223,6 +226,7 @@ impl<'a> CharIndices<'a> {
|
||||
/// See its documentation for more.
|
||||
///
|
||||
/// [`bytes`]: str::bytes
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Bytes<'a>(pub(super) Copied<slice::Iter<'a, u8>>);
|
||||
@ -1089,6 +1093,7 @@ generate_pattern_iterators! {
|
||||
///
|
||||
/// [`lines`]: str::lines
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Lines<'a>(pub(super) Map<SplitTerminator<'a, char>, LinesAnyMap>);
|
||||
|
||||
@ -1128,6 +1133,7 @@ impl FusedIterator for Lines<'_> {}
|
||||
/// [`lines_any`]: str::lines_any
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_deprecated(since = "1.4.0", reason = "use lines()/Lines instead now")]
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
#[derive(Clone, Debug)]
|
||||
#[allow(deprecated)]
|
||||
pub struct LinesAny<'a>(pub(super) Lines<'a>);
|
||||
|
@ -29,6 +29,7 @@ impl Utf8Lossy {
|
||||
}
|
||||
|
||||
/// Iterator over lossy UTF-8 string
|
||||
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
||||
#[unstable(feature = "str_internals", issue = "none")]
|
||||
#[allow(missing_debug_implementations)]
|
||||
pub struct Utf8LossyChunksIter<'a> {
|
||||
|
@ -498,6 +498,7 @@ impl str {
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_deprecated(since = "1.29.0", reason = "use `get_unchecked(begin..end)` instead")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub unsafe fn slice_unchecked(&self, begin: usize, end: usize) -> &str {
|
||||
// SAFETY: the caller must uphold the safety contract for `get_unchecked`;
|
||||
@ -570,6 +571,7 @@ impl str {
|
||||
/// assert_eq!(" Martin-Löf", last);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "str_split_at", since = "1.4.0")]
|
||||
pub fn split_at(&self, mid: usize) -> (&str, &str) {
|
||||
// is_char_boundary checks that the index is in [0, .len()]
|
||||
@ -613,6 +615,7 @@ impl str {
|
||||
/// assert_eq!("PER Martin-Löf", s);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "str_split_at", since = "1.4.0")]
|
||||
pub fn split_at_mut(&mut self, mid: usize) -> (&mut str, &mut str) {
|
||||
// is_char_boundary checks that the index is in [0, .len()]
|
||||
@ -2255,6 +2258,7 @@ impl str {
|
||||
/// assert!(!non_ascii.is_ascii());
|
||||
/// ```
|
||||
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub fn is_ascii(&self) -> bool {
|
||||
// We can treat each byte as character here: all multibyte characters
|
||||
@ -2276,6 +2280,7 @@ impl str {
|
||||
/// assert!(!"Ferrös".eq_ignore_ascii_case("FERRÖS"));
|
||||
/// ```
|
||||
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub fn eq_ignore_ascii_case(&self, other: &str) -> bool {
|
||||
self.as_bytes().eq_ignore_ascii_case(other.as_bytes())
|
||||
|
@ -251,6 +251,7 @@ static UTF8_CHAR_WIDTH: [u8; 256] = [
|
||||
|
||||
/// Given a first byte, determines how many bytes are in this UTF-8 character.
|
||||
#[unstable(feature = "str_internals", issue = "none")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub fn utf8_char_width(b: u8) -> usize {
|
||||
UTF8_CHAR_WIDTH[b as usize] as usize
|
||||
|
@ -167,6 +167,7 @@ impl<'a> Context<'a> {
|
||||
|
||||
/// Returns a reference to the `Waker` for the current task.
|
||||
#[stable(feature = "futures_api", since = "1.36.0")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub fn waker(&self) -> &'a Waker {
|
||||
&self.waker
|
||||
@ -242,6 +243,7 @@ impl Waker {
|
||||
///
|
||||
/// This function is primarily used for optimization purposes.
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "futures_api", since = "1.36.0")]
|
||||
pub fn will_wake(&self, other: &Waker) -> bool {
|
||||
self.waker == other.waker
|
||||
|
@ -357,6 +357,7 @@ impl Duration {
|
||||
/// ```
|
||||
#[stable(feature = "duration_extras", since = "1.27.0")]
|
||||
#[rustc_const_stable(feature = "duration_extras", since = "1.32.0")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn subsec_millis(&self) -> u32 {
|
||||
self.nanos / NANOS_PER_MILLI
|
||||
@ -379,6 +380,7 @@ impl Duration {
|
||||
/// ```
|
||||
#[stable(feature = "duration_extras", since = "1.27.0")]
|
||||
#[rustc_const_stable(feature = "duration_extras", since = "1.32.0")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn subsec_micros(&self) -> u32 {
|
||||
self.nanos / NANOS_PER_MICRO
|
||||
@ -401,6 +403,7 @@ impl Duration {
|
||||
/// ```
|
||||
#[stable(feature = "duration", since = "1.3.0")]
|
||||
#[rustc_const_stable(feature = "duration", since = "1.32.0")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn subsec_nanos(&self) -> u32 {
|
||||
self.nanos
|
||||
|
@ -115,7 +115,7 @@ fn test_eq_ignore_ascii_case() {
|
||||
#[test]
|
||||
fn inference_works() {
|
||||
let x = "a".to_string();
|
||||
x.eq_ignore_ascii_case("A");
|
||||
let _ = x.eq_ignore_ascii_case("A");
|
||||
}
|
||||
|
||||
// Shorthands used by the is_ascii_* tests.
|
||||
|
@ -59,7 +59,6 @@
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
#![feature(never_type)]
|
||||
#![feature(unwrap_infallible)]
|
||||
#![feature(option_result_unwrap_unchecked)]
|
||||
#![feature(result_into_ok_or_err)]
|
||||
#![feature(ptr_metadata)]
|
||||
#![feature(once_cell)]
|
||||
|
@ -1320,6 +1320,8 @@ where
|
||||
///
|
||||
/// let mut intersection = a.intersection(&b);
|
||||
/// ```
|
||||
#[must_use = "this returns the intersection as an iterator, \
|
||||
without modifying either input set"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct Intersection<'a, T: 'a, S: 'a> {
|
||||
// iterator of the first set
|
||||
@ -1345,6 +1347,8 @@ pub struct Intersection<'a, T: 'a, S: 'a> {
|
||||
///
|
||||
/// let mut difference = a.difference(&b);
|
||||
/// ```
|
||||
#[must_use = "this returns the difference as an iterator, \
|
||||
without modifying either input set"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct Difference<'a, T: 'a, S: 'a> {
|
||||
// iterator of the first set
|
||||
@ -1370,6 +1374,8 @@ pub struct Difference<'a, T: 'a, S: 'a> {
|
||||
///
|
||||
/// let mut intersection = a.symmetric_difference(&b);
|
||||
/// ```
|
||||
#[must_use = "this returns the difference as an iterator, \
|
||||
without modifying either input set"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct SymmetricDifference<'a, T: 'a, S: 'a> {
|
||||
iter: Chain<Difference<'a, T, S>, Difference<'a, T, S>>,
|
||||
@ -1392,6 +1398,8 @@ pub struct SymmetricDifference<'a, T: 'a, S: 'a> {
|
||||
///
|
||||
/// let mut union_iter = a.union(&b);
|
||||
/// ```
|
||||
#[must_use = "this returns the union as an iterator, \
|
||||
without modifying either input set"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct Union<'a, T: 'a, S: 'a> {
|
||||
iter: Chain<Iter<'a, T>, Difference<'a, T, S>>,
|
||||
|
@ -829,6 +829,7 @@ impl OsStr {
|
||||
/// assert!(!non_ascii.is_ascii());
|
||||
/// ```
|
||||
#[stable(feature = "osstring_ascii", since = "1.53.0")]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub fn is_ascii(&self) -> bool {
|
||||
self.inner.is_ascii()
|
||||
|
@ -1046,7 +1046,6 @@ impl Metadata {
|
||||
///
|
||||
#[cfg_attr(unix, doc = "```no_run")]
|
||||
#[cfg_attr(not(unix), doc = "```ignore")]
|
||||
/// #![feature(is_symlink)]
|
||||
/// use std::fs;
|
||||
/// use std::path::Path;
|
||||
/// use std::os::unix::fs::symlink;
|
||||
@ -1062,7 +1061,7 @@ impl Metadata {
|
||||
/// }
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[unstable(feature = "is_symlink", issue = "85748")]
|
||||
#[stable(feature = "is_symlink", since = "1.57.0")]
|
||||
pub fn is_symlink(&self) -> bool {
|
||||
self.file_type().is_symlink()
|
||||
}
|
||||
|
@ -487,6 +487,7 @@ impl Stdin {
|
||||
/// println!("got a chunk: {}", String::from_utf8_lossy(&split.unwrap()));
|
||||
/// }
|
||||
/// ```
|
||||
#[must_use = "`self` will be dropped if the result is not used"]
|
||||
#[unstable(feature = "stdin_forwarders", issue = "87096")]
|
||||
pub fn split(self, byte: u8) -> Split<StdinLock<'static>> {
|
||||
self.into_locked().split(byte)
|
||||
|
@ -2751,7 +2751,7 @@ impl Path {
|
||||
fs::metadata(self).map(|m| m.is_dir()).unwrap_or(false)
|
||||
}
|
||||
|
||||
/// Returns true if the path exists on disk and is pointing at a symbolic link.
|
||||
/// Returns `true` if the path exists on disk and is pointing at a symbolic link.
|
||||
///
|
||||
/// This function will not traverse symbolic links.
|
||||
/// In case of a broken symbolic link this will also return true.
|
||||
@ -2763,7 +2763,6 @@ impl Path {
|
||||
///
|
||||
#[cfg_attr(unix, doc = "```no_run")]
|
||||
#[cfg_attr(not(unix), doc = "```ignore")]
|
||||
/// #![feature(is_symlink)]
|
||||
/// use std::path::Path;
|
||||
/// use std::os::unix::fs::symlink;
|
||||
///
|
||||
@ -2772,8 +2771,14 @@ impl Path {
|
||||
/// assert_eq!(link_path.is_symlink(), true);
|
||||
/// assert_eq!(link_path.exists(), false);
|
||||
/// ```
|
||||
#[unstable(feature = "is_symlink", issue = "85748")]
|
||||
///
|
||||
/// # See Also
|
||||
///
|
||||
/// This is a convenience function that coerces errors to false. If you want to
|
||||
/// check errors, call [`fs::symlink_metadata`] and handle its [`Result`]. Then call
|
||||
/// [`fs::Metadata::is_symlink`] if it was [`Ok`].
|
||||
#[must_use]
|
||||
#[stable(feature = "is_symlink", since = "1.57.0")]
|
||||
pub fn is_symlink(&self) -> bool {
|
||||
fs::symlink_metadata(self).map(|m| m.is_symlink()).unwrap_or(false)
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ struct PtrBack<T: Front>(Vec<T::Back>);
|
||||
|
||||
struct M(PtrBack<Vec<M>>);
|
||||
|
||||
#[allow(unused_must_use)]
|
||||
fn main() {
|
||||
std::mem::size_of::<M>();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user