]> git.lizzy.rs Git - rust.git/commitdiff
stabilize `#[must_use]` for functions and must-use operators
authorZack M. Davis <code@zackmdavis.net>
Sun, 11 Mar 2018 00:23:28 +0000 (16:23 -0800)
committerZack M. Davis <code@zackmdavis.net>
Sun, 29 Apr 2018 03:32:49 +0000 (20:32 -0700)
This is in the matter of RFC 1940 and tracking issue #43302.

22 files changed:
src/doc/unstable-book/src/language-features/fn-must-use.md [deleted file]
src/liballoc/lib.rs
src/liballoc/tests/slice.rs
src/libcore/lib.rs
src/librustc_lint/unused.rs
src/libstd/ffi/c_str.rs
src/libstd/sync/mpsc/select.rs
src/libsyntax/feature_gate.rs
src/test/ui/feature-gate-fn_must_use-cap-lints-allow.rs [deleted file]
src/test/ui/feature-gate-fn_must_use-cap-lints-allow.stderr [deleted file]
src/test/ui/feature-gate-fn_must_use.rs [deleted file]
src/test/ui/feature-gate-fn_must_use.stderr [deleted file]
src/test/ui/feature-gate/issue-43106-gating-of-builtin-attrs.rs
src/test/ui/feature-gate/issue-43106-gating-of-builtin-attrs.stderr
src/test/ui/fn_must_use.rs [new file with mode: 0644]
src/test/ui/fn_must_use.stderr [new file with mode: 0644]
src/test/ui/lint/must-use-ops.rs
src/test/ui/lint/must-use-ops.stderr
src/test/ui/rfc_1940-must_use_on_functions/fn_must_use.rs [deleted file]
src/test/ui/rfc_1940-must_use_on_functions/fn_must_use.stderr [deleted file]
src/test/ui/span/gated-features-attr-spans.rs
src/test/ui/span/gated-features-attr-spans.stderr

diff --git a/src/doc/unstable-book/src/language-features/fn-must-use.md b/src/doc/unstable-book/src/language-features/fn-must-use.md
deleted file mode 100644 (file)
index 71b6cd6..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-# `fn_must_use`
-
-The tracking issue for this feature is [#43302].
-
-[#43302]: https://github.com/rust-lang/rust/issues/43302
-
-------------------------
-
-The `fn_must_use` feature allows functions and methods to be annotated with
-`#[must_use]`, indicating that the `unused_must_use` lint should require their
-return values to be used (similarly to how types annotated with `must_use`,
-most notably `Result`, are linted if not used).
-
-## Examples
-
-```rust
-#![feature(fn_must_use)]
-
-#[must_use]
-fn double(x: i32) -> i32 {
-    2 * x
-}
-
-fn main() {
-    double(4); // warning: unused return value of `double` which must be used
-
-    let _ = double(4); // (no warning)
-}
-
-```
index 021395d0c824a0c88f19d45157a24b17f776644a..fa74352c23cd5a9c8ea9e26ac9b9f446c4a89ef9 100644 (file)
@@ -96,7 +96,7 @@
 #![feature(dropck_eyepatch)]
 #![feature(exact_size_is_empty)]
 #![feature(fmt_internals)]
-#![feature(fn_must_use)]
+#![cfg_attr(stage0, feature(fn_must_use))]
 #![feature(from_ref)]
 #![feature(fundamental)]
 #![feature(lang_items)]
index 99d9c51efc75790c2e552c89d6490423445a2292..6fd0b33f02a60a9632249c6be29dac951d248ea7 100644 (file)
@@ -1282,6 +1282,7 @@ fn test_box_slice_clone() {
 }
 
 #[test]
+#[allow(unused_must_use)] // here, we care about the side effects of `.clone()`
 #[cfg_attr(target_os = "emscripten", ignore)]
 fn test_box_slice_clone_panics() {
     use std::sync::Arc;
index 0e21a3327fddf471f6a486fb9e1f222f5e545981..f4ed24cc3a3727129bb6f219c6f497156fb98c92 100644 (file)
@@ -76,7 +76,6 @@
 #![feature(doc_cfg)]
 #![feature(doc_spotlight)]
 #![feature(extern_types)]
-#![feature(fn_must_use)]
 #![feature(fundamental)]
 #![feature(intrinsics)]
 #![feature(iterator_flatten)]
 
 #![cfg_attr(stage0, feature(target_feature))]
 #![cfg_attr(stage0, feature(cfg_target_feature))]
+#![cfg_attr(stage0, feature(fn_must_use))]
 
 #[prelude_import]
 #[allow(unused)]
index c32e9cdce0e61409ed46f52d28bcf1420290fdb5..9e1b75ba3366abbea6f3e42038ba422d738f026b 100644 (file)
@@ -73,59 +73,59 @@ fn check_stmt(&mut self, cx: &LateContext, s: &hir::Stmt) {
 
         let mut fn_warned = false;
         let mut op_warned = false;
-        if cx.tcx.features().fn_must_use {
-            let maybe_def = match expr.node {
-                hir::ExprCall(ref callee, _) => {
-                    match callee.node {
-                        hir::ExprPath(ref qpath) => {
-                            let def = cx.tables.qpath_def(qpath, callee.hir_id);
-                            if let Def::Fn(_) = def {
-                                Some(def)
-                            } else {  // `Def::Local` if it was a closure, for which we
-                                None  // do not currently support must-use linting
-                            }
-                        },
-                        _ => None
-                    }
-                },
-                hir::ExprMethodCall(..) => {
-                    cx.tables.type_dependent_defs().get(expr.hir_id).cloned()
-                },
-                _ => None
-            };
-            if let Some(def) = maybe_def {
-                let def_id = def.def_id();
-                fn_warned = check_must_use(cx, def_id, s.span, "return value of ");
-            }
-            let must_use_op = match expr.node {
-                // Hardcoding operators here seemed more expedient than the
-                // refactoring that would be needed to look up the `#[must_use]`
-                // attribute which does exist on the comparison trait methods
-                hir::ExprBinary(bin_op, ..)  => {
-                    match bin_op.node {
-                        hir::BiEq | hir::BiLt | hir::BiLe | hir::BiNe | hir::BiGe | hir::BiGt => {
-                            Some("comparison")
-                        },
-                        hir::BiAdd | hir::BiSub | hir::BiDiv | hir::BiMul | hir::BiRem => {
-                            Some("arithmetic operation")
-                        },
-                        hir::BiAnd | hir::BiOr => {
-                            Some("logical operation")
-                        },
-                        hir::BiBitXor | hir::BiBitAnd | hir::BiBitOr | hir::BiShl | hir::BiShr => {
-                            Some("bitwise operation")
-                        },
-                    }
-                },
-                hir::ExprUnary(..) => Some("unary operation"),
-                _ => None
-            };
-            if let Some(must_use_op) = must_use_op {
-                cx.span_lint(UNUSED_MUST_USE, expr.span,
-                    &format!("unused {} which must be used", must_use_op));
-                op_warned = true;
-            }
+        let maybe_def = match expr.node {
+            hir::ExprCall(ref callee, _) => {
+                match callee.node {
+                    hir::ExprPath(ref qpath) => {
+                        let def = cx.tables.qpath_def(qpath, callee.hir_id);
+                        if let Def::Fn(_) = def {
+                            Some(def)
+                        } else {  // `Def::Local` if it was a closure, for which we
+                            None  // do not currently support must-use linting
+                        }
+                    },
+                    _ => None
+                }
+            },
+            hir::ExprMethodCall(..) => {
+                cx.tables.type_dependent_defs().get(expr.hir_id).cloned()
+            },
+            _ => None
+        };
+        if let Some(def) = maybe_def {
+            let def_id = def.def_id();
+            fn_warned = check_must_use(cx, def_id, s.span, "return value of ");
         }
+        let must_use_op = match expr.node {
+            // Hardcoding operators here seemed more expedient than the
+            // refactoring that would be needed to look up the `#[must_use]`
+            // attribute which does exist on the comparison trait methods
+            hir::ExprBinary(bin_op, ..)  => {
+                match bin_op.node {
+                    hir::BiEq | hir::BiLt | hir::BiLe | hir::BiNe | hir::BiGe | hir::BiGt => {
+                        Some("comparison")
+                    },
+                    hir::BiAdd | hir::BiSub | hir::BiDiv | hir::BiMul | hir::BiRem => {
+                        Some("arithmetic operation")
+                    },
+                    hir::BiAnd | hir::BiOr => {
+                        Some("logical operation")
+                    },
+                    hir::BiBitXor | hir::BiBitAnd | hir::BiBitOr | hir::BiShl | hir::BiShr => {
+                        Some("bitwise operation")
+                    },
+                }
+            },
+            hir::ExprUnary(..) => Some("unary operation"),
+            _ => None
+        };
+
+        if let Some(must_use_op) = must_use_op {
+            cx.span_lint(UNUSED_MUST_USE, expr.span,
+                         &format!("unused {} which must be used", must_use_op));
+            op_warned = true;
+        }
+
         if !(ty_warned || fn_warned || op_warned) {
             cx.span_lint(UNUSED_RESULTS, s.span, "unused result");
         }
index c88c2bc913713634aa465e8fa82830226b3802e2..d4937c00012284df935bff4f0bf8d36170310d4c 100644 (file)
@@ -988,6 +988,7 @@ pub unsafe fn from_bytes_with_nul_unchecked(bytes: &[u8]) -> &CStr {
     /// behavior when `ptr` is used inside the `unsafe` block:
     ///
     /// ```no_run
+    /// # #![allow(unused_must_use)]
     /// use std::ffi::{CString};
     ///
     /// let ptr = CString::new("Hello").unwrap().as_ptr();
@@ -1003,6 +1004,7 @@ pub unsafe fn from_bytes_with_nul_unchecked(bytes: &[u8]) -> &CStr {
     /// To fix the problem, bind the `CString` to a local variable:
     ///
     /// ```no_run
+    /// # #![allow(unused_must_use)]
     /// use std::ffi::{CString};
     ///
     /// let hello = CString::new("Hello").unwrap();
index a9f3cea243f366c61e0abf759c474c95a00581ae..9310dad9172a9f816436039b0d6bb4e15d836dc6 100644 (file)
@@ -518,6 +518,7 @@ fn stress() {
         }
     }
 
+    #[allow(unused_must_use)]
     #[test]
     fn cloning() {
         let (tx1, rx1) = channel::<i32>();
@@ -540,6 +541,7 @@ fn cloning() {
         tx3.send(()).unwrap();
     }
 
+    #[allow(unused_must_use)]
     #[test]
     fn cloning2() {
         let (tx1, rx1) = channel::<i32>();
index a4a83712a083a730029d66aacb1542a13db6d45d..f16b1ba440ac46feb799250ac6d90b2cff1f55a1 100644 (file)
@@ -369,9 +369,6 @@ pub fn walk_feature_fields<F>(&self, mut f: F)
     // #[doc(include="some-file")]
     (active, external_doc, "1.22.0", Some(44732), None),
 
-    // allow `#[must_use]` on functions and comparison operators (RFC 1940)
-    (active, fn_must_use, "1.21.0", Some(43302), None),
-
     // Future-proofing enums/structs with #[non_exhaustive] attribute (RFC 2008)
     (active, non_exhaustive, "1.22.0", Some(44109), None),
 
@@ -591,6 +588,8 @@ pub fn walk_feature_fields<F>(&self, mut f: F)
     (accepted, target_feature, "1.27.0", None, None),
     // Trait object syntax with `dyn` prefix
     (accepted, dyn_trait, "1.27.0", Some(44662), None),
+    // allow `#[must_use]` on functions; and, must-use operators (RFC 1940)
+    (accepted, fn_must_use, "1.27.0", Some(43302), None),
 );
 
 // If you change this, please modify src/doc/unstable-book as well. You must
@@ -1545,11 +1544,6 @@ fn visit_item(&mut self, i: &'a ast::Item) {
                                         function may change over time, for now \
                                         a top-level `fn main()` is required");
                 }
-                if let Some(attr) = attr::find_by_name(&i.attrs[..], "must_use") {
-                    gate_feature_post!(&self, fn_must_use, attr.span,
-                                       "`#[must_use]` on functions is experimental",
-                                       GateStrength::Soft);
-                }
             }
 
             ast::ItemKind::Struct(..) => {
@@ -1581,7 +1575,7 @@ fn visit_item(&mut self, i: &'a ast::Item) {
                                    "trait aliases are not yet fully implemented");
             }
 
-            ast::ItemKind::Impl(_, polarity, defaultness, _, _, _, ref impl_items) => {
+            ast::ItemKind::Impl(_, polarity, defaultness, _, _, _, _) => {
                 if polarity == ast::ImplPolarity::Negative {
                     gate_feature_post!(&self, optin_builtin_traits,
                                        i.span,
@@ -1594,16 +1588,6 @@ fn visit_item(&mut self, i: &'a ast::Item) {
                                        i.span,
                                        "specialization is unstable");
                 }
-
-                for impl_item in impl_items {
-                    if let ast::ImplItemKind::Method(..) = impl_item.node {
-                        if let Some(attr) = attr::find_by_name(&impl_item.attrs[..], "must_use") {
-                            gate_feature_post!(&self, fn_must_use, attr.span,
-                                               "`#[must_use]` on methods is experimental",
-                                               GateStrength::Soft);
-                        }
-                    }
-                }
             }
 
             ast::ItemKind::Trait(ast::IsAuto::Yes, ..) => {
diff --git a/src/test/ui/feature-gate-fn_must_use-cap-lints-allow.rs b/src/test/ui/feature-gate-fn_must_use-cap-lints-allow.rs
deleted file mode 100644 (file)
index 1c04199..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// compile-flags: --cap-lints allow
-
-// This tests that the fn_must_use feature-gate warning respects the lint
-// cap. (See discussion in Issue #44213.)
-
-#![feature(rustc_attrs)]
-
-#[must_use] // (no feature-gate warning because of the lint cap!)
-fn need_to_use_it() -> bool { true }
-
-#[rustc_error]
-fn main() {} //~ ERROR compilation successful
diff --git a/src/test/ui/feature-gate-fn_must_use-cap-lints-allow.stderr b/src/test/ui/feature-gate-fn_must_use-cap-lints-allow.stderr
deleted file mode 100644 (file)
index a2c1ded..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-error: compilation successful
-  --> $DIR/feature-gate-fn_must_use-cap-lints-allow.rs:22:1
-   |
-LL | fn main() {} //~ ERROR compilation successful
-   | ^^^^^^^^^^^^
-
-error: aborting due to previous error
-
diff --git a/src/test/ui/feature-gate-fn_must_use.rs b/src/test/ui/feature-gate-fn_must_use.rs
deleted file mode 100644 (file)
index 72fdcc7..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![feature(rustc_attrs)]
-
-struct MyStruct;
-
-impl MyStruct {
-    #[must_use] //~ WARN `#[must_use]` on methods is experimental
-    fn need_to_use_method() -> bool { true }
-}
-
-#[must_use] //~ WARN `#[must_use]` on functions is experimental
-fn need_to_use_it() -> bool { true }
-
-
-// Feature gates are tidy-required to have a specially named (or
-// comment-annotated) compile-fail test (which MUST fail), but for
-// backwards-compatibility reasons, we want `#[must_use]` on functions to be
-// compilable even if the `fn_must_use` feature is absent, thus necessitating
-// the usage of `#[rustc_error]` here, pragmatically if awkwardly solving this
-// dilemma until a superior solution can be devised.
-#[rustc_error]
-fn main() {} //~ ERROR compilation successful
diff --git a/src/test/ui/feature-gate-fn_must_use.stderr b/src/test/ui/feature-gate-fn_must_use.stderr
deleted file mode 100644 (file)
index 431c57a..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-warning: `#[must_use]` on methods is experimental (see issue #43302)
-  --> $DIR/feature-gate-fn_must_use.rs:16:5
-   |
-LL |     #[must_use] //~ WARN `#[must_use]` on methods is experimental
-   |     ^^^^^^^^^^^
-   |
-   = help: add #![feature(fn_must_use)] to the crate attributes to enable
-
-warning: `#[must_use]` on functions is experimental (see issue #43302)
-  --> $DIR/feature-gate-fn_must_use.rs:20:1
-   |
-LL | #[must_use] //~ WARN `#[must_use]` on functions is experimental
-   | ^^^^^^^^^^^
-   |
-   = help: add #![feature(fn_must_use)] to the crate attributes to enable
-
-error: compilation successful
-  --> $DIR/feature-gate-fn_must_use.rs:31:1
-   |
-LL | fn main() {} //~ ERROR compilation successful
-   | ^^^^^^^^^^^^
-
-error: aborting due to previous error
-
index 21950402c8c41cedd3007d2368b4b28253a17cbc..7b0c81dbab6511ced7ca328851f6ff58a3c5e9ca 100644 (file)
@@ -661,7 +661,6 @@ mod must_use {
     mod inner { #![must_use="1400"] }
 
     #[must_use = "1400"] fn f() { }
-    //~^ WARN `#[must_use]` on functions is experimental
 
     #[must_use = "1400"] struct S;
 
index 0beed62798710e9710efff7af3c438e1b0f6e0bf..76ab50c9089afa1d0be488e3e1932869c990f011 100644 (file)
@@ -12,14 +12,6 @@ LL |     mod inner { #![macro_escape] }
    |
    = help: consider an outer attribute, #[macro_use] mod ...
 
-warning: `#[must_use]` on functions is experimental (see issue #43302)
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:663:5
-   |
-LL |     #[must_use = "1400"] fn f() { }
-   |     ^^^^^^^^^^^^^^^^^^^^
-   |
-   = help: add #![feature(fn_must_use)] to the crate attributes to enable
-
 warning: unknown lint: `x5400`
   --> $DIR/issue-43106-gating-of-builtin-attrs.rs:49:33
    |
@@ -799,433 +791,433 @@ LL | #[no_std = "2600"]
    | ^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:692:17
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:691:17
    |
 LL |     mod inner { #![crate_name="0900"] }
    |                 ^^^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be in the root module
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:692:17
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:691:17
    |
 LL |     mod inner { #![crate_name="0900"] }
    |                 ^^^^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:696:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:695:5
    |
 LL |     #[crate_name = "0900"] fn f() { }
    |     ^^^^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:696:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:695:5
    |
 LL |     #[crate_name = "0900"] fn f() { }
    |     ^^^^^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:700:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:699:5
    |
 LL |     #[crate_name = "0900"] struct S;
    |     ^^^^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:700:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:699:5
    |
 LL |     #[crate_name = "0900"] struct S;
    |     ^^^^^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:704:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:703:5
    |
 LL |     #[crate_name = "0900"] type T = S;
    |     ^^^^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:704:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:703:5
    |
 LL |     #[crate_name = "0900"] type T = S;
    |     ^^^^^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:708:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:707:5
    |
 LL |     #[crate_name = "0900"] impl S { }
    |     ^^^^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:708:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:707:5
    |
 LL |     #[crate_name = "0900"] impl S { }
    |     ^^^^^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:688:1
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:687:1
    |
 LL | #[crate_name = "0900"]
    | ^^^^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:688:1
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:687:1
    |
 LL | #[crate_name = "0900"]
    | ^^^^^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:717:17
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:716:17
    |
 LL |     mod inner { #![crate_type="0800"] }
    |                 ^^^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be in the root module
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:717:17
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:716:17
    |
 LL |     mod inner { #![crate_type="0800"] }
    |                 ^^^^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:721:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:720:5
    |
 LL |     #[crate_type = "0800"] fn f() { }
    |     ^^^^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:721:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:720:5
    |
 LL |     #[crate_type = "0800"] fn f() { }
    |     ^^^^^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:725:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:724:5
    |
 LL |     #[crate_type = "0800"] struct S;
    |     ^^^^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:725:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:724:5
    |
 LL |     #[crate_type = "0800"] struct S;
    |     ^^^^^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:729:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:728:5
    |
 LL |     #[crate_type = "0800"] type T = S;
    |     ^^^^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:729:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:728:5
    |
 LL |     #[crate_type = "0800"] type T = S;
    |     ^^^^^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:733:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:732:5
    |
 LL |     #[crate_type = "0800"] impl S { }
    |     ^^^^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:733:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:732:5
    |
 LL |     #[crate_type = "0800"] impl S { }
    |     ^^^^^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:713:1
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:712:1
    |
 LL | #[crate_type = "0800"]
    | ^^^^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:713:1
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:712:1
    |
 LL | #[crate_type = "0800"]
    | ^^^^^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:742:17
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:741:17
    |
 LL |     mod inner { #![feature(x0600)] }
    |                 ^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be in the root module
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:742:17
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:741:17
    |
 LL |     mod inner { #![feature(x0600)] }
    |                 ^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:746:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:745:5
    |
 LL |     #[feature(x0600)] fn f() { }
    |     ^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:746:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:745:5
    |
 LL |     #[feature(x0600)] fn f() { }
    |     ^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:750:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:749:5
    |
 LL |     #[feature(x0600)] struct S;
    |     ^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:750:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:749:5
    |
 LL |     #[feature(x0600)] struct S;
    |     ^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:754:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:753:5
    |
 LL |     #[feature(x0600)] type T = S;
    |     ^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:754:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:753:5
    |
 LL |     #[feature(x0600)] type T = S;
    |     ^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:758:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:757:5
    |
 LL |     #[feature(x0600)] impl S { }
    |     ^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:758:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:757:5
    |
 LL |     #[feature(x0600)] impl S { }
    |     ^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:738:1
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:737:1
    |
 LL | #[feature(x0600)]
    | ^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:738:1
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:737:1
    |
 LL | #[feature(x0600)]
    | ^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:768:17
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:767:17
    |
 LL |     mod inner { #![no_main="0400"] }
    |                 ^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be in the root module
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:768:17
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:767:17
    |
 LL |     mod inner { #![no_main="0400"] }
    |                 ^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:772:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:771:5
    |
 LL |     #[no_main = "0400"] fn f() { }
    |     ^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:772:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:771:5
    |
 LL |     #[no_main = "0400"] fn f() { }
    |     ^^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:776:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:775:5
    |
 LL |     #[no_main = "0400"] struct S;
    |     ^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:776:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:775:5
    |
 LL |     #[no_main = "0400"] struct S;
    |     ^^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:780:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:779:5
    |
 LL |     #[no_main = "0400"] type T = S;
    |     ^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:780:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:779:5
    |
 LL |     #[no_main = "0400"] type T = S;
    |     ^^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:784:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:783:5
    |
 LL |     #[no_main = "0400"] impl S { }
    |     ^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:784:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:783:5
    |
 LL |     #[no_main = "0400"] impl S { }
    |     ^^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:764:1
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:763:1
    |
 LL | #[no_main = "0400"]
    | ^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:764:1
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:763:1
    |
 LL | #[no_main = "0400"]
    | ^^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:806:17
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:805:17
    |
 LL |     mod inner { #![recursion_limit="0200"] }
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be in the root module
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:806:17
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:805:17
    |
 LL |     mod inner { #![recursion_limit="0200"] }
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:810:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:809:5
    |
 LL |     #[recursion_limit="0200"] fn f() { }
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:810:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:809:5
    |
 LL |     #[recursion_limit="0200"] fn f() { }
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:814:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:813:5
    |
 LL |     #[recursion_limit="0200"] struct S;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:814:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:813:5
    |
 LL |     #[recursion_limit="0200"] struct S;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:818:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:817:5
    |
 LL |     #[recursion_limit="0200"] type T = S;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:818:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:817:5
    |
 LL |     #[recursion_limit="0200"] type T = S;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:822:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:821:5
    |
 LL |     #[recursion_limit="0200"] impl S { }
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:822:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:821:5
    |
 LL |     #[recursion_limit="0200"] impl S { }
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:802:1
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:801:1
    |
 LL | #[recursion_limit="0200"]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:802:1
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:801:1
    |
 LL | #[recursion_limit="0200"]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:831:17
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:830:17
    |
 LL |     mod inner { #![type_length_limit="0100"] }
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be in the root module
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:831:17
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:830:17
    |
 LL |     mod inner { #![type_length_limit="0100"] }
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:835:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:834:5
    |
 LL |     #[type_length_limit="0100"] fn f() { }
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:835:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:834:5
    |
 LL |     #[type_length_limit="0100"] fn f() { }
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:839:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:838:5
    |
 LL |     #[type_length_limit="0100"] struct S;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:839:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:838:5
    |
 LL |     #[type_length_limit="0100"] struct S;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:843:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:842:5
    |
 LL |     #[type_length_limit="0100"] type T = S;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:843:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:842:5
    |
 LL |     #[type_length_limit="0100"] type T = S;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:847:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:846:5
    |
 LL |     #[type_length_limit="0100"] impl S { }
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:847:5
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:846:5
    |
 LL |     #[type_length_limit="0100"] impl S { }
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: unused attribute
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:827:1
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:826:1
    |
 LL | #[type_length_limit="0100"]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 warning: crate-level attribute should be an inner attribute: add an exclamation mark: #![foo]
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:827:1
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:826:1
    |
 LL | #[type_length_limit="0100"]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -1309,7 +1301,7 @@ LL | #![proc_macro_derive          = "2500"] //~ WARN unused attribute
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: compilation successful
-  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:858:1
+  --> $DIR/issue-43106-gating-of-builtin-attrs.rs:857:1
    |
 LL | / fn main() { //~ ERROR compilation successful
 LL | |     println!("Hello World");
diff --git a/src/test/ui/fn_must_use.rs b/src/test/ui/fn_must_use.rs
new file mode 100644 (file)
index 0000000..def2304
--- /dev/null
@@ -0,0 +1,78 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// compile-pass
+
+#![warn(unused_must_use)]
+
+#[derive(PartialEq, Eq)]
+struct MyStruct {
+    n: usize,
+}
+
+impl MyStruct {
+    #[must_use]
+    fn need_to_use_this_method_value(&self) -> usize {
+        self.n
+    }
+}
+
+trait EvenNature {
+    #[must_use = "no side effects"]
+    fn is_even(&self) -> bool;
+}
+
+impl EvenNature for MyStruct {
+    fn is_even(&self) -> bool {
+        self.n % 2 == 0
+    }
+}
+
+trait Replaceable {
+    fn replace(&mut self, substitute: usize) -> usize;
+}
+
+impl Replaceable for MyStruct {
+    // ↓ N.b.: `#[must_use]` attribute on a particular trait implementation
+    // method won't work; the attribute should be on the method signature in
+    // the trait's definition.
+    #[must_use]
+    fn replace(&mut self, substitute: usize) -> usize {
+        let previously = self.n;
+        self.n = substitute;
+        previously
+    }
+}
+
+#[must_use = "it's important"]
+fn need_to_use_this_value() -> bool {
+    false
+}
+
+fn main() {
+    need_to_use_this_value(); //~ WARN unused return value
+
+    let mut m = MyStruct { n: 2 };
+    let n = MyStruct { n: 3 };
+
+    m.need_to_use_this_method_value(); //~ WARN unused return value
+    m.is_even(); // trait method!
+    //~^ WARN unused return value
+
+    m.replace(3); // won't warn (annotation needs to be in trait definition)
+
+    // comparison methods are `must_use`
+    2.eq(&3); //~ WARN unused return value
+    m.eq(&n); //~ WARN unused return value
+
+    // lint includes comparison operators
+    2 == 3; //~ WARN unused comparison
+    m == n; //~ WARN unused comparison
+}
diff --git a/src/test/ui/fn_must_use.stderr b/src/test/ui/fn_must_use.stderr
new file mode 100644 (file)
index 0000000..5026dac
--- /dev/null
@@ -0,0 +1,48 @@
+warning: unused return value of `need_to_use_this_value` which must be used: it's important
+  --> $DIR/fn_must_use.rs:60:5
+   |
+LL |     need_to_use_this_value(); //~ WARN unused return value
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+note: lint level defined here
+  --> $DIR/fn_must_use.rs:13:9
+   |
+LL | #![warn(unused_must_use)]
+   |         ^^^^^^^^^^^^^^^
+
+warning: unused return value of `MyStruct::need_to_use_this_method_value` which must be used
+  --> $DIR/fn_must_use.rs:65:5
+   |
+LL |     m.need_to_use_this_method_value(); //~ WARN unused return value
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+warning: unused return value of `EvenNature::is_even` which must be used: no side effects
+  --> $DIR/fn_must_use.rs:66:5
+   |
+LL |     m.is_even(); // trait method!
+   |     ^^^^^^^^^^^^
+
+warning: unused return value of `std::cmp::PartialEq::eq` which must be used
+  --> $DIR/fn_must_use.rs:72:5
+   |
+LL |     2.eq(&3); //~ WARN unused return value
+   |     ^^^^^^^^^
+
+warning: unused return value of `std::cmp::PartialEq::eq` which must be used
+  --> $DIR/fn_must_use.rs:73:5
+   |
+LL |     m.eq(&n); //~ WARN unused return value
+   |     ^^^^^^^^^
+
+warning: unused comparison which must be used
+  --> $DIR/fn_must_use.rs:76:5
+   |
+LL |     2 == 3; //~ WARN unused comparison
+   |     ^^^^^^
+
+warning: unused comparison which must be used
+  --> $DIR/fn_must_use.rs:77:5
+   |
+LL |     m == n; //~ WARN unused comparison
+   |     ^^^^^^
+
index 4ed82ab3b4025c283726b3b47b3cac4e2412d935..c0575f817c8d172a522fd41d6d6a77e7e06af5b0 100644 (file)
@@ -12,7 +12,6 @@
 
 // compile-pass
 
-#![feature(fn_must_use)]
 #![warn(unused_must_use)]
 
 fn main() {
index f444ef0907575e4b7cc5f3373ee811b7eed2d355..5703536ef48fd1e1153450e0a1e077b351d8c6a5 100644 (file)
 warning: unused comparison which must be used
-  --> $DIR/must-use-ops.rs:23:5
+  --> $DIR/must-use-ops.rs:22:5
    |
 LL |     val == 1;
    |     ^^^^^^^^
    |
 note: lint level defined here
-  --> $DIR/must-use-ops.rs:16:9
+  --> $DIR/must-use-ops.rs:15:9
    |
 LL | #![warn(unused_must_use)]
    |         ^^^^^^^^^^^^^^^
 
 warning: unused comparison which must be used
-  --> $DIR/must-use-ops.rs:24:5
+  --> $DIR/must-use-ops.rs:23:5
    |
 LL |     val < 1;
    |     ^^^^^^^
 
 warning: unused comparison which must be used
-  --> $DIR/must-use-ops.rs:25:5
+  --> $DIR/must-use-ops.rs:24:5
    |
 LL |     val <= 1;
    |     ^^^^^^^^
 
 warning: unused comparison which must be used
-  --> $DIR/must-use-ops.rs:26:5
+  --> $DIR/must-use-ops.rs:25:5
    |
 LL |     val != 1;
    |     ^^^^^^^^
 
 warning: unused comparison which must be used
-  --> $DIR/must-use-ops.rs:27:5
+  --> $DIR/must-use-ops.rs:26:5
    |
 LL |     val >= 1;
    |     ^^^^^^^^
 
 warning: unused comparison which must be used
-  --> $DIR/must-use-ops.rs:28:5
+  --> $DIR/must-use-ops.rs:27:5
    |
 LL |     val > 1;
    |     ^^^^^^^
 
 warning: unused arithmetic operation which must be used
-  --> $DIR/must-use-ops.rs:31:5
+  --> $DIR/must-use-ops.rs:30:5
    |
 LL |     val + 2;
    |     ^^^^^^^
 
 warning: unused arithmetic operation which must be used
-  --> $DIR/must-use-ops.rs:32:5
+  --> $DIR/must-use-ops.rs:31:5
    |
 LL |     val - 2;
    |     ^^^^^^^
 
 warning: unused arithmetic operation which must be used
-  --> $DIR/must-use-ops.rs:33:5
+  --> $DIR/must-use-ops.rs:32:5
    |
 LL |     val / 2;
    |     ^^^^^^^
 
 warning: unused arithmetic operation which must be used
-  --> $DIR/must-use-ops.rs:34:5
+  --> $DIR/must-use-ops.rs:33:5
    |
 LL |     val * 2;
    |     ^^^^^^^
 
 warning: unused arithmetic operation which must be used
-  --> $DIR/must-use-ops.rs:35:5
+  --> $DIR/must-use-ops.rs:34:5
    |
 LL |     val % 2;
    |     ^^^^^^^
 
 warning: unused logical operation which must be used
-  --> $DIR/must-use-ops.rs:38:5
+  --> $DIR/must-use-ops.rs:37:5
    |
 LL |     true && true;
    |     ^^^^^^^^^^^^
 
 warning: unused logical operation which must be used
-  --> $DIR/must-use-ops.rs:39:5
+  --> $DIR/must-use-ops.rs:38:5
    |
 LL |     false || true;
    |     ^^^^^^^^^^^^^
 
 warning: unused bitwise operation which must be used
-  --> $DIR/must-use-ops.rs:42:5
+  --> $DIR/must-use-ops.rs:41:5
    |
 LL |     5 ^ val;
    |     ^^^^^^^
 
 warning: unused bitwise operation which must be used
-  --> $DIR/must-use-ops.rs:43:5
+  --> $DIR/must-use-ops.rs:42:5
    |
 LL |     5 & val;
    |     ^^^^^^^
 
 warning: unused bitwise operation which must be used
-  --> $DIR/must-use-ops.rs:44:5
+  --> $DIR/must-use-ops.rs:43:5
    |
 LL |     5 | val;
    |     ^^^^^^^
 
 warning: unused bitwise operation which must be used
-  --> $DIR/must-use-ops.rs:45:5
+  --> $DIR/must-use-ops.rs:44:5
    |
 LL |     5 << val;
    |     ^^^^^^^^
 
 warning: unused bitwise operation which must be used
-  --> $DIR/must-use-ops.rs:46:5
+  --> $DIR/must-use-ops.rs:45:5
    |
 LL |     5 >> val;
    |     ^^^^^^^^
 
 warning: unused unary operation which must be used
-  --> $DIR/must-use-ops.rs:49:5
+  --> $DIR/must-use-ops.rs:48:5
    |
 LL |     !val;
    |     ^^^^
 
 warning: unused unary operation which must be used
-  --> $DIR/must-use-ops.rs:50:5
+  --> $DIR/must-use-ops.rs:49:5
    |
 LL |     -val;
    |     ^^^^
 
 warning: unused unary operation which must be used
-  --> $DIR/must-use-ops.rs:51:5
+  --> $DIR/must-use-ops.rs:50:5
    |
 LL |     *val_pointer;
    |     ^^^^^^^^^^^^
diff --git a/src/test/ui/rfc_1940-must_use_on_functions/fn_must_use.rs b/src/test/ui/rfc_1940-must_use_on_functions/fn_must_use.rs
deleted file mode 100644 (file)
index d20ebf0..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// compile-pass
-
-#![feature(fn_must_use)]
-#![warn(unused_must_use)]
-
-#[derive(PartialEq, Eq)]
-struct MyStruct {
-    n: usize,
-}
-
-impl MyStruct {
-    #[must_use]
-    fn need_to_use_this_method_value(&self) -> usize {
-        self.n
-    }
-}
-
-trait EvenNature {
-    #[must_use = "no side effects"]
-    fn is_even(&self) -> bool;
-}
-
-impl EvenNature for MyStruct {
-    fn is_even(&self) -> bool {
-        self.n % 2 == 0
-    }
-}
-
-trait Replaceable {
-    fn replace(&mut self, substitute: usize) -> usize;
-}
-
-impl Replaceable for MyStruct {
-    // ↓ N.b.: `#[must_use]` attribute on a particular trait implementation
-    // method won't work; the attribute should be on the method signature in
-    // the trait's definition.
-    #[must_use]
-    fn replace(&mut self, substitute: usize) -> usize {
-        let previously = self.n;
-        self.n = substitute;
-        previously
-    }
-}
-
-#[must_use = "it's important"]
-fn need_to_use_this_value() -> bool {
-    false
-}
-
-fn main() {
-    need_to_use_this_value(); //~ WARN unused return value
-
-    let mut m = MyStruct { n: 2 };
-    let n = MyStruct { n: 3 };
-
-    m.need_to_use_this_method_value(); //~ WARN unused return value
-    m.is_even(); // trait method!
-    //~^ WARN unused return value
-
-    m.replace(3); // won't warn (annotation needs to be in trait definition)
-
-    // comparison methods are `must_use`
-    2.eq(&3); //~ WARN unused return value
-    m.eq(&n); //~ WARN unused return value
-
-    // lint includes comparison operators
-    2 == 3; //~ WARN unused comparison
-    m == n; //~ WARN unused comparison
-}
diff --git a/src/test/ui/rfc_1940-must_use_on_functions/fn_must_use.stderr b/src/test/ui/rfc_1940-must_use_on_functions/fn_must_use.stderr
deleted file mode 100644 (file)
index d0a8bb5..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-warning: unused return value of `need_to_use_this_value` which must be used: it's important
-  --> $DIR/fn_must_use.rs:61:5
-   |
-LL |     need_to_use_this_value(); //~ WARN unused return value
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^
-   |
-note: lint level defined here
-  --> $DIR/fn_must_use.rs:14:9
-   |
-LL | #![warn(unused_must_use)]
-   |         ^^^^^^^^^^^^^^^
-
-warning: unused return value of `MyStruct::need_to_use_this_method_value` which must be used
-  --> $DIR/fn_must_use.rs:66:5
-   |
-LL |     m.need_to_use_this_method_value(); //~ WARN unused return value
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-warning: unused return value of `EvenNature::is_even` which must be used: no side effects
-  --> $DIR/fn_must_use.rs:67:5
-   |
-LL |     m.is_even(); // trait method!
-   |     ^^^^^^^^^^^^
-
-warning: unused return value of `std::cmp::PartialEq::eq` which must be used
-  --> $DIR/fn_must_use.rs:73:5
-   |
-LL |     2.eq(&3); //~ WARN unused return value
-   |     ^^^^^^^^^
-
-warning: unused return value of `std::cmp::PartialEq::eq` which must be used
-  --> $DIR/fn_must_use.rs:74:5
-   |
-LL |     m.eq(&n); //~ WARN unused return value
-   |     ^^^^^^^^^
-
-warning: unused comparison which must be used
-  --> $DIR/fn_must_use.rs:77:5
-   |
-LL |     2 == 3; //~ WARN unused comparison
-   |     ^^^^^^
-
-warning: unused comparison which must be used
-  --> $DIR/fn_must_use.rs:78:5
-   |
-LL |     m == n; //~ WARN unused comparison
-   |     ^^^^^^
-
index 83a4c5d5dd2ff4fc980291062d5360a6ae530657..eff1f98eb714e69706637b09d3583c1565f63669 100644 (file)
@@ -8,33 +8,10 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(attr_literals)]
-
-#[repr(align(16))]
-struct Gem {
-    mohs_hardness: u8,
-    poofed: bool,
-    weapon: Weapon,
-}
-
 #[repr(simd)] //~ ERROR are experimental
 struct Weapon {
     name: String,
     damage: u32
 }
 
-impl Gem {
-    #[must_use] fn summon_weapon(&self) -> Weapon { self.weapon }
-    //~^ WARN is experimental
-}
-
-#[must_use] //~ WARN is experimental
-fn bubble(gem: Gem) -> Result<Gem, ()> {
-    if gem.poofed {
-        Ok(gem)
-    } else {
-        Err(())
-    }
-}
-
 fn main() {}
index 179daf83c3c0b64c007dccd043b2d536058f15bf..a99530529fcf1a802d80f3a197ea925f7a90ef35 100644 (file)
@@ -1,27 +1,11 @@
 error[E0658]: SIMD types are experimental and possibly buggy (see issue #27731)
-  --> $DIR/gated-features-attr-spans.rs:20:1
+  --> $DIR/gated-features-attr-spans.rs:11:1
    |
 LL | #[repr(simd)] //~ ERROR are experimental
    | ^^^^^^^^^^^^^
    |
    = help: add #![feature(repr_simd)] to the crate attributes to enable
 
-warning: `#[must_use]` on methods is experimental (see issue #43302)
-  --> $DIR/gated-features-attr-spans.rs:27:5
-   |
-LL |     #[must_use] fn summon_weapon(&self) -> Weapon { self.weapon }
-   |     ^^^^^^^^^^^
-   |
-   = help: add #![feature(fn_must_use)] to the crate attributes to enable
-
-warning: `#[must_use]` on functions is experimental (see issue #43302)
-  --> $DIR/gated-features-attr-spans.rs:31:1
-   |
-LL | #[must_use] //~ WARN is experimental
-   | ^^^^^^^^^^^
-   |
-   = help: add #![feature(fn_must_use)] to the crate attributes to enable
-
 error: aborting due to previous error
 
 For more information about this error, try `rustc --explain E0658`.