Skip to content

Commit c9ccb0b

Browse files
authoredNov 17, 2022
Rollup merge of #104433 - TaKO8Ki:fix-104392, r=estebank
Fix `emit_unused_delims_expr` ICE Fixes #104392
2 parents 43dca24 + 1cf4132 commit c9ccb0b

File tree

3 files changed

+45
-9
lines changed

3 files changed

+45
-9
lines changed
 

‎compiler/rustc_lint/src/unused.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -533,16 +533,14 @@ trait UnusedDelimLint {
533533
right_pos: Option<BytePos>,
534534
) {
535535
let spans = match value.kind {
536-
ast::ExprKind::Block(ref block, None) if block.stmts.len() > 0 => {
537-
let start = block.stmts[0].span;
538-
let end = block.stmts[block.stmts.len() - 1].span;
539-
if let Some(start) = start.find_ancestor_inside(value.span)
540-
&& let Some(end) = end.find_ancestor_inside(value.span)
536+
ast::ExprKind::Block(ref block, None) if block.stmts.len() == 1 => {
537+
if let StmtKind::Expr(expr) = &block.stmts[0].kind
538+
&& let ExprKind::Err = expr.kind
541539
{
542-
Some((
543-
value.span.with_hi(start.lo()),
544-
value.span.with_lo(end.hi()),
545-
))
540+
return
541+
}
542+
if let Some(span) = block.stmts[0].span.find_ancestor_inside(value.span) {
543+
Some((value.span.with_hi(span.lo()), value.span.with_lo(span.hi())))
546544
} else {
547545
None
548546
}

‎src/test/ui/lint/issue-104392.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
fn main() {
2+
{ unsafe 92 } //~ ERROR expected `{`, found `92`
3+
}
4+
5+
fn foo() {
6+
{ mod 92 } //~ ERROR expected identifier, found `92`
7+
}
8+
9+
fn bar() {
10+
{ trait 92 } //~ ERROR expected identifier, found `92`
11+
}

‎src/test/ui/lint/issue-104392.stderr

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error: expected `{`, found `92`
2+
--> $DIR/issue-104392.rs:2:14
3+
|
4+
LL | { unsafe 92 }
5+
| ------ ^^ expected `{`
6+
| |
7+
| while parsing this `unsafe` expression
8+
|
9+
help: try placing this code inside a block
10+
|
11+
LL | { unsafe { 92 } }
12+
| + +
13+
14+
error: expected identifier, found `92`
15+
--> $DIR/issue-104392.rs:6:11
16+
|
17+
LL | { mod 92 }
18+
| ^^ expected identifier
19+
20+
error: expected identifier, found `92`
21+
--> $DIR/issue-104392.rs:10:13
22+
|
23+
LL | { trait 92 }
24+
| ^^ expected identifier
25+
26+
error: aborting due to 3 previous errors
27+

0 commit comments

Comments
 (0)
Please sign in to comment.