about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorYuki Okushi <huyuumi.dev@gmail.com>2021-01-27 04:43:35 +0900
committerGitHub <noreply@github.com>2021-01-27 04:43:35 +0900
commitd68570c78f698bd913bfc8dae33ebe81590457b7 (patch)
tree88ee596fd792ab6508e3aa01d4912e798d3be3d2 /src
parent24a1081a239927424ad8ad5b4500e26d83924e76 (diff)
parent8ddc1c83f2fe56c2087bd5ee743720ec607b76df (diff)
Rollup merge of #81407 - osa1:issue81098, r=estebank
Refine "remove semicolon" suggestion in trait selection

Don't suggest it if the last statement doesn't have a semicolon

Fixes #81098

See also #54771 for why this suggestion was added
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/suggestions/issue-81098.rs13
-rw-r--r--src/test/ui/suggestions/issue-81098.stderr23
2 files changed, 36 insertions, 0 deletions
diff --git a/src/test/ui/suggestions/issue-81098.rs b/src/test/ui/suggestions/issue-81098.rs
new file mode 100644
index 00000000000..a601b5866f4
--- /dev/null
+++ b/src/test/ui/suggestions/issue-81098.rs
@@ -0,0 +1,13 @@
+// Don't suggest removing a semicolon if the last statement isn't an expression with semicolon
+// (#81098)
+fn wat() -> impl core::fmt::Display { //~ ERROR: `()` doesn't implement `std::fmt::Display`
+    fn why() {}
+}
+
+// Do it if the last statement is an expression with semicolon
+// (#54771)
+fn ok() -> impl core::fmt::Display { //~ ERROR: `()` doesn't implement `std::fmt::Display`
+    1;
+}
+
+fn main() {}
diff --git a/src/test/ui/suggestions/issue-81098.stderr b/src/test/ui/suggestions/issue-81098.stderr
new file mode 100644
index 00000000000..2a72159e577
--- /dev/null
+++ b/src/test/ui/suggestions/issue-81098.stderr
@@ -0,0 +1,23 @@
+error[E0277]: `()` doesn't implement `std::fmt::Display`
+  --> $DIR/issue-81098.rs:3:13
+   |
+LL | fn wat() -> impl core::fmt::Display {
+   |             ^^^^^^^^^^^^^^^^^^^^^^^ `()` cannot be formatted with the default formatter
+   |
+   = help: the trait `std::fmt::Display` is not implemented for `()`
+   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
+
+error[E0277]: `()` doesn't implement `std::fmt::Display`
+  --> $DIR/issue-81098.rs:9:12
+   |
+LL | fn ok() -> impl core::fmt::Display {
+   |            ^^^^^^^^^^^^^^^^^^^^^^^ `()` cannot be formatted with the default formatter
+LL |     1;
+   |      - consider removing this semicolon
+   |
+   = help: the trait `std::fmt::Display` is not implemented for `()`
+   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.