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 @@ -942,6 +942,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
err.span_label(block.span, "this empty block is missing a tail expression");
return;
};
// FIXME expr and stmt have the same span if expr comes from expansion
// cc: https://github.com/rust-lang/rust/pull/147416#discussion_r2499407523
if stmt.span.from_expansion() {
return;
}
let hir::StmtKind::Semi(tail_expr) = stmt.kind else {
return;
};
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/macros/macro-expansion-empty-span-147255.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//! Regression test for <https://github.com/rust-lang/rust/issues/147255>

fn main() {
let mut x = 4;
let x_str = {
format!("{}", x);
//()
};
println!("{}", x_str); //~ ERROR `()` doesn't implement `std::fmt::Display`
}
15 changes: 15 additions & 0 deletions tests/ui/macros/macro-expansion-empty-span-147255.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0277]: `()` doesn't implement `std::fmt::Display`
--> $DIR/macro-expansion-empty-span-147255.rs:9:20
|
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
= 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: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
Loading