Rollup merge of #104433 - TaKO8Ki:fix-104392, r=estebank

Fix `emit_unused_delims_expr` ICE

Fixes #104392
This commit is contained in:
Matthias Krüger 2022-11-17 22:33:18 +01:00 committed by GitHub
commit c9ccb0ba28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 9 deletions

View file

@ -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
}

View file

@ -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`
}

View file

@ -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