forked from mirrors/gecko-dev
Bug 1729598 - Replace MOZ_MUST_USE_TYPE with [[nodiscard]]. r=static-analysis-reviewers,andi
Differential Revision: https://phabricator.services.mozilla.com/D125504
This commit is contained in:
parent
196daa1700
commit
c9530ebe28
10 changed files with 20 additions and 23 deletions
|
|
@ -25,7 +25,7 @@ namespace mozilla {
|
||||||
// Allow QMResult errors to use existing stack id and to increase the frame id
|
// Allow QMResult errors to use existing stack id and to increase the frame id
|
||||||
// during error propagation.
|
// during error propagation.
|
||||||
template <>
|
template <>
|
||||||
class MOZ_MUST_USE_TYPE GenericErrorResult<QMResult> {
|
class [[nodiscard]] GenericErrorResult<QMResult> {
|
||||||
QMResult mErrorValue;
|
QMResult mErrorValue;
|
||||||
|
|
||||||
template <typename V, typename E2>
|
template <typename V, typename E2>
|
||||||
|
|
|
||||||
|
|
@ -1161,7 +1161,7 @@ auto CollectWhile(const Cond& aCond, const Body& aBody)
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
class MOZ_MUST_USE_TYPE GenericErrorResult<mozilla::ipc::IPCResult> {
|
class [[nodiscard]] GenericErrorResult<mozilla::ipc::IPCResult> {
|
||||||
mozilla::ipc::IPCResult mErrorValue;
|
mozilla::ipc::IPCResult mErrorValue;
|
||||||
|
|
||||||
template <typename V, typename E2>
|
template <typename V, typename E2>
|
||||||
|
|
|
||||||
|
|
@ -55,17 +55,10 @@ namespace image {
|
||||||
* NOT_SUPPORTED: The requested operation is not supported, but the image is
|
* NOT_SUPPORTED: The requested operation is not supported, but the image is
|
||||||
* otherwise valid.
|
* otherwise valid.
|
||||||
*/
|
*/
|
||||||
enum class MOZ_MUST_USE_TYPE ImgDrawResult : uint8_t {
|
enum class [[nodiscard]] ImgDrawResult : uint8_t{
|
||||||
SUCCESS,
|
SUCCESS, SUCCESS_NOT_COMPLETE, INCOMPLETE, WRONG_SIZE,
|
||||||
SUCCESS_NOT_COMPLETE,
|
NOT_READY, TEMPORARY_ERROR, BAD_IMAGE, BAD_ARGS,
|
||||||
INCOMPLETE,
|
NOT_SUPPORTED};
|
||||||
WRONG_SIZE,
|
|
||||||
NOT_READY,
|
|
||||||
TEMPORARY_ERROR,
|
|
||||||
BAD_IMAGE,
|
|
||||||
BAD_ARGS,
|
|
||||||
NOT_SUPPORTED
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* You can combine ImgDrawResults with &. By analogy to bitwise-&, the result is
|
* You can combine ImgDrawResults with &. By analogy to bitwise-&, the result is
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@
|
||||||
//
|
//
|
||||||
// TODO(heycam): We should perhaps have a similar struct for Owned types with a
|
// TODO(heycam): We should perhaps have a similar struct for Owned types with a
|
||||||
// Consume() method to convert them into a UniquePtr. The struct for Strong
|
// Consume() method to convert them into a UniquePtr. The struct for Strong
|
||||||
// types at least have MOZ_MUST_USE_TYPE on them.
|
// types at least have [[nodiscard]] on them.
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Using these types in Rust =========================
|
// Using these types in Rust =========================
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,11 @@ struct unused_t;
|
||||||
* Otherwise, use std::move(RefPtr/nsCOMPtr/etc).
|
* Otherwise, use std::move(RefPtr/nsCOMPtr/etc).
|
||||||
*/
|
*/
|
||||||
template <class T>
|
template <class T>
|
||||||
struct MOZ_MUST_USE_TYPE MOZ_NON_AUTOABLE already_AddRefed {
|
struct
|
||||||
|
#if !defined(MOZ_CLANG_PLUGIN) && !defined(XGILL_PLUGIN)
|
||||||
|
[[nodiscard]]
|
||||||
|
#endif
|
||||||
|
MOZ_NON_AUTOABLE already_AddRefed {
|
||||||
already_AddRefed() : mRawPtr(nullptr) {}
|
already_AddRefed() : mRawPtr(nullptr) {}
|
||||||
|
|
||||||
// For simplicity, allow returning nullptr from functions returning
|
// For simplicity, allow returning nullptr from functions returning
|
||||||
|
|
|
||||||
|
|
@ -439,7 +439,7 @@ constexpr auto ToResult(Result<V, E>&& aValue)
|
||||||
* V* const, E> is not possible.)
|
* V* const, E> is not possible.)
|
||||||
*/
|
*/
|
||||||
template <typename V, typename E>
|
template <typename V, typename E>
|
||||||
class MOZ_MUST_USE_TYPE Result final {
|
class [[nodiscard]] Result final {
|
||||||
// See class comment on Result<const V, E> and Result<V, const E>.
|
// See class comment on Result<const V, E> and Result<V, const E>.
|
||||||
static_assert(!std::is_const_v<V>);
|
static_assert(!std::is_const_v<V>);
|
||||||
static_assert(!std::is_const_v<E>);
|
static_assert(!std::is_const_v<E>);
|
||||||
|
|
@ -745,7 +745,7 @@ class MOZ_MUST_USE_TYPE Result final {
|
||||||
* useful in error-handling macros; see MOZ_TRY for an example.
|
* useful in error-handling macros; see MOZ_TRY for an example.
|
||||||
*/
|
*/
|
||||||
template <typename E>
|
template <typename E>
|
||||||
class MOZ_MUST_USE_TYPE GenericErrorResult {
|
class [[nodiscard]] GenericErrorResult {
|
||||||
E mErrorValue;
|
E mErrorValue;
|
||||||
|
|
||||||
template <typename V, typename E2>
|
template <typename V, typename E2>
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ struct ErrorPropagationTag;
|
||||||
// Allow nsresult errors to automatically convert to nsresult values, so MOZ_TRY
|
// Allow nsresult errors to automatically convert to nsresult values, so MOZ_TRY
|
||||||
// can be used in XPCOM methods with Result<T, nserror> results.
|
// can be used in XPCOM methods with Result<T, nserror> results.
|
||||||
template <>
|
template <>
|
||||||
class MOZ_MUST_USE_TYPE GenericErrorResult<nsresult> {
|
class [[nodiscard]] GenericErrorResult<nsresult> {
|
||||||
nsresult mErrorValue;
|
nsresult mErrorValue;
|
||||||
|
|
||||||
template <typename V, typename E2>
|
template <typename V, typename E2>
|
||||||
|
|
|
||||||
|
|
@ -473,8 +473,8 @@ renaming_overrides_prefixing = true
|
||||||
inline bool IsRight() const;
|
inline bool IsRight() const;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# TODO(emilio): Add hooks to cbindgen to be able to generate MOZ_MUST_USE_TYPE
|
# TODO(emilio): Add hooks to cbindgen to be able to generate [[nodiscard]]
|
||||||
# or [[nodiscard]] on the functions.
|
# on the functions.
|
||||||
"Owned" = """
|
"Owned" = """
|
||||||
UniquePtr<GeckoType> Consume() {
|
UniquePtr<GeckoType> Consume() {
|
||||||
UniquePtr<GeckoType> ret(ptr);
|
UniquePtr<GeckoType> ret(ptr);
|
||||||
|
|
|
||||||
|
|
@ -234,9 +234,9 @@ struct UnusedZero<nsresult> {
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class MOZ_MUST_USE_TYPE GenericErrorResult;
|
class GenericErrorResult;
|
||||||
template <>
|
template <>
|
||||||
class MOZ_MUST_USE_TYPE GenericErrorResult<nsresult>;
|
class GenericErrorResult<nsresult>;
|
||||||
|
|
||||||
struct Ok;
|
struct Ok;
|
||||||
template <typename V, typename E>
|
template <typename V, typename E>
|
||||||
|
|
|
||||||
|
|
@ -290,7 +290,7 @@ to OOM).
|
||||||
The ``must_use`` property is useful if the result of a method call or an
|
The ``must_use`` property is useful if the result of a method call or an
|
||||||
attribute get/set should always (or usually) be checked, which is frequently
|
attribute get/set should always (or usually) be checked, which is frequently
|
||||||
the case. (e.g. a method that opens a file should almost certainly have its
|
the case. (e.g. a method that opens a file should almost certainly have its
|
||||||
result checked.) This property will cause ``MOZ_MUST_USE`` to be added to the
|
result checked.) This property will cause ``[[nodiscard]]`` to be added to the
|
||||||
generated function declarations, which means certain compilers (e.g. clang and
|
generated function declarations, which means certain compilers (e.g. clang and
|
||||||
GCC) will reports errors if these results are not used.
|
GCC) will reports errors if these results are not used.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue