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

Do not skip visiting nested expressions #207

Merged
merged 1 commit into from
May 7, 2020
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
6 changes: 2 additions & 4 deletions pin-project-internal/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,7 @@ fn replace_item_fn(item: &mut ItemFn, mutability: Mutability) -> Result<()> {

fn visit_stmt(&mut self, node: &mut Stmt) -> Result<()> {
match node {
Stmt::Expr(expr) | Stmt::Semi(expr, _) => {
visit_mut::visit_expr_mut(self, expr);
self.visit_expr(expr)
}
Stmt::Expr(expr) | Stmt::Semi(expr, _) => self.visit_expr(expr),
Stmt::Local(local) => {
visit_mut::visit_local_mut(self, local);
if let Some(attr) = local.attrs.find_remove(self.name())? {
Expand All @@ -226,6 +223,7 @@ fn replace_item_fn(item: &mut ItemFn, mutability: Mutability) -> Result<()> {
}

fn visit_expr(&mut self, node: &mut Expr) -> Result<()> {
visit_mut::visit_expr_mut(self, node);
let attr = match node {
Expr::Match(expr) => expr.attrs.find_remove(self.name())?,
Expr::If(expr_if) => {
Expand Down
30 changes: 30 additions & 0 deletions tests/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,33 @@ fn non_stmt_expr_match() {
},
);
}

// https://github.com/taiki-e/pin-project/issues/206
#[test]
#[project]
fn issue_206() {
#[pin_project]
enum Enum<A> {
Variant(#[pin] A),
}

let mut x = Enum::Variant(1);
let x = Pin::new(&mut x).project();

Some({
#[project]
match &x {
Enum::Variant(_) => {}
}
});

loop {
let _ = {
#[project]
match &x {
Enum::Variant(_) => {}
}
};
break;
}
}