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

Ignoring empty statements in closures. #6128

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
review patch issue-6116
  • Loading branch information
Alexander Glusker authored and rscprof committed May 4, 2024
commit a09398fd58c31e1ec8d908333210a133ff0b4da1
10 changes: 3 additions & 7 deletions src/closures.rs
Original file line number Diff line number Diff line change
@@ -1,3 1,4 @@
use rustc_ast::ast::StmtKind;
rscprof marked this conversation as resolved.
Show resolved Hide resolved
use rustc_ast::{ast, ptr};
use rustc_span::Span;
use thin_vec::thin_vec;
Expand Down Expand Up @@ -119,13 120,8 @@ fn get_inner_expr<'a>(
expr
}

fn iter_stmts_without_empty(
stmts: &thin_vec::ThinVec<ast::Stmt>,
) -> impl Iterator<Item = &ast::Stmt> {
stmts.iter().filter(|x| match x.kind {
crate::ast::StmtKind::Empty => false,
_ => true,
})
fn iter_stmts_without_empty(stmts: &[ast::Stmt]) -> impl Iterator<Item = &ast::Stmt> {
stmts.iter().filter(|x| !matches!(x.kind, StmtKind::Empty))
}

// Figure out if a block is necessary.
Expand Down
8 changes: 8 additions & 0 deletions tests/source/issue-6116/main2.rs
Original file line number Diff line number Diff line change
@@ -0,0 1,8 @@
fn bar() -> fn(i32) -> i32 {
|a| {
;
a;
b
}
}

8 changes: 8 additions & 0 deletions tests/source/issue-6116/main3.rs
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this test case is a great addition! Also wanted to note that you can totally continue to add new files as test cases, though you might find it easier to place all of these test cases into a single file.

Copy link
Author

Choose a reason for hiding this comment

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

I don't know what I have to do)))

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm letting you know that instead of creating multiple test files you can add more than one test case to a single file.

for example:

fn foo() -> fn(i32) -> i32 {
    |a| {
        ;
        a
    }
}

fn bar() -> fn(i32) -> i32 {
    |a| {
        ;
        a;
        b
    }
}

fn foobar() -> fn(i32) -> i32 {
    |a| {
        ;
	;
	;;;;
        a
    }
}

fn baz() -> fn(i32) -> i32 {
    |a| {
        /*comment before empty statement */;
        a
    }
}

Original file line number Diff line number Diff line change
@@ -0,0 1,8 @@
fn foo() -> fn(i32) -> i32 {
|a| {
;
;
;;;;
a
}
}
7 changes: 7 additions & 0 deletions tests/source/issue-6116/main4.rs
Original file line number Diff line number Diff line change
@@ -0,0 1,7 @@
fn foo() -> fn(i32) -> i32 {
|a| {
/*comment before empty statement */;
a
}
}

6 changes: 6 additions & 0 deletions tests/target/issue-6116/main2.rs
Original file line number Diff line number Diff line change
@@ -0,0 1,6 @@
fn bar() -> fn(i32) -> i32 {
|a| {
a;
b
}
}
3 changes: 3 additions & 0 deletions tests/target/issue-6116/main3.rs
Original file line number Diff line number Diff line change
@@ -0,0 1,3 @@
fn foo() -> fn(i32) -> i32 {
|a| a
}
6 changes: 6 additions & 0 deletions tests/target/issue-6116/main4.rs
Original file line number Diff line number Diff line change
@@ -0,0 1,6 @@
fn foo() -> fn(i32) -> i32 {
|a| {
/*comment before empty statement */
a
}
}