Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {

let new_obligation =
self.mk_trait_obligation_with_new_self_ty(obligation.param_env, trait_pred_and_self);
if self.predicate_must_hold_modulo_regions(&new_obligation) {
if !matches!(tail_expr.kind, hir::ExprKind::Err(_))
&& self.predicate_must_hold_modulo_regions(&new_obligation)
{
err.span_suggestion_short(
stmt.span.with_lo(tail_expr.span.hi()),
"remove this semicolon",
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/type/recover-from-semicolon-trailing-undefined.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@ compile-flags: -Znext-solver=globally

// Regression test for https://github.com/rust-lang/rust/issues/151610

fn main() {
let x_str = {
x!("{}", x);
//~^ ERROR cannot find macro `x` in this scope
};
println!("{}", x_str);
//~^ ERROR `()` doesn't implement `std::fmt::Display`
}
26 changes: 26 additions & 0 deletions tests/ui/type/recover-from-semicolon-trailing-undefined.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
error: cannot find macro `x` in this scope
--> $DIR/recover-from-semicolon-trailing-undefined.rs:7:9
|
LL | x!("{}", x);
| ^

error[E0277]: `()` doesn't implement `std::fmt::Display`
--> $DIR/recover-from-semicolon-trailing-undefined.rs:10:20
|
LL | let x_str = {
| _________________-
LL | | x!("{}", x);
LL | |
LL | | };
| |_____- this block is missing a tail expression
LL | println!("{}", x_str);
| -- ^^^^^ `()` cannot be formatted with the default formatter
| |
| required by this formatting parameter
|
= 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`.
Loading