about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorZack M. Davis <code@zackmdavis.net>2018-01-31 20:56:01 -0800
committerZack M. Davis <code@zackmdavis.net>2018-01-31 21:27:16 -0800
commite4b1a7971d7b4ed61d27af44e3169cb26595ae13 (patch)
treec098bbf8f2ecc5d4ca8fecf2d9b6332b03633f46 /src/test
parent8f9d91587fa1d2595405f8a1cc1c43e7b044be1a (diff)
concerning well-formed suggestions for unused shorthand field patterns
Previously, unused variables would get a note that the warning could be
silenced by prefixing the variable with an underscore, but that doesn't
work for field shorthand patterns, which the liveness analysis didn't
know about.

The "to avoid this warning" verbiage seemed unnecessary.

Resolves #47390.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.rs34
-rw-r--r--src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.stderr40
-rw-r--r--src/test/ui/span/issue-24690.stderr3
3 files changed, 75 insertions, 2 deletions
diff --git a/src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.rs b/src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.rs
new file mode 100644
index 00000000000..a68b4f76352
--- /dev/null
+++ b/src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.rs
@@ -0,0 +1,34 @@
+// Copyright 2018 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.
+
+// must-compile-successfully
+
+#![warn(unused)] // UI tests pass `-A unused` (#43896)
+
+struct SoulHistory {
+    corridors_of_light: usize,
+    hours_are_suns: bool,
+    endless_and_singing: bool
+}
+
+fn main() {
+    let i_think_continually = 2;
+    let who_from_the_womb_remembered = SoulHistory {
+        corridors_of_light: 5,
+        hours_are_suns: true,
+        endless_and_singing: true
+    };
+
+    if let SoulHistory { corridors_of_light,
+                         mut hours_are_suns,
+                         endless_and_singing: true } = who_from_the_womb_remembered {
+        hours_are_suns = false;
+    }
+}
diff --git a/src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.stderr b/src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.stderr
new file mode 100644
index 00000000000..694fe69e016
--- /dev/null
+++ b/src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.stderr
@@ -0,0 +1,40 @@
+warning: unused variable: `i_think_continually`
+  --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:22:9
+   |
+22 |     let i_think_continually = 2;
+   |         ^^^^^^^^^^^^^^^^^^^ help: consider using `_i_think_continually` instead
+   |
+note: lint level defined here
+  --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:13:9
+   |
+13 | #![warn(unused)] // UI tests pass `-A unused` (#43896)
+   |         ^^^^^^
+   = note: #[warn(unused_variables)] implied by #[warn(unused)]
+
+warning: unused variable: `corridors_of_light`
+  --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:29:26
+   |
+29 |     if let SoulHistory { corridors_of_light,
+   |                          ^^^^^^^^^^^^^^^^^^ help: try ignoring the field: `corridors_of_light: _`
+
+warning: variable `hours_are_suns` is assigned to, but never used
+  --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:30:26
+   |
+30 |                          mut hours_are_suns,
+   |                          ^^^^^^^^^^^^^^^^^^
+   |
+   = note: consider using `_hours_are_suns` instead
+
+warning: value assigned to `hours_are_suns` is never read
+  --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:32:9
+   |
+32 |         hours_are_suns = false;
+   |         ^^^^^^^^^^^^^^
+   |
+note: lint level defined here
+  --> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:13:9
+   |
+13 | #![warn(unused)] // UI tests pass `-A unused` (#43896)
+   |         ^^^^^^
+   = note: #[warn(unused_assignments)] implied by #[warn(unused)]
+
diff --git a/src/test/ui/span/issue-24690.stderr b/src/test/ui/span/issue-24690.stderr
index 7e19c7492ce..31728dbf08d 100644
--- a/src/test/ui/span/issue-24690.stderr
+++ b/src/test/ui/span/issue-24690.stderr
@@ -2,7 +2,7 @@ warning: unused variable: `theOtherTwo`
   --> $DIR/issue-24690.rs:23:9
    |
 23 |     let theOtherTwo = 2; //~ WARN should have a snake case name
-   |         ^^^^^^^^^^^
+   |         ^^^^^^^^^^^ help: consider using `_theOtherTwo` instead
    |
 note: lint level defined here
   --> $DIR/issue-24690.rs:18:9
@@ -10,7 +10,6 @@ note: lint level defined here
 18 | #![warn(unused)]
    |         ^^^^^^
    = note: #[warn(unused_variables)] implied by #[warn(unused)]
-   = note: to avoid this warning, consider using `_theOtherTwo` instead
 
 warning: variable `theTwo` should have a snake case name such as `the_two`
   --> $DIR/issue-24690.rs:22:9