From ecc4ca54a4c7b1c436c466357877336c1df781cd Mon Sep 17 00:00:00 2001 From: Felix Chapman Date: Mon, 10 Dec 2018 14:45:26 +0000 Subject: [PATCH] Add #[must_use] attribute to stdlib traits --- src/libcore/future/future.rs | 1 + src/libcore/iter/iterator.rs | 1 + src/libcore/ops/function.rs | 3 +++ 3 files changed, 5 insertions(+) diff --git a/src/libcore/future/future.rs b/src/libcore/future/future.rs index 0c870f9e404a2..5dee1d6dd3a39 100644 --- a/src/libcore/future/future.rs +++ b/src/libcore/future/future.rs @@ -33,6 +33,7 @@ use task::{Poll, LocalWaker}; /// /// When using a future, you generally won't call `poll` directly, but instead /// `await!` the value. +#[must_use] pub trait Future { /// The result of the `Future`. type Output; diff --git a/src/libcore/iter/iterator.rs b/src/libcore/iter/iterator.rs index 92a4aed4e27e5..c0b83a6868b38 100644 --- a/src/libcore/iter/iterator.rs +++ b/src/libcore/iter/iterator.rs @@ -98,6 +98,7 @@ fn _assert_is_object_safe(_: &dyn Iterator) {} message="`{Self}` is not an iterator" )] #[doc(spotlight)] +#[must_use] pub trait Iterator { /// The type of the elements being iterated over. #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/ops/function.rs b/src/libcore/ops/function.rs index d1be724c3264e..3b356b9a1e7b4 100644 --- a/src/libcore/ops/function.rs +++ b/src/libcore/ops/function.rs @@ -72,6 +72,7 @@ label="expected an `Fn<{Args}>` closure, found `{Self}`", )] #[fundamental] // so that regex can rely that `&str: !FnMut` +#[must_use] pub trait Fn : FnMut { /// Performs the call operation. #[unstable(feature = "fn_traits", issue = "29625")] @@ -150,6 +151,7 @@ pub trait Fn : FnMut { label="expected an `FnMut<{Args}>` closure, found `{Self}`", )] #[fundamental] // so that regex can rely that `&str: !FnMut` +#[must_use] pub trait FnMut : FnOnce { /// Performs the call operation. #[unstable(feature = "fn_traits", issue = "29625")] @@ -228,6 +230,7 @@ pub trait FnMut : FnOnce { label="expected an `FnOnce<{Args}>` closure, found `{Self}`", )] #[fundamental] // so that regex can rely that `&str: !FnMut` +#[must_use] pub trait FnOnce { /// The returned type after the call operator is used. #[stable(feature = "fn_once_output", since = "1.12.0")]