Skip to content

Commit

Permalink
Make tests pass on stable
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron1011 committed Mar 9, 2020
1 parent eb80d67 commit 1d5231e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 27 deletions.
37 changes: 10 additions & 27 deletions tests/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
#![warn(rust_2018_idioms, single_use_lifetimes)]
#![allow(dead_code)]

// This hack is needed until https://github.com/rust-lang/rust/pull/69201
// makes it way into stable.
// Ceurrently, `#[attr] if true {}` doesn't even *parse* on stable,
// which means that it will error even behind a `#[rustversion::nightly]`
//
// This trick makes sure that we don't even attempt to parse
// the `#[project] if let _` test on stable.
#[rustversion::nightly]
include!("project_if_attr.rs.in");

use pin_project::{pin_project, project};
use std::pin::Pin;

Expand Down Expand Up @@ -86,33 +96,6 @@ 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]
Expand Down
29 changes: 29 additions & 0 deletions tests/project_if_attr.rs.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// FIXME: Once https://github.com/rust-lang/rust/pull/69201 makes its
// way into stable, move this back into `project.rs

#[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!();
}
}

0 comments on commit 1d5231e

Please sign in to comment.