diff --git a/library/alloc/src/collections/binary_heap.rs b/library/alloc/src/collections/binary_heap.rs
index cfb1cd09c3975..46458099135e8 100644
--- a/library/alloc/src/collections/binary_heap.rs
+++ b/library/alloc/src/collections/binary_heap.rs
@@ -1009,6 +1009,7 @@ impl BinaryHeap {
///
/// io::sink().write(heap.as_slice()).unwrap();
/// ```
+ #[must_use]
#[unstable(feature = "binary_heap_as_slice", issue = "83659")]
pub fn as_slice(&self) -> &[T] {
self.data.as_slice()
@@ -1049,6 +1050,7 @@ impl BinaryHeap {
///
/// assert_eq!(heap.len(), 2);
/// ```
+ #[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> usize {
self.data.len()
@@ -1072,6 +1074,7 @@ impl BinaryHeap {
///
/// assert!(!heap.is_empty());
/// ```
+ #[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool {
self.len() == 0
diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs
index fa86e611565e6..df6c6d494d4ef 100644
--- a/library/alloc/src/collections/btree/map.rs
+++ b/library/alloc/src/collections/btree/map.rs
@@ -2205,6 +2205,7 @@ impl BTreeMap {
/// 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 {
@@ -2225,6 +2226,7 @@ impl BTreeMap {
/// 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 {
diff --git a/library/alloc/src/collections/btree/set.rs b/library/alloc/src/collections/btree/set.rs
index d732f65b0d05f..2d411ff8ada8d 100644
--- a/library/alloc/src/collections/btree/set.rs
+++ b/library/alloc/src/collections/btree/set.rs
@@ -1034,6 +1034,7 @@ impl BTreeSet {
/// 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 {
@@ -1052,6 +1053,7 @@ impl BTreeSet {
/// 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 {
diff --git a/library/alloc/src/collections/btree/set/tests.rs b/library/alloc/src/collections/btree/set/tests.rs
index 0a87ae12d61a5..2fc17a7c8603f 100644
--- a/library/alloc/src/collections/btree/set/tests.rs
+++ b/library/alloc/src/collections/btree/set/tests.rs
@@ -610,11 +610,11 @@ fn test_send() {
#[test]
fn test_ord_absence() {
fn set(mut set: BTreeSet) {
- set.is_empty();
- set.len();
+ let _ = set.is_empty();
+ let _ = set.len();
set.clear();
- set.iter();
- set.into_iter();
+ let _ = set.iter();
+ let _ = set.into_iter();
}
fn set_debug(set: BTreeSet) {
diff --git a/library/alloc/src/collections/linked_list.rs b/library/alloc/src/collections/linked_list.rs
index 6dcba318c3598..92589f818c995 100644
--- a/library/alloc/src/collections/linked_list.rs
+++ b/library/alloc/src/collections/linked_list.rs
@@ -577,6 +577,7 @@ impl LinkedList {
/// assert!(!dl.is_empty());
/// ```
#[inline]
+ #[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn is_empty(&self) -> bool {
self.head.is_none()
@@ -603,6 +604,7 @@ impl LinkedList {
/// assert_eq!(dl.len(), 3);
/// ```
#[inline]
+ #[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> usize {
self.len
@@ -1385,6 +1387,7 @@ impl<'a, T> CursorMut<'a, T> {
/// The lifetime of the returned `Cursor` is bound to that of the
/// `CursorMut`, which means it cannot outlive the `CursorMut` and that the
/// `CursorMut` is frozen for the lifetime of the `Cursor`.
+ #[must_use]
#[unstable(feature = "linked_list_cursors", issue = "58533")]
pub fn as_cursor(&self) -> Cursor<'_, T> {
Cursor { list: self.list, current: self.current, index: self.index }
diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs
index 2f4a131136e92..493cf3117edf6 100644
--- a/library/alloc/src/rc.rs
+++ b/library/alloc/src/rc.rs
@@ -2093,6 +2093,7 @@ impl Weak {
/// ```
///
/// [`null`]: ptr::null
+ #[must_use]
#[stable(feature = "rc_as_ptr", since = "1.45.0")]
pub fn as_ptr(&self) -> *const T {
let ptr: *mut RcBox = NonNull::as_ptr(self.ptr);
@@ -2229,6 +2230,8 @@ impl Weak {
///
/// assert!(weak_five.upgrade().is_none());
/// ```
+ #[must_use = "this returns a new `Rc`, \
+ without modifying the original weak pointer"]
#[stable(feature = "rc_weak", since = "1.4.0")]
pub fn upgrade(&self) -> Option> {
let inner = self.inner()?;
diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs
index f11fa92766f1f..3a83c07fc38b2 100644
--- a/library/alloc/src/string.rs
+++ b/library/alloc/src/string.rs
@@ -803,6 +803,7 @@ impl String {
/// assert_eq!("foo", s.as_str());
/// ```
#[inline]
+ #[must_use]
#[stable(feature = "string_as_str", since = "1.7.0")]
pub fn as_str(&self) -> &str {
self
@@ -823,6 +824,7 @@ impl String {
/// assert_eq!("FOOBAR", s_mut_str);
/// ```
#[inline]
+ #[must_use]
#[stable(feature = "string_as_str", since = "1.7.0")]
pub fn as_mut_str(&mut self) -> &mut str {
self
@@ -1163,6 +1165,7 @@ impl String {
/// assert_eq!(&[104, 101, 108, 108, 111], s.as_bytes());
/// ```
#[inline]
+ #[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn as_bytes(&self) -> &[u8] {
&self.vec
@@ -1540,6 +1543,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()
@@ -1559,6 +1563,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
@@ -1766,6 +1771,7 @@ impl FromUtf8Error {
///
/// assert_eq!(&[0, 159], value.unwrap_err().as_bytes());
/// ```
+ #[must_use]
#[stable(feature = "from_utf8_error_as_bytes", since = "1.26.0")]
pub fn as_bytes(&self) -> &[u8] {
&self.bytes[..]
@@ -2782,6 +2788,7 @@ impl<'a> Drain<'a> {
/// let _ = drain.next().unwrap();
/// assert_eq!(drain.as_str(), "bc");
/// ```
+ #[must_use]
#[stable(feature = "string_drain_as_str", since = "1.55.0")]
pub fn as_str(&self) -> &str {
self.iter.as_str()
diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs
index 1d4216d7d571a..b75e9a2f3c71e 100644
--- a/library/alloc/src/sync.rs
+++ b/library/alloc/src/sync.rs
@@ -146,7 +146,7 @@ macro_rules! acquire {
/// use std::sync::Arc;
///
/// let my_arc = Arc::new(());
-/// Arc::downgrade(&my_arc);
+/// let my_weak = Arc::downgrade(&my_arc);
/// ```
///
/// `Arc`'s implementations of traits like `Clone` may also be called using
@@ -827,6 +827,7 @@ impl Arc {
/// assert_eq!(x_ptr, Arc::as_ptr(&y));
/// assert_eq!(unsafe { &*x_ptr }, "hello");
/// ```
+ #[must_use]
#[stable(feature = "rc_as_ptr", since = "1.45.0")]
pub fn as_ptr(this: &Self) -> *const T {
let ptr: *mut ArcInner = NonNull::as_ptr(this.ptr);
@@ -897,6 +898,8 @@ impl Arc {
///
/// let weak_five = Arc::downgrade(&five);
/// ```
+ #[must_use = "this returns a new `Weak` pointer, \
+ without modifying the original `Arc`"]
#[stable(feature = "arc_weak", since = "1.4.0")]
pub fn downgrade(this: &Self) -> Weak {
// This Relaxed is OK because we're checking the value in the CAS
@@ -1724,6 +1727,7 @@ impl Weak {
/// ```
///
/// [`null`]: core::ptr::null "ptr::null"
+ #[must_use]
#[stable(feature = "weak_into_raw", since = "1.45.0")]
pub fn as_ptr(&self) -> *const T {
let ptr: *mut ArcInner = NonNull::as_ptr(self.ptr);
@@ -1861,6 +1865,8 @@ impl Weak {
///
/// assert!(weak_five.upgrade().is_none());
/// ```
+ #[must_use = "this returns a new `Arc`, \
+ without modifying the original weak pointer"]
#[stable(feature = "arc_weak", since = "1.4.0")]
pub fn upgrade(&self) -> Option> {
// We use a CAS loop to increment the strong count instead of a
diff --git a/library/alloc/src/vec/drain.rs b/library/alloc/src/vec/drain.rs
index fb32d144f872c..e643940d017ba 100644
--- a/library/alloc/src/vec/drain.rs
+++ b/library/alloc/src/vec/drain.rs
@@ -52,6 +52,7 @@ impl<'a, T, A: Allocator> Drain<'a, T, A> {
/// let _ = drain.next().unwrap();
/// assert_eq!(drain.as_slice(), &['b', 'c']);
/// ```
+ #[must_use]
#[stable(feature = "vec_drain_as_slice", since = "1.46.0")]
pub fn as_slice(&self) -> &[T] {
self.iter.as_slice()
diff --git a/library/core/src/alloc/layout.rs b/library/core/src/alloc/layout.rs
index d4c8ea33501a6..780f82d8afaee 100644
--- a/library/core/src/alloc/layout.rs
+++ b/library/core/src/alloc/layout.rs
@@ -112,6 +112,8 @@ impl Layout {
/// The minimum byte alignment 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 = "this returns the minimum alignment, \
+ without modifying the layout"]
#[inline]
pub const fn align(&self) -> usize {
self.align_.get()
@@ -229,6 +231,8 @@ impl Layout {
/// satisfy this constraint is to ensure `align <= self.align()`.
#[unstable(feature = "alloc_layout_extra", issue = "55724")]
#[rustc_const_unstable(feature = "const_alloc_layout", issue = "67521")]
+ #[must_use = "this returns the padding needed, \
+ without modifying the `Layout`"]
#[inline]
pub const fn padding_needed_for(&self, align: usize) -> usize {
let len = self.size();
@@ -262,6 +266,8 @@ impl Layout {
/// This is equivalent to adding the result of `padding_needed_for`
/// to the layout's current size.
#[stable(feature = "alloc_layout_manipulation", since = "1.44.0")]
+ #[must_use = "this returns a new `Layout`, \
+ without modifying the original"]
#[inline]
pub fn pad_to_align(&self) -> Layout {
let pad = self.padding_needed_for(self.align());
diff --git a/library/core/src/convert/mod.rs b/library/core/src/convert/mod.rs
index abeeef1a17ee0..83a73d9cbe506 100644
--- a/library/core/src/convert/mod.rs
+++ b/library/core/src/convert/mod.rs
@@ -273,6 +273,7 @@ pub trait AsMut {
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Into: Sized {
/// Performs the conversion.
+ #[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
fn into(self) -> T;
}
@@ -367,6 +368,7 @@ pub trait Into: Sized {
pub trait From: Sized {
/// Performs the conversion.
#[lang = "from"]
+ #[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
fn from(_: T) -> Self;
}
diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs
index d10563a40976d..b8ad7720e0c55 100644
--- a/library/core/src/fmt/mod.rs
+++ b/library/core/src/fmt/mod.rs
@@ -491,6 +491,7 @@ impl<'a> Arguments<'a> {
/// ```
#[stable(feature = "fmt_as_str", since = "1.52.0")]
#[rustc_const_unstable(feature = "const_arguments_as_str", issue = "none")]
+ #[must_use]
#[inline]
pub const fn as_str(&self) -> Option<&'static str> {
match (self.pieces, self.args) {
diff --git a/library/core/src/mem/maybe_uninit.rs b/library/core/src/mem/maybe_uninit.rs
index b9772eaa67813..624e87955022f 100644
--- a/library/core/src/mem/maybe_uninit.rs
+++ b/library/core/src/mem/maybe_uninit.rs
@@ -291,6 +291,7 @@ impl MaybeUninit {
/// [`assume_init`]: MaybeUninit::assume_init
#[stable(feature = "maybe_uninit", since = "1.36.0")]
#[rustc_const_stable(feature = "const_maybe_uninit", since = "1.36.0")]
+ #[must_use = "use `forget` to avoid running Drop code"]
#[inline(always)]
pub const fn new(val: T) -> MaybeUninit {
MaybeUninit { value: ManuallyDrop::new(val) }
diff --git a/library/core/src/option.rs b/library/core/src/option.rs
index df8af22a317bc..401267f5613ee 100644
--- a/library/core/src/option.rs
+++ b/library/core/src/option.rs
@@ -657,6 +657,7 @@ impl Option {
///
/// [&]: reference "shared reference"
#[inline]
+ #[must_use]
#[stable(feature = "pin", since = "1.33.0")]
pub fn as_pin_ref(self: Pin<&Self>) -> Option> {
// SAFETY: `x` is guaranteed to be pinned because it comes from `self`
@@ -668,6 +669,7 @@ impl Option {
///
/// [&mut]: reference "mutable reference"
#[inline]
+ #[must_use]
#[stable(feature = "pin", since = "1.33.0")]
pub fn as_pin_mut(self: Pin<&mut Self>) -> Option> {
// SAFETY: `get_unchecked_mut` is never used to move the `Option` inside `self`.
diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs
index 87c8674af0dc5..5a2ea053560d6 100644
--- a/library/core/src/ptr/non_null.rs
+++ b/library/core/src/ptr/non_null.rs
@@ -119,6 +119,7 @@ impl NonNull {
///
/// [the module documentation]: crate::ptr#safety
#[inline]
+ #[must_use]
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
pub unsafe fn as_uninit_ref<'a>(&self) -> &'a MaybeUninit {
// SAFETY: the caller must guarantee that `self` meets all the
@@ -151,6 +152,7 @@ impl NonNull {
///
/// [the module documentation]: crate::ptr#safety
#[inline]
+ #[must_use]
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
pub unsafe fn as_uninit_mut<'a>(&mut self) -> &'a mut MaybeUninit {
// SAFETY: the caller must guarantee that `self` meets all the
@@ -264,6 +266,7 @@ impl NonNull {
/// ```
#[stable(feature = "nonnull", since = "1.25.0")]
#[rustc_const_stable(feature = "const_nonnull_as_ptr", since = "1.32.0")]
+ #[must_use]
#[inline]
pub const fn as_ptr(self) -> *mut T {
self.pointer as *mut T
@@ -310,6 +313,7 @@ impl NonNull {
///
/// [the module documentation]: crate::ptr#safety
#[stable(feature = "nonnull", since = "1.25.0")]
+ #[must_use]
#[inline]
pub unsafe fn as_ref<'a>(&self) -> &'a T {
// SAFETY: the caller must guarantee that `self` meets all the
@@ -359,6 +363,7 @@ impl NonNull {
///
/// [the module documentation]: crate::ptr#safety
#[stable(feature = "nonnull", since = "1.25.0")]
+ #[must_use]
#[inline]
pub unsafe fn as_mut<'a>(&mut self) -> &'a mut T {
// SAFETY: the caller must guarantee that `self` meets all the
@@ -438,6 +443,7 @@ impl 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()
@@ -455,6 +461,7 @@ impl NonNull<[T]> {
/// assert_eq!(slice.as_non_null_ptr(), NonNull::new(1 as *mut i8).unwrap());
/// ```
#[inline]
+ #[must_use]
#[unstable(feature = "slice_ptr_get", issue = "74265")]
#[rustc_const_unstable(feature = "slice_ptr_get", issue = "74265")]
pub const fn as_non_null_ptr(self) -> NonNull {
@@ -474,6 +481,7 @@ impl NonNull<[T]> {
/// assert_eq!(slice.as_mut_ptr(), 1 as *mut i8);
/// ```
#[inline]
+ #[must_use]
#[unstable(feature = "slice_ptr_get", issue = "74265")]
#[rustc_const_unstable(feature = "slice_ptr_get", issue = "74265")]
pub const fn as_mut_ptr(self) -> *mut T {
@@ -518,6 +526,7 @@ impl NonNull<[T]> {
///
/// [valid]: crate::ptr#safety
#[inline]
+ #[must_use]
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
pub unsafe fn as_uninit_slice<'a>(&self) -> &'a [MaybeUninit] {
// SAFETY: the caller must uphold the safety contract for `as_uninit_slice`.
@@ -579,6 +588,7 @@ impl NonNull<[T]> {
/// # Ok::<_, std::alloc::AllocError>(())
/// ```
#[inline]
+ #[must_use]
#[unstable(feature = "ptr_as_uninit", issue = "75402")]
pub unsafe fn as_uninit_slice_mut<'a>(&self) -> &'a mut [MaybeUninit] {
// SAFETY: the caller must uphold the safety contract for `as_uninit_slice_mut`.
diff --git a/library/core/src/ptr/unique.rs b/library/core/src/ptr/unique.rs
index b3deddca18efe..5baceefb504a5 100644
--- a/library/core/src/ptr/unique.rs
+++ b/library/core/src/ptr/unique.rs
@@ -112,6 +112,7 @@ impl Unique {
/// The resulting lifetime is bound to self so this behaves "as if"
/// it were actually an instance of T that is getting borrowed. If a longer
/// (unbound) lifetime is needed, use `&*my_ptr.as_ptr()`.
+ #[must_use]
#[inline]
pub unsafe fn as_ref(&self) -> &T {
// SAFETY: the caller must guarantee that `self` meets all the
@@ -124,6 +125,7 @@ impl Unique {
/// The resulting lifetime is bound to self so this behaves "as if"
/// it were actually an instance of T that is getting borrowed. If a longer
/// (unbound) lifetime is needed, use `&mut *my_ptr.as_ptr()`.
+ #[must_use]
#[inline]
pub unsafe fn as_mut(&mut self) -> &mut T {
// SAFETY: the caller must guarantee that `self` meets all the
diff --git a/library/core/src/slice/iter.rs b/library/core/src/slice/iter.rs
index 70e59cda63f26..dbf97851b03e4 100644
--- a/library/core/src/slice/iter.rs
+++ b/library/core/src/slice/iter.rs
@@ -124,6 +124,7 @@ impl<'a, T> Iter<'a, T> {
/// // Now `as_slice` returns "[2, 3]":
/// println!("{:?}", iter.as_slice());
/// ```
+ #[must_use]
#[stable(feature = "iter_to_slice", since = "1.4.0")]
pub fn as_slice(&self) -> &'a [T] {
self.make_slice()
@@ -298,6 +299,7 @@ impl<'a, T> IterMut<'a, T> {
/// // Now `as_slice` returns "[2, 3]":
/// assert_eq!(iter.as_slice(), &[2, 3]);
/// ```
+ #[must_use]
#[stable(feature = "slice_iter_mut_as_slice", since = "1.53.0")]
pub fn as_slice(&self) -> &[T] {
self.make_slice()
diff --git a/library/core/src/str/iter.rs b/library/core/src/str/iter.rs
index 8db9edc61472f..94cb81e9d41a1 100644
--- a/library/core/src/str/iter.rs
+++ b/library/core/src/str/iter.rs
@@ -109,6 +109,7 @@ impl<'a> Chars<'a> {
/// assert_eq!(chars.as_str(), "");
/// ```
#[stable(feature = "iter_to_slice", since = "1.4.0")]
+ #[must_use]
#[inline]
pub fn as_str(&self) -> &'a str {
// SAFETY: `Chars` is only made from a str, which guarantees the iter is valid UTF-8.
@@ -185,6 +186,7 @@ impl<'a> CharIndices<'a> {
/// This has the same lifetime as the original slice, and so the
/// iterator can continue to be used while this exists.
#[stable(feature = "iter_to_slice", since = "1.4.0")]
+ #[must_use]
#[inline]
pub fn as_str(&self) -> &'a str {
self.iter.as_str()
@@ -1247,6 +1249,7 @@ impl<'a> SplitWhitespace<'a> {
/// assert_eq!(split.as_str(), "");
/// ```
#[inline]
+ #[must_use]
#[unstable(feature = "str_split_whitespace_as_str", issue = "77998")]
pub fn as_str(&self) -> &'a str {
self.inner.iter.as_str()
@@ -1302,6 +1305,7 @@ impl<'a> SplitAsciiWhitespace<'a> {
/// assert_eq!(split.as_str(), "");
/// ```
#[inline]
+ #[must_use]
#[unstable(feature = "str_split_whitespace_as_str", issue = "77998")]
pub fn as_str(&self) -> &'a str {
if self.inner.iter.iter.finished {
diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs
index 14ce94c178c5b..d29e1c46d78eb 100644
--- a/library/core/src/str/mod.rs
+++ b/library/core/src/str/mod.rs
@@ -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()
@@ -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
}
@@ -230,6 +232,7 @@ impl str {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "str_as_bytes", since = "1.39.0")]
+ #[must_use]
#[inline(always)]
#[allow(unused_attributes)]
pub const fn as_bytes(&self) -> &[u8] {
@@ -274,6 +277,7 @@ impl str {
/// assert_eq!("ðŸ”∈ðŸŒ", s);
/// ```
#[stable(feature = "str_mut_extras", since = "1.20.0")]
+ #[must_use]
#[inline(always)]
pub unsafe fn as_bytes_mut(&mut self) -> &mut [u8] {
// SAFETY: the cast from `&str` to `&[u8]` is safe since `str`
@@ -304,6 +308,7 @@ impl str {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "rustc_str_as_ptr", since = "1.32.0")]
+ #[must_use]
#[inline]
pub const fn as_ptr(&self) -> *const u8 {
self as *const str as *const u8
@@ -318,6 +323,7 @@ impl str {
/// It is your responsibility to make sure that the string slice only gets
/// modified in a way that it remains valid UTF-8.
#[stable(feature = "str_as_mut_ptr", since = "1.36.0")]
+ #[must_use]
#[inline]
pub fn as_mut_ptr(&mut self) -> *mut u8 {
self as *mut str as *mut u8
diff --git a/library/core/src/task/poll.rs b/library/core/src/task/poll.rs
index 3e0b3e89758a6..80e1458dc9421 100644
--- a/library/core/src/task/poll.rs
+++ b/library/core/src/task/poll.rs
@@ -97,7 +97,7 @@ impl Poll {
/// Extracts the successful type of a [`Poll`].
///
/// When combined with the `?` operator, this function will
- /// propogate any [`Poll::Pending`] values to the caller, and
+ /// propagate any [`Poll::Pending`] values to the caller, and
/// extract the `T` from [`Poll::Ready`].
///
/// # Examples
diff --git a/library/core/src/time.rs b/library/core/src/time.rs
index 40c5338d13cfd..5a74f39e8bc8b 100644
--- a/library/core/src/time.rs
+++ b/library/core/src/time.rs
@@ -334,6 +334,7 @@ impl Duration {
/// [`subsec_nanos`]: Duration::subsec_nanos
#[stable(feature = "duration", since = "1.3.0")]
#[rustc_const_stable(feature = "duration", since = "1.32.0")]
+ #[must_use]
#[inline]
pub const fn as_secs(&self) -> u64 {
self.secs
@@ -417,6 +418,7 @@ impl Duration {
/// ```
#[stable(feature = "duration_as_u128", since = "1.33.0")]
#[rustc_const_stable(feature = "duration_as_u128", since = "1.33.0")]
+ #[must_use]
#[inline]
pub const fn as_millis(&self) -> u128 {
self.secs as u128 * MILLIS_PER_SEC as u128 + (self.nanos / NANOS_PER_MILLI) as u128
@@ -434,6 +436,7 @@ impl Duration {
/// ```
#[stable(feature = "duration_as_u128", since = "1.33.0")]
#[rustc_const_stable(feature = "duration_as_u128", since = "1.33.0")]
+ #[must_use]
#[inline]
pub const fn as_micros(&self) -> u128 {
self.secs as u128 * MICROS_PER_SEC as u128 + (self.nanos / NANOS_PER_MICRO) as u128
@@ -451,6 +454,7 @@ impl Duration {
/// ```
#[stable(feature = "duration_as_u128", since = "1.33.0")]
#[rustc_const_stable(feature = "duration_as_u128", since = "1.33.0")]
+ #[must_use]
#[inline]
pub const fn as_nanos(&self) -> u128 {
self.secs as u128 * NANOS_PER_SEC as u128 + self.nanos as u128
@@ -674,6 +678,7 @@ impl Duration {
/// assert_eq!(dur.as_secs_f64(), 2.7);
/// ```
#[stable(feature = "duration_float", since = "1.38.0")]
+ #[must_use]
#[inline]
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
pub const fn as_secs_f64(&self) -> f64 {
@@ -692,6 +697,7 @@ impl Duration {
/// assert_eq!(dur.as_secs_f32(), 2.7);
/// ```
#[stable(feature = "duration_float", since = "1.38.0")]
+ #[must_use]
#[inline]
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
pub const fn as_secs_f32(&self) -> f32 {
diff --git a/library/std/src/ffi/c_str.rs b/library/std/src/ffi/c_str.rs
index 8b51c4450c2aa..78eb91e41936b 100644
--- a/library/std/src/ffi/c_str.rs
+++ b/library/std/src/ffi/c_str.rs
@@ -297,6 +297,7 @@ impl FromVecWithNulError {
///
/// assert_eq!(&bytes[..], value.unwrap_err().as_bytes());
/// ```
+ #[must_use]
pub fn as_bytes(&self) -> &[u8] {
&self.bytes[..]
}
@@ -618,6 +619,7 @@ impl CString {
/// assert_eq!(bytes, &[b'f', b'o', b'o']);
/// ```
#[inline]
+ #[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn as_bytes(&self) -> &[u8] {
// SAFETY: CString has a length at least 1
@@ -637,6 +639,7 @@ impl CString {
/// assert_eq!(bytes, &[b'f', b'o', b'o', b'\0']);
/// ```
#[inline]
+ #[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn as_bytes_with_nul(&self) -> &[u8] {
&self.inner
@@ -655,6 +658,7 @@ impl CString {
/// CStr::from_bytes_with_nul(b"foo\0").expect("CStr::from_bytes_with_nul failed"));
/// ```
#[inline]
+ #[must_use]
#[stable(feature = "as_c_str", since = "1.20.0")]
pub fn as_c_str(&self) -> &CStr {
&*self
@@ -1313,6 +1317,7 @@ impl CStr {
/// This way, the lifetime of the [`CString`] in `hello` encompasses
/// the lifetime of `ptr` and the `unsafe` block.
#[inline]
+ #[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_str_as_ptr", since = "1.32.0")]
pub const fn as_ptr(&self) -> *const c_char {
diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs
index de745f2164962..8860309b30606 100644
--- a/library/std/src/ffi/os_str.rs
+++ b/library/std/src/ffi/os_str.rs
@@ -137,6 +137,7 @@ impl OsString {
/// assert_eq!(os_string.as_os_str(), os_str);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
+ #[must_use]
#[inline]
pub fn as_os_str(&self) -> &OsStr {
self
@@ -662,6 +663,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()
@@ -693,6 +695,7 @@ 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()
diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs
index 85d350729239c..d35a07ce64984 100644
--- a/library/std/src/fs.rs
+++ b/library/std/src/fs.rs
@@ -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()
@@ -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()
@@ -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()
@@ -1078,6 +1081,7 @@ impl Metadata {
/// Ok(())
/// }
/// ```
+ #[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn len(&self) -> u64 {
self.0.size()
@@ -1306,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()
@@ -1338,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()
@@ -1373,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()
diff --git a/library/std/src/net/addr.rs b/library/std/src/net/addr.rs
index cd2007cc2cb42..a689d2a56b721 100644
--- a/library/std/src/net/addr.rs
+++ b/library/std/src/net/addr.rs
@@ -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 {
@@ -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 {
diff --git a/library/std/src/net/ip.rs b/library/std/src/net/ip.rs
index 99922eef61f10..68b8bb8f3e190 100644
--- a/library/std/src/net/ip.rs
+++ b/library/std/src/net/ip.rs
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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(_))
@@ -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(_))
@@ -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
@@ -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
@@ -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() {
@@ -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, ..])
@@ -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
@@ -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)
@@ -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
@@ -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()
@@ -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
@@ -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())
@@ -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() {
@@ -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())
@@ -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())
@@ -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() {
@@ -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
@@ -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()
@@ -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
@@ -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)
@@ -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)
@@ -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()
@@ -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
diff --git a/library/std/src/os/unix/net/addr.rs b/library/std/src/os/unix/net/addr.rs
index 62bfde8bfd436..c9ccc26f4e179 100644
--- a/library/std/src/os/unix/net/addr.rs
+++ b/library/std/src/os/unix/net/addr.rs
@@ -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 }
@@ -192,6 +193,7 @@ impl SocketAddr {
/// }
/// ```
#[stable(feature = "unix_socket", since = "1.10.0")]
+ #[must_use]
pub fn as_pathname(&self) -> Option<&Path> {
if let AddressKind::Pathname(path) = self.address() { Some(path) } else { None }
}
diff --git a/library/std/src/os/unix/net/ancillary.rs b/library/std/src/os/unix/net/ancillary.rs
index 57bb61903c147..353bf2f11665a 100644
--- a/library/std/src/os/unix/net/ancillary.rs
+++ b/library/std/src/os/unix/net/ancillary.rs
@@ -431,12 +431,14 @@ impl<'a> SocketAncillary<'a> {
}
/// Returns `true` if the ancillary data is empty.
+ #[must_use]
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
pub fn is_empty(&self) -> bool {
self.length == 0
}
/// Returns the number of used bytes.
+ #[must_use]
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
pub fn len(&self) -> usize {
self.length
diff --git a/library/std/src/path.rs b/library/std/src/path.rs
index a8a79fb9c8fbb..5306403547586 100644
--- a/library/std/src/path.rs
+++ b/library/std/src/path.rs
@@ -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::*;
@@ -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)
@@ -427,6 +429,7 @@ impl<'a> PrefixComponent<'a> {
/// Returns the raw [`OsStr`] slice for this prefix.
#[stable(feature = "rust1", since = "1.0.0")]
+ #[must_use]
#[inline]
pub fn as_os_str(&self) -> &'a OsStr {
self.raw
@@ -676,6 +679,7 @@ impl<'a> Components<'a> {
///
/// assert_eq!(Path::new("foo/bar.txt"), components.as_path());
/// ```
+ #[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn as_path(&self) -> &'a Path {
let mut comps = self.clone();
@@ -821,6 +825,7 @@ impl<'a> Iter<'a> {
/// assert_eq!(Path::new("foo/bar.txt"), iter.as_path());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
+ #[must_use]
#[inline]
pub fn as_path(&self) -> &'a Path {
self.inner.as_path()
@@ -1188,6 +1193,7 @@ impl PathBuf {
/// assert_eq!(Path::new("/test"), p.as_path());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
+ #[must_use]
#[inline]
pub fn as_path(&self) -> &Path {
self
@@ -1923,6 +1929,7 @@ impl Path {
/// assert_eq!(os_str, std::ffi::OsStr::new("foo.txt"));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
+ #[must_use]
#[inline]
pub fn as_os_str(&self) -> &OsStr {
&self.inner
@@ -2011,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") {
@@ -2035,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()
@@ -2061,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()
@@ -2511,6 +2521,8 @@ impl Path {
/// println!("{}", path.display());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
+ #[must_use = "this does not display the path, \
+ it returns an object that can be displayed"]
#[inline]
pub fn display(&self) -> Display<'_> {
Display { path: self }
@@ -2698,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)
}
@@ -2724,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)
}
@@ -2750,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)
}
diff --git a/library/std/src/sync/barrier.rs b/library/std/src/sync/barrier.rs
index 0e28a2d166f13..133c3e46cd8a6 100644
--- a/library/std/src/sync/barrier.rs
+++ b/library/std/src/sync/barrier.rs
@@ -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
}
diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs
index 7d404aff30e07..82847d83ad225 100644
--- a/library/std/src/thread/mod.rs
+++ b/library/std/src/thread/mod.rs
@@ -1031,6 +1031,7 @@ impl ThreadId {
/// value is entirely opaque -- only equality testing is stable. Note that
/// it is not guaranteed which values new threads will return, and this may
/// change across Rust versions.
+ #[must_use]
#[unstable(feature = "thread_id_value", issue = "67939")]
pub fn as_u64(&self) -> NonZeroU64 {
self.0
diff --git a/src/doc/edition-guide b/src/doc/edition-guide
index 2d9b1b9da706d..7c0088ca744d2 160000
--- a/src/doc/edition-guide
+++ b/src/doc/edition-guide
@@ -1 +1 @@
-Subproject commit 2d9b1b9da706de24650fdc5c3b0182f55c82115d
+Subproject commit 7c0088ca744d293a5f4b1e2ac378e7c23d30fe55
diff --git a/src/doc/embedded-book b/src/doc/embedded-book
index 4c76da9ddb465..270fccd339e59 160000
--- a/src/doc/embedded-book
+++ b/src/doc/embedded-book
@@ -1 +1 @@
-Subproject commit 4c76da9ddb4650203c129fceffdea95a3466c205
+Subproject commit 270fccd339e5972d9c900e788f197e81a0bcd956
diff --git a/src/doc/nomicon b/src/doc/nomicon
index 2747c4bb2cbc0..2d66852a27c5d 160000
--- a/src/doc/nomicon
+++ b/src/doc/nomicon
@@ -1 +1 @@
-Subproject commit 2747c4bb2cbc0639b733793ddb0bf4e9daa2634e
+Subproject commit 2d66852a27c5d0ec50ae021820d1de22caa2b1bd
diff --git a/src/doc/reference b/src/doc/reference
index 13747275bd14c..b5c68b02984f7 160000
--- a/src/doc/reference
+++ b/src/doc/reference
@@ -1 +1 @@
-Subproject commit 13747275bd14c2d2b453100498532f9ae5504769
+Subproject commit b5c68b02984f74e99d1f1b332029e05f607e2660
diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example
index 28aca4a36962c..9a60624fcad01 160000
--- a/src/doc/rust-by-example
+++ b/src/doc/rust-by-example
@@ -1 +1 @@
-Subproject commit 28aca4a36962c709bce301c03114b5589381dfb8
+Subproject commit 9a60624fcad0140826c44389571dc622917cd632
diff --git a/src/doc/rustc-dev-guide b/src/doc/rustc-dev-guide
index d1f03cbaa39d9..fba15a46ca8ef 160000
--- a/src/doc/rustc-dev-guide
+++ b/src/doc/rustc-dev-guide
@@ -1 +1 @@
-Subproject commit d1f03cbaa39d9164f5fe4b9b93762668142e0dad
+Subproject commit fba15a46ca8efa97e8a955794724ac7ce27805b8
diff --git a/src/test/ui/never_type/never-value-fallback-issue-66757.nofallback.stderr b/src/test/ui/never_type/never-value-fallback-issue-66757.nofallback.stderr
index f374266626bcc..614cdff1f8022 100644
--- a/src/test/ui/never_type/never-value-fallback-issue-66757.nofallback.stderr
+++ b/src/test/ui/never_type/never-value-fallback-issue-66757.nofallback.stderr
@@ -1,5 +1,5 @@
error[E0277]: the trait bound `E: From<()>` is not satisfied
- --> $DIR/never-value-fallback-issue-66757.rs:27:5
+ --> $DIR/never-value-fallback-issue-66757.rs:28:5
|
LL | >::from(never);
| ^^^^^^^^^^^^^^^^^^^^ the trait `From<()>` is not implemented for `E`
diff --git a/src/test/ui/never_type/never-value-fallback-issue-66757.rs b/src/test/ui/never_type/never-value-fallback-issue-66757.rs
index 6dc7e6ad2d93d..fc6fe6eb5cc02 100644
--- a/src/test/ui/never_type/never-value-fallback-issue-66757.rs
+++ b/src/test/ui/never_type/never-value-fallback-issue-66757.rs
@@ -22,6 +22,7 @@ impl From for E {
#[allow(unreachable_code)]
#[allow(dead_code)]
+#[allow(unused_must_use)]
fn foo(never: !) {
>::from(never); // Ok
>::from(never); //[nofallback]~ ERROR trait bound `E: From<()>` is not satisfied
diff --git a/src/tools/clippy/tests/ui/cast_lossless_float.fixed b/src/tools/clippy/tests/ui/cast_lossless_float.fixed
index 709d58b596c83..32a9c1c4ae1af 100644
--- a/src/tools/clippy/tests/ui/cast_lossless_float.fixed
+++ b/src/tools/clippy/tests/ui/cast_lossless_float.fixed
@@ -6,24 +6,24 @@
fn main() {
// Test clippy::cast_lossless with casts to floating-point types
let x0 = 1i8;
- f32::from(x0);
- f64::from(x0);
+ let _ = f32::from(x0);
+ let _ = f64::from(x0);
let x1 = 1u8;
- f32::from(x1);
- f64::from(x1);
+ let _ = f32::from(x1);
+ let _ = f64::from(x1);
let x2 = 1i16;
- f32::from(x2);
- f64::from(x2);
+ let _ = f32::from(x2);
+ let _ = f64::from(x2);
let x3 = 1u16;
- f32::from(x3);
- f64::from(x3);
+ let _ = f32::from(x3);
+ let _ = f64::from(x3);
let x4 = 1i32;
- f64::from(x4);
+ let _ = f64::from(x4);
let x5 = 1u32;
- f64::from(x5);
+ let _ = f64::from(x5);
// Test with casts from floating-point types
- f64::from(1.0f32);
+ let _ = f64::from(1.0f32);
}
// The lint would suggest using `f64::from(input)` here but the `XX::from` function is not const,
diff --git a/src/tools/clippy/tests/ui/cast_lossless_float.rs b/src/tools/clippy/tests/ui/cast_lossless_float.rs
index eb0aab8864290..6f5ddcfe09c8a 100644
--- a/src/tools/clippy/tests/ui/cast_lossless_float.rs
+++ b/src/tools/clippy/tests/ui/cast_lossless_float.rs
@@ -6,24 +6,24 @@
fn main() {
// Test clippy::cast_lossless with casts to floating-point types
let x0 = 1i8;
- x0 as f32;
- x0 as f64;
+ let _ = x0 as f32;
+ let _ = x0 as f64;
let x1 = 1u8;
- x1 as f32;
- x1 as f64;
+ let _ = x1 as f32;
+ let _ = x1 as f64;
let x2 = 1i16;
- x2 as f32;
- x2 as f64;
+ let _ = x2 as f32;
+ let _ = x2 as f64;
let x3 = 1u16;
- x3 as f32;
- x3 as f64;
+ let _ = x3 as f32;
+ let _ = x3 as f64;
let x4 = 1i32;
- x4 as f64;
+ let _ = x4 as f64;
let x5 = 1u32;
- x5 as f64;
+ let _ = x5 as f64;
// Test with casts from floating-point types
- 1.0f32 as f64;
+ let _ = 1.0f32 as f64;
}
// The lint would suggest using `f64::from(input)` here but the `XX::from` function is not const,
diff --git a/src/tools/clippy/tests/ui/cast_lossless_float.stderr b/src/tools/clippy/tests/ui/cast_lossless_float.stderr
index 0ed09f3083c28..8326d40be7165 100644
--- a/src/tools/clippy/tests/ui/cast_lossless_float.stderr
+++ b/src/tools/clippy/tests/ui/cast_lossless_float.stderr
@@ -1,70 +1,70 @@
error: casting `i8` to `f32` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_float.rs:9:5
+ --> $DIR/cast_lossless_float.rs:9:13
|
-LL | x0 as f32;
- | ^^^^^^^^^ help: try: `f32::from(x0)`
+LL | let _ = x0 as f32;
+ | ^^^^^^^^^ help: try: `f32::from(x0)`
|
= note: `-D clippy::cast-lossless` implied by `-D warnings`
error: casting `i8` to `f64` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_float.rs:10:5
+ --> $DIR/cast_lossless_float.rs:10:13
|
-LL | x0 as f64;
- | ^^^^^^^^^ help: try: `f64::from(x0)`
+LL | let _ = x0 as f64;
+ | ^^^^^^^^^ help: try: `f64::from(x0)`
error: casting `u8` to `f32` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_float.rs:12:5
+ --> $DIR/cast_lossless_float.rs:12:13
|
-LL | x1 as f32;
- | ^^^^^^^^^ help: try: `f32::from(x1)`
+LL | let _ = x1 as f32;
+ | ^^^^^^^^^ help: try: `f32::from(x1)`
error: casting `u8` to `f64` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_float.rs:13:5
+ --> $DIR/cast_lossless_float.rs:13:13
|
-LL | x1 as f64;
- | ^^^^^^^^^ help: try: `f64::from(x1)`
+LL | let _ = x1 as f64;
+ | ^^^^^^^^^ help: try: `f64::from(x1)`
error: casting `i16` to `f32` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_float.rs:15:5
+ --> $DIR/cast_lossless_float.rs:15:13
|
-LL | x2 as f32;
- | ^^^^^^^^^ help: try: `f32::from(x2)`
+LL | let _ = x2 as f32;
+ | ^^^^^^^^^ help: try: `f32::from(x2)`
error: casting `i16` to `f64` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_float.rs:16:5
+ --> $DIR/cast_lossless_float.rs:16:13
|
-LL | x2 as f64;
- | ^^^^^^^^^ help: try: `f64::from(x2)`
+LL | let _ = x2 as f64;
+ | ^^^^^^^^^ help: try: `f64::from(x2)`
error: casting `u16` to `f32` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_float.rs:18:5
+ --> $DIR/cast_lossless_float.rs:18:13
|
-LL | x3 as f32;
- | ^^^^^^^^^ help: try: `f32::from(x3)`
+LL | let _ = x3 as f32;
+ | ^^^^^^^^^ help: try: `f32::from(x3)`
error: casting `u16` to `f64` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_float.rs:19:5
+ --> $DIR/cast_lossless_float.rs:19:13
|
-LL | x3 as f64;
- | ^^^^^^^^^ help: try: `f64::from(x3)`
+LL | let _ = x3 as f64;
+ | ^^^^^^^^^ help: try: `f64::from(x3)`
error: casting `i32` to `f64` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_float.rs:21:5
+ --> $DIR/cast_lossless_float.rs:21:13
|
-LL | x4 as f64;
- | ^^^^^^^^^ help: try: `f64::from(x4)`
+LL | let _ = x4 as f64;
+ | ^^^^^^^^^ help: try: `f64::from(x4)`
error: casting `u32` to `f64` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_float.rs:23:5
+ --> $DIR/cast_lossless_float.rs:23:13
|
-LL | x5 as f64;
- | ^^^^^^^^^ help: try: `f64::from(x5)`
+LL | let _ = x5 as f64;
+ | ^^^^^^^^^ help: try: `f64::from(x5)`
error: casting `f32` to `f64` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_float.rs:26:5
+ --> $DIR/cast_lossless_float.rs:26:13
|
-LL | 1.0f32 as f64;
- | ^^^^^^^^^^^^^ help: try: `f64::from(1.0f32)`
+LL | let _ = 1.0f32 as f64;
+ | ^^^^^^^^^^^^^ help: try: `f64::from(1.0f32)`
error: aborting due to 11 previous errors
diff --git a/src/tools/clippy/tests/ui/cast_lossless_integer.fixed b/src/tools/clippy/tests/ui/cast_lossless_integer.fixed
index 03e49adb117db..72a708b40737b 100644
--- a/src/tools/clippy/tests/ui/cast_lossless_integer.fixed
+++ b/src/tools/clippy/tests/ui/cast_lossless_integer.fixed
@@ -5,27 +5,27 @@
fn main() {
// Test clippy::cast_lossless with casts to integer types
- i16::from(1i8);
- i32::from(1i8);
- i64::from(1i8);
- i16::from(1u8);
- i32::from(1u8);
- i64::from(1u8);
- u16::from(1u8);
- u32::from(1u8);
- u64::from(1u8);
- i32::from(1i16);
- i64::from(1i16);
- i32::from(1u16);
- i64::from(1u16);
- u32::from(1u16);
- u64::from(1u16);
- i64::from(1i32);
- i64::from(1u32);
- u64::from(1u32);
+ let _ = i16::from(1i8);
+ let _ = i32::from(1i8);
+ let _ = i64::from(1i8);
+ let _ = i16::from(1u8);
+ let _ = i32::from(1u8);
+ let _ = i64::from(1u8);
+ let _ = u16::from(1u8);
+ let _ = u32::from(1u8);
+ let _ = u64::from(1u8);
+ let _ = i32::from(1i16);
+ let _ = i64::from(1i16);
+ let _ = i32::from(1u16);
+ let _ = i64::from(1u16);
+ let _ = u32::from(1u16);
+ let _ = u64::from(1u16);
+ let _ = i64::from(1i32);
+ let _ = i64::from(1u32);
+ let _ = u64::from(1u32);
// Test with an expression wrapped in parens
- u16::from(1u8 + 1u8);
+ let _ = u16::from(1u8 + 1u8);
}
// The lint would suggest using `f64::from(input)` here but the `XX::from` function is not const,
diff --git a/src/tools/clippy/tests/ui/cast_lossless_integer.rs b/src/tools/clippy/tests/ui/cast_lossless_integer.rs
index 6a984d245963f..34bb47181e69d 100644
--- a/src/tools/clippy/tests/ui/cast_lossless_integer.rs
+++ b/src/tools/clippy/tests/ui/cast_lossless_integer.rs
@@ -5,27 +5,27 @@
fn main() {
// Test clippy::cast_lossless with casts to integer types
- 1i8 as i16;
- 1i8 as i32;
- 1i8 as i64;
- 1u8 as i16;
- 1u8 as i32;
- 1u8 as i64;
- 1u8 as u16;
- 1u8 as u32;
- 1u8 as u64;
- 1i16 as i32;
- 1i16 as i64;
- 1u16 as i32;
- 1u16 as i64;
- 1u16 as u32;
- 1u16 as u64;
- 1i32 as i64;
- 1u32 as i64;
- 1u32 as u64;
+ let _ = 1i8 as i16;
+ let _ = 1i8 as i32;
+ let _ = 1i8 as i64;
+ let _ = 1u8 as i16;
+ let _ = 1u8 as i32;
+ let _ = 1u8 as i64;
+ let _ = 1u8 as u16;
+ let _ = 1u8 as u32;
+ let _ = 1u8 as u64;
+ let _ = 1i16 as i32;
+ let _ = 1i16 as i64;
+ let _ = 1u16 as i32;
+ let _ = 1u16 as i64;
+ let _ = 1u16 as u32;
+ let _ = 1u16 as u64;
+ let _ = 1i32 as i64;
+ let _ = 1u32 as i64;
+ let _ = 1u32 as u64;
// Test with an expression wrapped in parens
- (1u8 + 1u8) as u16;
+ let _ = (1u8 + 1u8) as u16;
}
// The lint would suggest using `f64::from(input)` here but the `XX::from` function is not const,
diff --git a/src/tools/clippy/tests/ui/cast_lossless_integer.stderr b/src/tools/clippy/tests/ui/cast_lossless_integer.stderr
index 8e2890f9c28d0..721b94876cb2c 100644
--- a/src/tools/clippy/tests/ui/cast_lossless_integer.stderr
+++ b/src/tools/clippy/tests/ui/cast_lossless_integer.stderr
@@ -1,118 +1,118 @@
error: casting `i8` to `i16` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_integer.rs:8:5
+ --> $DIR/cast_lossless_integer.rs:8:13
|
-LL | 1i8 as i16;
- | ^^^^^^^^^^ help: try: `i16::from(1i8)`
+LL | let _ = 1i8 as i16;
+ | ^^^^^^^^^^ help: try: `i16::from(1i8)`
|
= note: `-D clippy::cast-lossless` implied by `-D warnings`
error: casting `i8` to `i32` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_integer.rs:9:5
+ --> $DIR/cast_lossless_integer.rs:9:13
|
-LL | 1i8 as i32;
- | ^^^^^^^^^^ help: try: `i32::from(1i8)`
+LL | let _ = 1i8 as i32;
+ | ^^^^^^^^^^ help: try: `i32::from(1i8)`
error: casting `i8` to `i64` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_integer.rs:10:5
+ --> $DIR/cast_lossless_integer.rs:10:13
|
-LL | 1i8 as i64;
- | ^^^^^^^^^^ help: try: `i64::from(1i8)`
+LL | let _ = 1i8 as i64;
+ | ^^^^^^^^^^ help: try: `i64::from(1i8)`
error: casting `u8` to `i16` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_integer.rs:11:5
+ --> $DIR/cast_lossless_integer.rs:11:13
|
-LL | 1u8 as i16;
- | ^^^^^^^^^^ help: try: `i16::from(1u8)`
+LL | let _ = 1u8 as i16;
+ | ^^^^^^^^^^ help: try: `i16::from(1u8)`
error: casting `u8` to `i32` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_integer.rs:12:5
+ --> $DIR/cast_lossless_integer.rs:12:13
|
-LL | 1u8 as i32;
- | ^^^^^^^^^^ help: try: `i32::from(1u8)`
+LL | let _ = 1u8 as i32;
+ | ^^^^^^^^^^ help: try: `i32::from(1u8)`
error: casting `u8` to `i64` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_integer.rs:13:5
+ --> $DIR/cast_lossless_integer.rs:13:13
|
-LL | 1u8 as i64;
- | ^^^^^^^^^^ help: try: `i64::from(1u8)`
+LL | let _ = 1u8 as i64;
+ | ^^^^^^^^^^ help: try: `i64::from(1u8)`
error: casting `u8` to `u16` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_integer.rs:14:5
+ --> $DIR/cast_lossless_integer.rs:14:13
|
-LL | 1u8 as u16;
- | ^^^^^^^^^^ help: try: `u16::from(1u8)`
+LL | let _ = 1u8 as u16;
+ | ^^^^^^^^^^ help: try: `u16::from(1u8)`
error: casting `u8` to `u32` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_integer.rs:15:5
+ --> $DIR/cast_lossless_integer.rs:15:13
|
-LL | 1u8 as u32;
- | ^^^^^^^^^^ help: try: `u32::from(1u8)`
+LL | let _ = 1u8 as u32;
+ | ^^^^^^^^^^ help: try: `u32::from(1u8)`
error: casting `u8` to `u64` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_integer.rs:16:5
+ --> $DIR/cast_lossless_integer.rs:16:13
|
-LL | 1u8 as u64;
- | ^^^^^^^^^^ help: try: `u64::from(1u8)`
+LL | let _ = 1u8 as u64;
+ | ^^^^^^^^^^ help: try: `u64::from(1u8)`
error: casting `i16` to `i32` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_integer.rs:17:5
+ --> $DIR/cast_lossless_integer.rs:17:13
|
-LL | 1i16 as i32;
- | ^^^^^^^^^^^ help: try: `i32::from(1i16)`
+LL | let _ = 1i16 as i32;
+ | ^^^^^^^^^^^ help: try: `i32::from(1i16)`
error: casting `i16` to `i64` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_integer.rs:18:5
+ --> $DIR/cast_lossless_integer.rs:18:13
|
-LL | 1i16 as i64;
- | ^^^^^^^^^^^ help: try: `i64::from(1i16)`
+LL | let _ = 1i16 as i64;
+ | ^^^^^^^^^^^ help: try: `i64::from(1i16)`
error: casting `u16` to `i32` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_integer.rs:19:5
+ --> $DIR/cast_lossless_integer.rs:19:13
|
-LL | 1u16 as i32;
- | ^^^^^^^^^^^ help: try: `i32::from(1u16)`
+LL | let _ = 1u16 as i32;
+ | ^^^^^^^^^^^ help: try: `i32::from(1u16)`
error: casting `u16` to `i64` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_integer.rs:20:5
+ --> $DIR/cast_lossless_integer.rs:20:13
|
-LL | 1u16 as i64;
- | ^^^^^^^^^^^ help: try: `i64::from(1u16)`
+LL | let _ = 1u16 as i64;
+ | ^^^^^^^^^^^ help: try: `i64::from(1u16)`
error: casting `u16` to `u32` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_integer.rs:21:5
+ --> $DIR/cast_lossless_integer.rs:21:13
|
-LL | 1u16 as u32;
- | ^^^^^^^^^^^ help: try: `u32::from(1u16)`
+LL | let _ = 1u16 as u32;
+ | ^^^^^^^^^^^ help: try: `u32::from(1u16)`
error: casting `u16` to `u64` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_integer.rs:22:5
+ --> $DIR/cast_lossless_integer.rs:22:13
|
-LL | 1u16 as u64;
- | ^^^^^^^^^^^ help: try: `u64::from(1u16)`
+LL | let _ = 1u16 as u64;
+ | ^^^^^^^^^^^ help: try: `u64::from(1u16)`
error: casting `i32` to `i64` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_integer.rs:23:5
+ --> $DIR/cast_lossless_integer.rs:23:13
|
-LL | 1i32 as i64;
- | ^^^^^^^^^^^ help: try: `i64::from(1i32)`
+LL | let _ = 1i32 as i64;
+ | ^^^^^^^^^^^ help: try: `i64::from(1i32)`
error: casting `u32` to `i64` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_integer.rs:24:5
+ --> $DIR/cast_lossless_integer.rs:24:13
|
-LL | 1u32 as i64;
- | ^^^^^^^^^^^ help: try: `i64::from(1u32)`
+LL | let _ = 1u32 as i64;
+ | ^^^^^^^^^^^ help: try: `i64::from(1u32)`
error: casting `u32` to `u64` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_integer.rs:25:5
+ --> $DIR/cast_lossless_integer.rs:25:13
|
-LL | 1u32 as u64;
- | ^^^^^^^^^^^ help: try: `u64::from(1u32)`
+LL | let _ = 1u32 as u64;
+ | ^^^^^^^^^^^ help: try: `u64::from(1u32)`
error: casting `u8` to `u16` may become silently lossy if you later change the type
- --> $DIR/cast_lossless_integer.rs:28:5
+ --> $DIR/cast_lossless_integer.rs:28:13
|
-LL | (1u8 + 1u8) as u16;
- | ^^^^^^^^^^^^^^^^^^ help: try: `u16::from(1u8 + 1u8)`
+LL | let _ = (1u8 + 1u8) as u16;
+ | ^^^^^^^^^^^^^^^^^^ help: try: `u16::from(1u8 + 1u8)`
error: aborting due to 19 previous errors