From c60a4d9748600672f13f8a2e4c0e17c57c65e316 Mon Sep 17 00:00:00 2001 From: Alexander Glusker Date: Sat, 30 Mar 2024 02:49:01 +0300 Subject: [PATCH] review patch issue-6116 --- src/closures.rs | 10 +++------- tests/source/issue-6116/main2.rs | 8 ++++++++ tests/source/issue-6116/main3.rs | 8 ++++++++ tests/source/issue-6116/main4.rs | 7 +++++++ tests/target/issue-6116/main2.rs | 6 ++++++ tests/target/issue-6116/main3.rs | 3 +++ tests/target/issue-6116/main4.rs | 6 ++++++ 7 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 tests/source/issue-6116/main2.rs create mode 100644 tests/source/issue-6116/main3.rs create mode 100644 tests/source/issue-6116/main4.rs create mode 100644 tests/target/issue-6116/main2.rs create mode 100644 tests/target/issue-6116/main3.rs create mode 100644 tests/target/issue-6116/main4.rs diff --git a/src/closures.rs b/src/closures.rs index 0f5dbe23d1c..4af8aa95c52 100644 --- a/src/closures.rs +++ b/src/closures.rs @@ -1,3 +1,4 @@ +use rustc_ast::ast::StmtKind; use rustc_ast::{ast, ptr}; use rustc_span::Span; use thin_vec::thin_vec; @@ -119,13 +120,8 @@ fn get_inner_expr<'a>( expr } -fn iter_stmts_without_empty( - stmts: &thin_vec::ThinVec, -) -> impl Iterator { - stmts.iter().filter(|x| match x.kind { - crate::ast::StmtKind::Empty => false, - _ => true, - }) +fn iter_stmts_without_empty(stmts: &[ast::Stmt]) -> impl Iterator { + stmts.iter().filter(|x| !matches!(x.kind, StmtKind::Empty)) } // Figure out if a block is necessary. diff --git a/tests/source/issue-6116/main2.rs b/tests/source/issue-6116/main2.rs new file mode 100644 index 00000000000..1114fb1c461 --- /dev/null +++ b/tests/source/issue-6116/main2.rs @@ -0,0 +1,8 @@ +fn bar() -> fn(i32) -> i32 { + |a| { + ; + a; + b + } +} + diff --git a/tests/source/issue-6116/main3.rs b/tests/source/issue-6116/main3.rs new file mode 100644 index 00000000000..dbba9d96164 --- /dev/null +++ b/tests/source/issue-6116/main3.rs @@ -0,0 +1,8 @@ +fn foo() -> fn(i32) -> i32 { + |a| { + ; + ; + ;;;; + a + } +} diff --git a/tests/source/issue-6116/main4.rs b/tests/source/issue-6116/main4.rs new file mode 100644 index 00000000000..754aed66e72 --- /dev/null +++ b/tests/source/issue-6116/main4.rs @@ -0,0 +1,7 @@ +fn foo() -> fn(i32) -> i32 { + |a| { + /*comment before empty statement */; + a + } +} + diff --git a/tests/target/issue-6116/main2.rs b/tests/target/issue-6116/main2.rs new file mode 100644 index 00000000000..89679587ebc --- /dev/null +++ b/tests/target/issue-6116/main2.rs @@ -0,0 +1,6 @@ +fn bar() -> fn(i32) -> i32 { + |a| { + a; + b + } +} diff --git a/tests/target/issue-6116/main3.rs b/tests/target/issue-6116/main3.rs new file mode 100644 index 00000000000..dc0e48f1bfe --- /dev/null +++ b/tests/target/issue-6116/main3.rs @@ -0,0 +1,3 @@ +fn foo() -> fn(i32) -> i32 { + |a| a +} diff --git a/tests/target/issue-6116/main4.rs b/tests/target/issue-6116/main4.rs new file mode 100644 index 00000000000..e2eef35ef7b --- /dev/null +++ b/tests/target/issue-6116/main4.rs @@ -0,0 +1,6 @@ +fn foo() -> fn(i32) -> i32 { + |a| { + /*comment before empty statement */ + a + } +}