Skip to content

Commit 58899c4

Browse files
committed
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
2 parents 38b01d9 + ff6d8ec commit 58899c4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+129
-19
lines changed

library/alloc/src/alloc.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ pub use std::alloc::Global;
8181
/// }
8282
/// ```
8383
#[stable(feature = "global_alloc", since = "1.28.0")]
84+
#[must_use = "losing the pointer will leak memory"]
8485
#[inline]
8586
pub unsafe fn alloc(layout: Layout) -> *mut u8 {
8687
unsafe { __rust_alloc(layout.size(), layout.align()) }
@@ -117,6 +118,7 @@ pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {
117118
///
118119
/// See [`GlobalAlloc::realloc`].
119120
#[stable(feature = "global_alloc", since = "1.28.0")]
121+
#[must_use = "losing the pointer will leak memory"]
120122
#[inline]
121123
pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
122124
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
150152
/// }
151153
/// ```
152154
#[stable(feature = "global_alloc", since = "1.28.0")]
155+
#[must_use = "losing the pointer will leak memory"]
153156
#[inline]
154157
pub unsafe fn alloc_zeroed(layout: Layout) -> *mut u8 {
155158
unsafe { __rust_alloc_zeroed(layout.size(), layout.align()) }

library/alloc/src/collections/btree/set.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ pub struct Range<'a, T: 'a> {
137137
/// See its documentation for more.
138138
///
139139
/// [`difference`]: BTreeSet::difference
140+
#[must_use = "this returns the difference as an iterator, \
141+
without modifying either input set"]
140142
#[stable(feature = "rust1", since = "1.0.0")]
141143
pub struct Difference<'a, T: 'a> {
142144
inner: DifferenceInner<'a, T>,
@@ -169,6 +171,8 @@ impl<T: fmt::Debug> fmt::Debug for Difference<'_, T> {
169171
/// [`BTreeSet`]. See its documentation for more.
170172
///
171173
/// [`symmetric_difference`]: BTreeSet::symmetric_difference
174+
#[must_use = "this returns the difference as an iterator, \
175+
without modifying either input set"]
172176
#[stable(feature = "rust1", since = "1.0.0")]
173177
pub struct SymmetricDifference<'a, T: 'a>(MergeIterInner<Iter<'a, T>>);
174178

@@ -185,6 +189,8 @@ impl<T: fmt::Debug> fmt::Debug for SymmetricDifference<'_, T> {
185189
/// See its documentation for more.
186190
///
187191
/// [`intersection`]: BTreeSet::intersection
192+
#[must_use = "this returns the intersection as an iterator, \
193+
without modifying either input set"]
188194
#[stable(feature = "rust1", since = "1.0.0")]
189195
pub struct Intersection<'a, T: 'a> {
190196
inner: IntersectionInner<'a, T>,
@@ -217,6 +223,8 @@ impl<T: fmt::Debug> fmt::Debug for Intersection<'_, T> {
217223
/// See its documentation for more.
218224
///
219225
/// [`union`]: BTreeSet::union
226+
#[must_use = "this returns the union as an iterator, \
227+
without modifying either input set"]
220228
#[stable(feature = "rust1", since = "1.0.0")]
221229
pub struct Union<'a, T: 'a>(MergeIterInner<Iter<'a, T>>);
222230

library/alloc/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@
112112
#![feature(maybe_uninit_slice)]
113113
#![cfg_attr(test, feature(new_uninit))]
114114
#![feature(nonnull_slice_from_raw_parts)]
115-
#![feature(option_result_unwrap_unchecked)]
116115
#![feature(pattern)]
117116
#![feature(ptr_internals)]
118117
#![feature(receiver_trait)]

library/alloc/src/rc.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
//! use std::rc::Rc;
4242
//!
4343
//! let my_rc = Rc::new(());
44-
//! Rc::downgrade(&my_rc);
44+
//! let my_weak = Rc::downgrade(&my_rc);
4545
//! ```
4646
//!
4747
//! `Rc<T>`'s implementations of traits like `Clone` may also be called using
@@ -889,6 +889,8 @@ impl<T: ?Sized> Rc<T> {
889889
///
890890
/// let weak_five = Rc::downgrade(&five);
891891
/// ```
892+
#[must_use = "this returns a new `Weak` pointer, \
893+
without modifying the original `Rc`"]
892894
#[stable(feature = "rc_weak", since = "1.4.0")]
893895
pub fn downgrade(this: &Self) -> Weak<T> {
894896
this.inner().inc_weak();

library/alloc/src/string.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ impl String {
552552
///
553553
/// assert_eq!("Hello �World", output);
554554
/// ```
555+
#[must_use]
555556
#[cfg(not(no_global_oom_handling))]
556557
#[stable(feature = "rust1", since = "1.0.0")]
557558
pub fn from_utf8_lossy(v: &[u8]) -> Cow<'_, str> {
@@ -646,6 +647,7 @@ impl String {
646647
/// String::from_utf16_lossy(v));
647648
/// ```
648649
#[cfg(not(no_global_oom_handling))]
650+
#[must_use]
649651
#[inline]
650652
#[stable(feature = "rust1", since = "1.0.0")]
651653
pub fn from_utf16_lossy(v: &[u16]) -> String {

library/alloc/src/sync.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,7 @@ impl<T: ?Sized> Arc<T> {
804804
/// let x_ptr = Arc::into_raw(x);
805805
/// assert_eq!(unsafe { &*x_ptr }, "hello");
806806
/// ```
807+
#[must_use = "losing the pointer will leak memory"]
807808
#[stable(feature = "rc_raw", since = "1.17.0")]
808809
pub fn into_raw(this: Self) -> *const T {
809810
let ptr = Self::as_ptr(&this);

library/alloc/tests/str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ fn test_split_at_mut() {
10311031
#[should_panic]
10321032
fn test_split_at_boundscheck() {
10331033
let s = "ศไทย中华Việt Nam";
1034-
s.split_at(1);
1034+
let _ = s.split_at(1);
10351035
}
10361036

10371037
#[test]

library/core/src/alloc/layout.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ impl Layout {
104104
/// The minimum size in bytes for a memory block of this layout.
105105
#[stable(feature = "alloc_layout", since = "1.28.0")]
106106
#[rustc_const_stable(feature = "const_alloc_layout", since = "1.50.0")]
107+
#[must_use]
107108
#[inline]
108109
pub const fn size(&self) -> usize {
109110
self.size_
@@ -137,6 +138,7 @@ impl Layout {
137138
/// allocate backing structure for `T` (which could be a trait
138139
/// or other unsized type like a slice).
139140
#[stable(feature = "alloc_layout", since = "1.28.0")]
141+
#[must_use]
140142
#[inline]
141143
pub fn for_value<T: ?Sized>(t: &T) -> Self {
142144
let (size, align) = (mem::size_of_val(t), mem::align_of_val(t));
@@ -171,6 +173,7 @@ impl Layout {
171173
/// [trait object]: ../../book/ch17-02-trait-objects.html
172174
/// [extern type]: ../../unstable-book/language-features/extern-types.html
173175
#[unstable(feature = "layout_for_ptr", issue = "69835")]
176+
#[must_use]
174177
pub unsafe fn for_value_raw<T: ?Sized>(t: *const T) -> Self {
175178
// SAFETY: we pass along the prerequisites of these functions to the caller
176179
let (size, align) = unsafe { (mem::size_of_val_raw(t), mem::align_of_val_raw(t)) };
@@ -187,6 +190,7 @@ impl Layout {
187190
/// some other means.
188191
#[unstable(feature = "alloc_layout_extra", issue = "55724")]
189192
#[rustc_const_unstable(feature = "alloc_layout_extra", issue = "55724")]
193+
#[must_use]
190194
#[inline]
191195
pub const fn dangling(&self) -> NonNull<u8> {
192196
// SAFETY: align is guaranteed to be non-zero

library/core/src/any.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ impl TypeId {
458458
/// assert_eq!(is_string(&0), false);
459459
/// assert_eq!(is_string(&"cookie monster".to_string()), true);
460460
/// ```
461+
#[must_use]
461462
#[stable(feature = "rust1", since = "1.0.0")]
462463
#[rustc_const_unstable(feature = "const_type_id", issue = "77125")]
463464
pub const fn of<T: ?Sized + 'static>() -> TypeId {
@@ -492,6 +493,7 @@ impl TypeId {
492493
/// "core::option::Option<alloc::string::String>",
493494
/// );
494495
/// ```
496+
#[must_use]
495497
#[stable(feature = "type_name", since = "1.38.0")]
496498
#[rustc_const_unstable(feature = "const_type_name", issue = "63084")]
497499
pub const fn type_name<T: ?Sized>() -> &'static str {
@@ -534,6 +536,7 @@ pub const fn type_name<T: ?Sized>() -> &'static str {
534536
/// let y = 1.0;
535537
/// println!("{}", type_name_of_val(&y));
536538
/// ```
539+
#[must_use]
537540
#[unstable(feature = "type_name_of_val", issue = "66359")]
538541
#[rustc_const_unstable(feature = "const_type_name", issue = "63084")]
539542
pub const fn type_name_of_val<T: ?Sized>(_val: &T) -> &'static str {

library/core/src/ascii.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::str::from_utf8_unchecked;
1818
///
1919
/// This `struct` is created by the [`escape_default`] function. See its
2020
/// documentation for more.
21+
#[must_use = "iterators are lazy and do nothing unless consumed"]
2122
#[stable(feature = "rust1", since = "1.0.0")]
2223
#[derive(Clone)]
2324
pub struct EscapeDefault {

0 commit comments

Comments
 (0)