Skip to content

Commit

Permalink
Merge #244
Browse files Browse the repository at this point in the history
244: Deprecate project* attributes r=taiki-e a=taiki-e

This deprecates `#[project]`, `#[project_ref]`, and `#[project_replace]` attributes in favor of the naming of projected type.

Closes #225


Co-authored-by: Taiki Endo <te316e89@gmail.com>
  • Loading branch information
bors[bot] and taiki-e authored Jun 13, 2020
2 parents 755673f + fda3011 commit 9e3996f
Show file tree
Hide file tree
Showing 22 changed files with 192 additions and 76 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,33 @@ This project adheres to [Semantic Versioning](https://semver.org).

## [Unreleased]

* [Deprecated `#[project]`, `#[project_ref]`, and `#[project_replace]` attributes due to some unfixable limitations.][244]

Consider naming the projected type by passing an argument with the same name as the method to the #[pin_project] attribute instead.

```rust
use pin_project::pin_project;
use std::pin::Pin;

#[pin_project(project = EnumProj)]
enum Enum<T> {
Variant(#[pin] T),
}

fn func<T>(x: Pin<&mut Enum<T>>) {
match x.project() {
EnumProj::Variant(y) => {
let _: Pin<&mut T> = y;
}
}
}
```

See [#225][225] for more details.

[225]: https://github.com/taiki-e/pin-project/pull/225
[244]: https://github.com/taiki-e/pin-project/pull/244

## [0.4.20] - 2020-06-07

* [You can now use project_replace argument without Replace argument.][243]
Expand Down
10 changes: 8 additions & 2 deletions pin-project-internal/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ fn main() {
None => return,
};

// Underscore const names stabilized in Rust 1.37:
// https://github.com/rust-lang/rust/pull/61347/
// Underscore const names requires Rust 1.37:
// https://github.com/rust-lang/rust/pull/61347
if minor >= 37 {
println!("cargo:rustc-cfg=underscore_consts");
}

// #[deprecated] on proc-macro requires Rust 1.40:
// https://github.com/rust-lang/rust/pull/65666
if minor >= 40 {
println!("cargo:rustc-cfg=deprecated_proc_macro");
}
}

fn rustc_minor_version() -> Option<u32> {
Expand Down
34 changes: 34 additions & 0 deletions pin-project-internal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ pub fn pinned_drop(args: TokenStream, input: TokenStream) -> TokenStream {
/// ## Examples
///
/// ```rust
/// # #![allow(deprecated)]
/// use pin_project::{pin_project, project};
/// use std::pin::Pin;
///
Expand Down Expand Up @@ -576,6 +577,7 @@ pub fn pinned_drop(args: TokenStream, input: TokenStream) -> TokenStream {
/// ## Examples
///
/// ```rust
/// # #![allow(deprecated)]
/// use pin_project::{pin_project, project};
/// use std::pin::Pin;
///
Expand Down Expand Up @@ -616,6 +618,7 @@ pub fn pinned_drop(args: TokenStream, input: TokenStream) -> TokenStream {
/// ## Examples
///
/// ```rust
/// # #![allow(deprecated)]
/// use pin_project::{pin_project, project};
/// use std::pin::Pin;
///
Expand Down Expand Up @@ -650,6 +653,7 @@ pub fn pinned_drop(args: TokenStream, input: TokenStream) -> TokenStream {
/// ## Examples
///
/// ```rust
/// # #![allow(deprecated)]
/// # mod dox {
/// use pin_project::pin_project;
///
Expand All @@ -676,6 +680,16 @@ pub fn pinned_drop(args: TokenStream, input: TokenStream) -> TokenStream {
/// }
/// # }
/// ```
#[cfg_attr(
deprecated_proc_macro,
deprecated(
since = "0.4.21",
note = "consider naming projected type by passing `project` \
argument to #[pin_project] attribute instead, see release note \
<https://github.com/taiki-e/pin-project/releases/tag/v0.4.21> \
for details"
)
)]
#[proc_macro_attribute]
pub fn project(args: TokenStream, input: TokenStream) -> TokenStream {
let input = syn::parse_macro_input!(input);
Expand All @@ -691,6 +705,16 @@ pub fn project(args: TokenStream, input: TokenStream) -> TokenStream {
/// See [`#[project]`][`project`] attribute for more details.
///
/// [`project`]: ./attr.project.html
#[cfg_attr(
deprecated_proc_macro,
deprecated(
since = "0.4.21",
note = "consider naming projected type by passing `project_ref` \
argument to #[pin_project] attribute instead, see release note \
<https://github.com/taiki-e/pin-project/releases/tag/v0.4.21> \
for details"
)
)]
#[proc_macro_attribute]
pub fn project_ref(args: TokenStream, input: TokenStream) -> TokenStream {
let input = syn::parse_macro_input!(input);
Expand All @@ -706,6 +730,16 @@ pub fn project_ref(args: TokenStream, input: TokenStream) -> TokenStream {
/// See [`#[project]`][`project`] attribute for more details.
///
/// [`project`]: ./attr.project.html
#[cfg_attr(
deprecated_proc_macro,
deprecated(
since = "0.4.21",
note = "consider naming projected type by passing `project_replace` \
argument to #[pin_project] attribute instead, see release note \
<https://github.com/taiki-e/pin-project/releases/tag/v0.4.21> \
for details"
)
)]
#[proc_macro_attribute]
pub fn project_replace(args: TokenStream, input: TokenStream) -> TokenStream {
let input = syn::parse_macro_input!(input);
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ pub use pin_project_internal::pin_project;
#[doc(inline)]
pub use pin_project_internal::pinned_drop;

#[allow(deprecated)]
#[doc(inline)]
pub use pin_project_internal::project;

#[allow(deprecated)]
#[doc(inline)]
pub use pin_project_internal::project_ref;

#[allow(deprecated)]
#[doc(inline)]
pub use pin_project_internal::project_replace;

Expand Down
1 change: 1 addition & 0 deletions tests/project.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![warn(rust_2018_idioms, single_use_lifetimes)]
#![allow(dead_code)]
#![allow(deprecated)]

// Ceurrently, `#[attr] if true {}` doesn't even *parse* on MSRV,
// which means that it will error even behind a `#[rustversion::since(..)]`
Expand Down
1 change: 1 addition & 0 deletions tests/project_ref.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![warn(rust_2018_idioms, single_use_lifetimes)]
#![allow(dead_code)]
#![allow(deprecated)]

use pin_project::{pin_project, project_ref};
use std::pin::Pin;
Expand Down
1 change: 1 addition & 0 deletions tests/project_replace.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![warn(rust_2018_idioms, single_use_lifetimes)]
#![allow(dead_code)]
#![allow(deprecated)]

use pin_project::{pin_project, project_replace};
use std::{marker::PhantomData, pin::Pin};
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/project/ambiguous-let.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(deprecated)]

use pin_project::{pin_project, project};

#[pin_project]
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/project/ambiguous-let.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: Both initializer expression and pattern are replaceable, you need to split the initializer expression into separate let bindings to avoid ambiguity
--> $DIR/ambiguous-let.rs:16:9
--> $DIR/ambiguous-let.rs:18:9
|
16 | let Struct(x) = match Pin::new(&mut foo).project() {
18 | let Struct(x) = match Pin::new(&mut foo).project() {
| ^^^^^^^^^
8 changes: 8 additions & 0 deletions tests/ui/project/deprecated.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![deny(deprecated)]

use pin_project::{project, project_ref, project_replace};

#[project]
#[project_ref]
#[project_replace]
fn main() {}
23 changes: 23 additions & 0 deletions tests/ui/project/deprecated.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
error: use of deprecated item 'project': consider naming projected type by passing `project` argument to #[pin_project] attribute instead, see release note <https://github.com/taiki-e/pin-project/releases/tag/v0.4.21> for details
--> $DIR/deprecated.rs:5:3
|
5 | #[project]
| ^^^^^^^
|
note: the lint level is defined here
--> $DIR/deprecated.rs:1:9
|
1 | #![deny(deprecated)]
| ^^^^^^^^^^

error: use of deprecated item 'project_ref': consider naming projected type by passing `project_ref` argument to #[pin_project] attribute instead, see release note <https://github.com/taiki-e/pin-project/releases/tag/v0.4.21> for details
--> $DIR/deprecated.rs:6:3
|
6 | #[project_ref]
| ^^^^^^^^^^^

error: use of deprecated item 'project_replace': consider naming projected type by passing `project_replace` argument to #[pin_project] attribute instead, see release note <https://github.com/taiki-e/pin-project/releases/tag/v0.4.21> for details
--> $DIR/deprecated.rs:7:3
|
7 | #[project_replace]
| ^^^^^^^^^^^^^^^
2 changes: 2 additions & 0 deletions tests/ui/project/invalid.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(deprecated)]

mod argument {
use pin_project::{pin_project, project};

Expand Down
Loading

0 comments on commit 9e3996f

Please sign in to comment.