Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix emit_unused_delims_expr ICE #104433

Merged
merged 2 commits into from
Nov 18, 2022
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
16 changes: 7 additions & 9 deletions compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,16 +517,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 => {
Copy link
Member Author

@TaKO8Ki TaKO8Ki Nov 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the following comment, the block always has just one statement.

// emit a warning under the following conditions:
//
// - the block does not have a label
// - the block is not `unsafe`
// - the block contains exactly one expression (do not lint `{ expr; }`)
// - `followed_by_block` is true and the internal expr may contain a `{`
// - the block is not multiline (do not lint multiline match arms)

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