about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2023-01-06 02:43:16 +0000
committerEsteban Küber <esteban@kuber.com.ar>2023-01-06 02:43:16 +0000
commit1fa6ada9dd3a17fc8c99b6b559a2835946803d21 (patch)
tree5ab6b85dd8bc2a5e3978c24522b84820c36d5b4d /src
parent1983a627b37c98e6660dd74ea3a56ac157fc2777 (diff)
downloadrust-1fa6ada9dd3a17fc8c99b6b559a2835946803d21.tar.gz
rust-1fa6ada9dd3a17fc8c99b6b559a2835946803d21.zip
Detect bindings assigned blocks without tail expressions in trait errors
Address  #44173 for trait errors.
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/type/binding-assigned-block-without-tail-expression.rs6
-rw-r--r--src/test/ui/type/binding-assigned-block-without-tail-expression.stderr68
2 files changed, 65 insertions, 9 deletions
diff --git a/src/test/ui/type/binding-assigned-block-without-tail-expression.rs b/src/test/ui/type/binding-assigned-block-without-tail-expression.rs
index b5b23a9e672..09afd27a079 100644
--- a/src/test/ui/type/binding-assigned-block-without-tail-expression.rs
+++ b/src/test/ui/type/binding-assigned-block-without-tail-expression.rs
@@ -1,3 +1,4 @@
+struct S;
 fn main() {
     let x = {
         println!("foo");
@@ -7,10 +8,15 @@ fn main() {
     let z = {
         "hi";
     };
+    let s = {
+        S;
+    };
     println!("{}", x); //~ ERROR E0277
     println!("{}", y); //~ ERROR E0277
     println!("{}", z); //~ ERROR E0277
+    println!("{}", s); //~ ERROR E0277
     let _: i32 = x; //~ ERROR E0308
     let _: i32 = y; //~ ERROR E0308
     let _: i32 = z; //~ ERROR E0308
+    let _: i32 = s; //~ ERROR E0308
 }
diff --git a/src/test/ui/type/binding-assigned-block-without-tail-expression.stderr b/src/test/ui/type/binding-assigned-block-without-tail-expression.stderr
index 46300104b05..646c632517a 100644
--- a/src/test/ui/type/binding-assigned-block-without-tail-expression.stderr
+++ b/src/test/ui/type/binding-assigned-block-without-tail-expression.stderr
@@ -1,5 +1,5 @@
 error[E0277]: `()` doesn't implement `std::fmt::Display`
-  --> $DIR/binding-assigned-block-without-tail-expression.rs:10:20
+  --> $DIR/binding-assigned-block-without-tail-expression.rs:14:20
    |
 LL |     println!("{}", x);
    |                    ^ `()` cannot be formatted with the default formatter
@@ -7,19 +7,29 @@ LL |     println!("{}", x);
    = 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
    = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+help: remove this semicolon
+   |
+LL -         42;
+LL +         42
+   |
 
 error[E0277]: `()` doesn't implement `std::fmt::Display`
-  --> $DIR/binding-assigned-block-without-tail-expression.rs:11:20
+  --> $DIR/binding-assigned-block-without-tail-expression.rs:15:20
    |
 LL |     println!("{}", y);
    |                    ^ `()` cannot be formatted with the default formatter
    |
+help: this empty block is missing a tail expression
+  --> $DIR/binding-assigned-block-without-tail-expression.rs:7:13
+   |
+LL |     let y = {};
+   |             ^^
    = 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
    = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error[E0277]: `()` doesn't implement `std::fmt::Display`
-  --> $DIR/binding-assigned-block-without-tail-expression.rs:12:20
+  --> $DIR/binding-assigned-block-without-tail-expression.rs:16:20
    |
 LL |     println!("{}", z);
    |                    ^ `()` cannot be formatted with the default formatter
@@ -27,9 +37,32 @@ LL |     println!("{}", z);
    = 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
    = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+help: remove this semicolon
+   |
+LL -         "hi";
+LL +         "hi"
+   |
+
+error[E0277]: `()` doesn't implement `std::fmt::Display`
+  --> $DIR/binding-assigned-block-without-tail-expression.rs:17:20
+   |
+LL |     println!("{}", s);
+   |                    ^ `()` cannot be formatted with the default formatter
+   |
+help: this block is missing a tail expression
+  --> $DIR/binding-assigned-block-without-tail-expression.rs:11:13
+   |
+LL |       let s = {
+   |  _____________^
+LL | |         S;
+LL | |     };
+   | |_____^
+   = 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
+   = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error[E0308]: mismatched types
-  --> $DIR/binding-assigned-block-without-tail-expression.rs:13:18
+  --> $DIR/binding-assigned-block-without-tail-expression.rs:18:18
    |
 LL |     let _: i32 = x;
    |            ---   ^ expected `i32`, found `()`
@@ -43,7 +76,7 @@ LL +         42
    |
 
 error[E0308]: mismatched types
-  --> $DIR/binding-assigned-block-without-tail-expression.rs:14:18
+  --> $DIR/binding-assigned-block-without-tail-expression.rs:19:18
    |
 LL |     let _: i32 = y;
    |            ---   ^ expected `i32`, found `()`
@@ -51,13 +84,13 @@ LL |     let _: i32 = y;
    |            expected due to this
    |
 help: this empty block is missing a tail expression
-  --> $DIR/binding-assigned-block-without-tail-expression.rs:6:13
+  --> $DIR/binding-assigned-block-without-tail-expression.rs:7:13
    |
 LL |     let y = {};
    |             ^^
 
 error[E0308]: mismatched types
-  --> $DIR/binding-assigned-block-without-tail-expression.rs:15:18
+  --> $DIR/binding-assigned-block-without-tail-expression.rs:20:18
    |
 LL |     let _: i32 = z;
    |            ---   ^ expected `i32`, found `()`
@@ -65,7 +98,7 @@ LL |     let _: i32 = z;
    |            expected due to this
    |
 help: this block is missing a tail expression
-  --> $DIR/binding-assigned-block-without-tail-expression.rs:7:13
+  --> $DIR/binding-assigned-block-without-tail-expression.rs:8:13
    |
 LL |       let z = {
    |  _____________^
@@ -73,7 +106,24 @@ LL | |         "hi";
 LL | |     };
    | |_____^
 
-error: aborting due to 6 previous errors
+error[E0308]: mismatched types
+  --> $DIR/binding-assigned-block-without-tail-expression.rs:21:18
+   |
+LL |     let _: i32 = s;
+   |            ---   ^ expected `i32`, found `()`
+   |            |
+   |            expected due to this
+   |
+help: this block is missing a tail expression
+  --> $DIR/binding-assigned-block-without-tail-expression.rs:11:13
+   |
+LL |       let s = {
+   |  _____________^
+LL | |         S;
+LL | |     };
+   | |_____^
+
+error: aborting due to 8 previous errors
 
 Some errors have detailed explanations: E0277, E0308.
 For more information about an error, try `rustc --explain E0277`.