Skip to content

Commit

Permalink
Merge #37
Browse files Browse the repository at this point in the history
37: Remove support of if-let expressions from #[project] attribute r=taiki-e a=taiki-e

This has many limitations.

cc #36

Co-authored-by: Taiki Endo <[email protected]>
  • Loading branch information
bors[bot] and taiki-e committed Aug 10, 2019
2 parents 9d577e0 + af891b9 commit 68b694c
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 55 deletions.
11 changes: 0 additions & 11 deletions pin-project-internal/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ impl Replace for Local {
impl Replace for Expr {
fn replace(&mut self, register: &mut Register) {
match self {
Expr::If(expr) => expr.replace(register),
Expr::ForLoop(ExprForLoop { pat, .. }) => pat.replace(register),
Expr::Let(ExprLet { pats, .. }) => pats.replace(register),

Expand All @@ -73,16 +72,6 @@ impl Replace for Expr {
}
}

impl Replace for ExprIf {
fn replace(&mut self, register: &mut Register) {
self.cond.replace(register);

if let Some(Expr::If(expr)) = self.else_branch.as_mut().map(|(_, expr)| &mut **expr) {
expr.replace(register);
}
}
}

impl Replace for Punctuated<Pat, Or> {
fn replace(&mut self, register: &mut Register) {
self.iter_mut().for_each(|pat| pat.replace(register));
Expand Down
33 changes: 2 additions & 31 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
///
/// ## Examples
///
/// The following two syntaxes are supported.
///
/// ### `let` bindings
///
/// ```rust
Expand Down Expand Up @@ -212,37 +214,6 @@
/// }
/// }
/// ```
///
/// ### `if let` expressions
///
/// When used against `if let` expressions, the `#[project]` attribute records
/// the name of the structure destructed with the first `if let`. Destructing
/// different structures in the after second times will not generate wrong code.
///
/// ```rust
/// use pin_project::{project, pin_projectable};
/// # use std::pin::Pin;
///
/// #[pin_projectable]
/// enum Foo<A, B, C> {
/// Tuple(#[pin] A, B),
/// Struct { field: C },
/// Unit,
/// }
///
/// impl<A, B, C> Foo<A, B, C> {
/// #[project] // Nightly does not need a dummy attribute to the function.
/// fn baz(self: Pin<&mut Self>) {
/// #[project]
/// {
/// if let Foo::Tuple(x, y) = self.project() {
/// let _: Pin<&mut A> = x;
/// let _: &mut B = y;
/// }
/// }
/// }
/// }
/// ```
#[cfg(feature = "project_attr")]
#[doc(inline)]
pub use pin_project_internal::project;
Expand Down
13 changes: 0 additions & 13 deletions tests/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,4 @@ fn test_project_attr() {
}
Baz::None => {}
}

#[project]
{
if let Baz::Variant1(x, y) = baz {
let x: Pin<&mut i32> = x;
assert_eq!(*x, 1);

let y: &mut i32 = y;
assert_eq!(*y, 2);
} else if let Option::Some(_) = Some(1) {
// Check that don't replace different types by mistake
}
}
}

0 comments on commit 68b694c

Please sign in to comment.