Rollup merge of #50511 - Manishearth:must-use, r=QuietMisdreavus
Add some explanations for #[must_use] `#[must_use]` can be given a string argument which is shown whilst warning for things. We should add a string argument to most of the user-exposed ones. I added these for everything but the operators, mostly because I'm not sure what to write there or if we need anything there.
This commit is contained in:
commit
4924fea202
src
@ -207,7 +207,8 @@ impl str {
|
||||
/// let s = "this is old";
|
||||
/// assert_eq!(s, s.replace("cookie monster", "little lamb"));
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[must_use = "this returns the replaced string as a new allocation, \
|
||||
without modifying the original"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn replace<'a, P: Pattern<'a>>(&'a self, from: P, to: &str) -> String {
|
||||
@ -247,7 +248,8 @@ impl str {
|
||||
/// let s = "this is old";
|
||||
/// assert_eq!(s, s.replacen("cookie monster", "little lamb", 10));
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[must_use = "this returns the replaced string as a new allocation, \
|
||||
without modifying the original"]
|
||||
#[stable(feature = "str_replacen", since = "1.16.0")]
|
||||
pub fn replacen<'a, P: Pattern<'a>>(&'a self, pat: P, to: &str, count: usize) -> String {
|
||||
// Hope to reduce the times of re-allocation
|
||||
|
@ -84,7 +84,7 @@ impl<'a> fmt::Write for PadAdapter<'a> {
|
||||
/// // prints "Foo { bar: 10, baz: "Hello World" }"
|
||||
/// println!("{:?}", Foo { bar: 10, baz: "Hello World".to_string() });
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[must_use = "must eventually call `finish()` on Debug builders"]
|
||||
#[allow(missing_debug_implementations)]
|
||||
#[stable(feature = "debug_builders", since = "1.2.0")]
|
||||
pub struct DebugStruct<'a, 'b: 'a> {
|
||||
@ -181,7 +181,7 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {
|
||||
/// // prints "Foo(10, "Hello World")"
|
||||
/// println!("{:?}", Foo(10, "Hello World".to_string()));
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[must_use = "must eventually call `finish()` on Debug builders"]
|
||||
#[allow(missing_debug_implementations)]
|
||||
#[stable(feature = "debug_builders", since = "1.2.0")]
|
||||
pub struct DebugTuple<'a, 'b: 'a> {
|
||||
@ -319,7 +319,7 @@ impl<'a, 'b: 'a> DebugInner<'a, 'b> {
|
||||
/// // prints "{10, 11}"
|
||||
/// println!("{:?}", Foo(vec![10, 11]));
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[must_use = "must eventually call `finish()` on Debug builders"]
|
||||
#[allow(missing_debug_implementations)]
|
||||
#[stable(feature = "debug_builders", since = "1.2.0")]
|
||||
pub struct DebugSet<'a, 'b: 'a> {
|
||||
@ -390,7 +390,7 @@ impl<'a, 'b: 'a> DebugSet<'a, 'b> {
|
||||
/// // prints "[10, 11]"
|
||||
/// println!("{:?}", Foo(vec![10, 11]));
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[must_use = "must eventually call `finish()` on Debug builders"]
|
||||
#[allow(missing_debug_implementations)]
|
||||
#[stable(feature = "debug_builders", since = "1.2.0")]
|
||||
pub struct DebugList<'a, 'b: 'a> {
|
||||
@ -461,7 +461,7 @@ impl<'a, 'b: 'a> DebugList<'a, 'b> {
|
||||
/// // prints "{"A": 10, "B": 11}"
|
||||
/// println!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)]));
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[must_use = "must eventually call `finish()` on Debug builders"]
|
||||
#[allow(missing_debug_implementations)]
|
||||
#[stable(feature = "debug_builders", since = "1.2.0")]
|
||||
pub struct DebugMap<'a, 'b: 'a> {
|
||||
|
@ -251,7 +251,7 @@ use ops;
|
||||
/// [`Ok`]: enum.Result.html#variant.Ok
|
||||
/// [`Err`]: enum.Result.html#variant.Err
|
||||
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
|
||||
#[must_use]
|
||||
#[must_use = "this `Result` may be an `Err` variant, which should be handled"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub enum Result<T, E> {
|
||||
/// Contains the success value
|
||||
|
@ -150,7 +150,7 @@ unsafe impl<T: ?Sized + Send> Sync for Mutex<T> { }
|
||||
/// [`lock`]: struct.Mutex.html#method.lock
|
||||
/// [`try_lock`]: struct.Mutex.html#method.try_lock
|
||||
/// [`Mutex`]: struct.Mutex.html
|
||||
#[must_use]
|
||||
#[must_use = "if unused the Mutex will immediately unlock"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct MutexGuard<'a, T: ?Sized + 'a> {
|
||||
// funny underscores due to how Deref/DerefMut currently work (they
|
||||
|
@ -94,7 +94,7 @@ unsafe impl<T: ?Sized + Send + Sync> Sync for RwLock<T> {}
|
||||
/// [`read`]: struct.RwLock.html#method.read
|
||||
/// [`try_read`]: struct.RwLock.html#method.try_read
|
||||
/// [`RwLock`]: struct.RwLock.html
|
||||
#[must_use]
|
||||
#[must_use = "if unused the RwLock will immediately unlock"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct RwLockReadGuard<'a, T: ?Sized + 'a> {
|
||||
__lock: &'a RwLock<T>,
|
||||
@ -115,7 +115,7 @@ unsafe impl<'a, T: ?Sized + Sync> Sync for RwLockReadGuard<'a, T> {}
|
||||
/// [`write`]: struct.RwLock.html#method.write
|
||||
/// [`try_write`]: struct.RwLock.html#method.try_write
|
||||
/// [`RwLock`]: struct.RwLock.html
|
||||
#[must_use]
|
||||
#[must_use = "if unused the RwLock will immediately unlock"]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub struct RwLockWriteGuard<'a, T: ?Sized + 'a> {
|
||||
__lock: &'a RwLock<T>,
|
||||
|
@ -41,7 +41,7 @@ unsafe impl<T: Send> Sync for ReentrantMutex<T> {}
|
||||
/// because implementation of the trait would violate Rust’s reference aliasing
|
||||
/// rules. Use interior mutability (usually `RefCell`) in order to mutate the
|
||||
/// guarded data.
|
||||
#[must_use]
|
||||
#[must_use = "if unused the ReentrantMutex will immediately unlock"]
|
||||
pub struct ReentrantMutexGuard<'a, T: 'a> {
|
||||
// funny underscores due to how Deref currently works (it disregards field
|
||||
// privacy).
|
||||
|
Loading…
x
Reference in New Issue
Block a user