about summary refs log tree commit diff
path: root/src/test/ui
diff options
context:
space:
mode:
authorZack M. Davis <code@zackmdavis.net>2017-09-30 00:53:26 -0700
committerZack M. Davis <code@zackmdavis.net>2017-10-01 20:15:24 -0700
commit8a14022c5d31e1648bd1212a52a9f1a9ddbf3fa1 (patch)
tree6fd34a9ef9dc811867fe369d66cae8293b0b37bf /src/test/ui
parente3b498971dfb5009f15700d103c88a6c427edd30 (diff)
downloadrust-8a14022c5d31e1648bd1212a52a9f1a9ddbf3fa1.tar.gz
rust-8a14022c5d31e1648bd1212a52a9f1a9ddbf3fa1.zip
correct unused-parens lint suggestion to strip exact pair
Diffstat (limited to 'src/test/ui')
-rw-r--r--src/test/ui/lint/unused_parens_json_suggestion.rs25
-rw-r--r--src/test/ui/lint/unused_parens_json_suggestion.stderr1
2 files changed, 26 insertions, 0 deletions
diff --git a/src/test/ui/lint/unused_parens_json_suggestion.rs b/src/test/ui/lint/unused_parens_json_suggestion.rs
new file mode 100644
index 00000000000..d7cbd11472a
--- /dev/null
+++ b/src/test/ui/lint/unused_parens_json_suggestion.rs
@@ -0,0 +1,25 @@
+// 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: --error-format json
+
+// ignore-windows (see Issue #44968)
+
+// The output for humans should just highlight the whole span without showing
+// the suggested replacement, but we also want to test that suggested
+// replacement only removes one set of parentheses, rather than naïvely
+// stripping away any starting or ending parenthesis characters—hence this
+// test of the JSON error format.
+
+fn main() {
+    // We want to suggest the properly-balanced expression `1 / (2 + 3)`, not
+    // the malformed `1 / (2 + 3`
+    let _a = (1 / (2 + 3));
+}
diff --git a/src/test/ui/lint/unused_parens_json_suggestion.stderr b/src/test/ui/lint/unused_parens_json_suggestion.stderr
new file mode 100644
index 00000000000..140224e0814
--- /dev/null
+++ b/src/test/ui/lint/unused_parens_json_suggestion.stderr
@@ -0,0 +1 @@
+{"message":"unnecessary parentheses around assigned value","code":null,"level":"warning","spans":[{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":1014,"byte_end":1027,"line_start":24,"line_end":24,"column_start":14,"column_end":27,"is_primary":true,"text":[{"text":"    let _a = (1 / (2 + 3));","highlight_start":14,"highlight_end":27}],"label":null,"suggested_replacement":null,"expansion":null}],"children":[{"message":"#[warn(unused_parens)] on by default","code":null,"level":"note","spans":[],"children":[],"rendered":null},{"message":"remove these parentheses","code":null,"level":"help","spans":[{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":1014,"byte_end":1027,"line_start":24,"line_end":24,"column_start":14,"column_end":27,"is_primary":true,"text":[{"text":"    let _a = (1 / (2 + 3));","highlight_start":14,"highlight_end":27}],"label":null,"suggested_replacement":"1 / (2 + 3)","expansion":null}],"children":[],"rendered":"    let _a = 1 / (2 + 3);"}],"rendered":null}