-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
181: Allow `#[project]` to be used on `if let` expressions r=taiki-e a=Aaron1011 This PR would work correctly, except for the fact that rust-lang/rust#68618 causes a compilation error to be emitted before we even have a chance to run. That issue is independent of the implementation of this PR, so this PR should start working automatically once the issue is resolved. Co-authored-by: Aaron Hill <aa1ronham@gmail.com>
- Loading branch information
Showing
3 changed files
with
75 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!(); | ||
} | ||
} | ||
|