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

Allow #[project] to be used on if let expressions #181

Merged
merged 6 commits into from
Mar 20, 2020
Merged
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
Add a test
Aaron1011 committed Mar 9, 2020

Verified

This commit was signed with the committer’s verified signature.
Aaron1011 Aaron Hill
commit eb80d67fdd40efbd7fa1752049a82e4f074b2c8a
27 changes: 27 additions & 0 deletions tests/project.rs
Original file line number Diff line number Diff line change
@@ -86,6 +86,33 @@ fn project_stmt_expr() {
assert_eq!(val, true);
}

#[rustversion::nightly]
#[test]
#[project]
fn project_if_let() {
#[pin_project]
enum Foo<A, B> {
Variant1(#[pin] A),
Variant2(u8),
Variant3 {
#[pin] field: B
}
}

let mut foo: Foo<bool, f32> = Foo::Variant1(true);
let foo = Pin::new(&mut foo).project();

#[project]
if let Foo::Variant1(a) = foo {
let a: Pin<&mut bool> = a;
assert_eq!(*a, true);
} else if let Foo::Variant2(_) = foo {
unreachable!();
} else if let Foo::Variant3 { .. } = foo {
unreachable!();
}
}

#[test]
fn project_impl() {
#[pin_project]