Skip to content

Commit

Permalink
fix: zero-length span with trailing semi-colon in block
Browse files Browse the repository at this point in the history
  • Loading branch information
EliseZeroTwo committed Dec 14, 2023
1 parent 2ecba0f commit 3637fb4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3162,7 +3162,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
};
if self.can_eq(self.param_env, expected_ty, ty) {
err.span_suggestion_short(
stmt.span.with_lo(tail_expr.span.hi()),
stmt.span
.with_lo(tail_expr.span.hi())
.with_hi(tail_expr.span.hi() + rustc_span::BytePos(1)),
"remove this semicolon",
"",
Applicability::MachineApplicable,
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/typeck/issue-114251.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// compile-flags: -C debug-assertions

fn main() {
let kitty = {
assert!(());
//~^ ERROR: cannot apply unary operator `!` to type `()`
};

let cat: u8 = kitty;
//~^ ERROR: mismatched types
}
23 changes: 23 additions & 0 deletions tests/ui/typeck/issue-114251.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
error[E0600]: cannot apply unary operator `!` to type `()`
--> $DIR/issue-114251.rs:6:9
|
LL | assert!(());
| ^^^^^^^^^^^ cannot apply unary operator `!`
|
= note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
--> $DIR/issue-114251.rs:10:19
|
LL | assert!(());
| - help: remove this semicolon
...
LL | let cat: u8 = kitty;
| -- ^^^^^ expected `u8`, found `()`
| |
| expected due to this

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0308, E0600.
For more information about an error, try `rustc --explain E0308`.

0 comments on commit 3637fb4

Please sign in to comment.