Skip to content

Commit

Permalink
Rollup merge of #104433 - TaKO8Ki:fix-104392, r=estebank
Browse files Browse the repository at this point in the history
Fix `emit_unused_delims_expr` ICE

Fixes #104392
  • Loading branch information
matthiaskrgr committed Nov 17, 2022
2 parents 43dca24 + 1cf4132 commit c9ccb0b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
16 changes: 7 additions & 9 deletions compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,16 +533,14 @@ trait UnusedDelimLint {
right_pos: Option<BytePos>,
) {
let spans = match value.kind {
ast::ExprKind::Block(ref block, None) if block.stmts.len() > 0 => {
let start = block.stmts[0].span;
let end = block.stmts[block.stmts.len() - 1].span;
if let Some(start) = start.find_ancestor_inside(value.span)
&& let Some(end) = end.find_ancestor_inside(value.span)
ast::ExprKind::Block(ref block, None) if block.stmts.len() == 1 => {
if let StmtKind::Expr(expr) = &block.stmts[0].kind
&& let ExprKind::Err = expr.kind
{
Some((
value.span.with_hi(start.lo()),
value.span.with_lo(end.hi()),
))
return
}
if let Some(span) = block.stmts[0].span.find_ancestor_inside(value.span) {
Some((value.span.with_hi(span.lo()), value.span.with_lo(span.hi())))
} else {
None
}
Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/lint/issue-104392.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fn main() {
{ unsafe 92 } //~ ERROR expected `{`, found `92`
}

fn foo() {
{ mod 92 } //~ ERROR expected identifier, found `92`
}

fn bar() {
{ trait 92 } //~ ERROR expected identifier, found `92`
}
27 changes: 27 additions & 0 deletions src/test/ui/lint/issue-104392.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
error: expected `{`, found `92`
--> $DIR/issue-104392.rs:2:14
|
LL | { unsafe 92 }
| ------ ^^ expected `{`
| |
| while parsing this `unsafe` expression
|
help: try placing this code inside a block
|
LL | { unsafe { 92 } }
| + +

error: expected identifier, found `92`
--> $DIR/issue-104392.rs:6:11
|
LL | { mod 92 }
| ^^ expected identifier

error: expected identifier, found `92`
--> $DIR/issue-104392.rs:10:13
|
LL | { trait 92 }
| ^^ expected identifier

error: aborting due to 3 previous errors

0 comments on commit c9ccb0b

Please sign in to comment.