forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#106519 - estebank:tail-unit, r=cjgillot
Detect bindings assigned blocks without tail expressions Fix rust-lang#44173.
- Loading branch information
Showing
6 changed files
with
285 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/test/ui/type/binding-assigned-block-without-tail-expression.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
struct S; | ||
fn main() { | ||
let x = { | ||
println!("foo"); | ||
42; | ||
}; | ||
let y = {}; | ||
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 | ||
} |
109 changes: 109 additions & 0 deletions
109
src/test/ui/type/binding-assigned-block-without-tail-expression.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
error[E0277]: `()` doesn't implement `std::fmt::Display` | ||
--> $DIR/binding-assigned-block-without-tail-expression.rs:14:20 | ||
| | ||
LL | 42; | ||
| - help: remove this semicolon | ||
... | ||
LL | println!("{}", x); | ||
| ^ `()` 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 | ||
= 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:15:20 | ||
| | ||
LL | let y = {}; | ||
| -- this empty block is missing a tail expression | ||
... | ||
LL | println!("{}", y); | ||
| ^ `()` 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 | ||
= 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:16:20 | ||
| | ||
LL | "hi"; | ||
| - help: remove this semicolon | ||
... | ||
LL | println!("{}", z); | ||
| ^ `()` 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 | ||
= 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:17:20 | ||
| | ||
LL | let s = { | ||
| _____________- | ||
LL | | S; | ||
LL | | }; | ||
| |_____- this block is missing a tail expression | ||
... | ||
LL | println!("{}", s); | ||
| ^ `()` 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 | ||
= 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:18:18 | ||
| | ||
LL | 42; | ||
| - help: remove this semicolon | ||
... | ||
LL | let _: i32 = x; | ||
| --- ^ expected `i32`, found `()` | ||
| | | ||
| expected due to this | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/binding-assigned-block-without-tail-expression.rs:19:18 | ||
| | ||
LL | let y = {}; | ||
| -- this empty block is missing a tail expression | ||
... | ||
LL | let _: i32 = y; | ||
| --- ^ expected `i32`, found `()` | ||
| | | ||
| expected due to this | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/binding-assigned-block-without-tail-expression.rs:20:18 | ||
| | ||
LL | let z = { | ||
| _____________- | ||
LL | | "hi"; | ||
LL | | }; | ||
| |_____- this block is missing a tail expression | ||
... | ||
LL | let _: i32 = z; | ||
| --- ^ expected `i32`, found `()` | ||
| | | ||
| expected due to this | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/binding-assigned-block-without-tail-expression.rs:21:18 | ||
| | ||
LL | let s = { | ||
| _____________- | ||
LL | | S; | ||
LL | | }; | ||
| |_____- this block is missing a tail expression | ||
... | ||
LL | let _: i32 = s; | ||
| --- ^ expected `i32`, found `()` | ||
| | | ||
| expected due to this | ||
|
||
error: aborting due to 8 previous errors | ||
|
||
Some errors have detailed explanations: E0277, E0308. | ||
For more information about an error, try `rustc --explain E0277`. |