Skip to content

Commit

Permalink
Deprecate project* attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Jun 13, 2020
1 parent 755673f commit 67d1fea
Show file tree
Hide file tree
Showing 20 changed files with 138 additions and 76 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ This project adheres to [Semantic Versioning](https://semver.org).

## [Unreleased]

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

TODO: write example

## [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, 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, 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, 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() {
| ^^^^^^^^^
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
104 changes: 52 additions & 52 deletions tests/ui/project/invalid.stderr
Original file line number Diff line number Diff line change
@@ -1,155 +1,155 @@
error: unexpected token: ()
--> $DIR/invalid.rs:10:18
--> $DIR/invalid.rs:12:18
|
10 | #[project()] //~ ERROR unexpected token
12 | #[project()] //~ ERROR unexpected token
| ^^

error: unexpected token: (foo)
--> $DIR/invalid.rs:17:18
--> $DIR/invalid.rs:19:18
|
17 | #[project(foo)] //~ ERROR unexpected token
19 | #[project(foo)] //~ ERROR unexpected token
| ^^^^^

error: unexpected token: ()
--> $DIR/invalid.rs:24:18
--> $DIR/invalid.rs:26:18
|
24 | #[project()] //~ ERROR unexpected token
26 | #[project()] //~ ERROR unexpected token
| ^^

error: unexpected token: (foo)
--> $DIR/invalid.rs:33:18
--> $DIR/invalid.rs:35:18
|
33 | #[project(foo)] //~ ERROR unexpected token
35 | #[project(foo)] //~ ERROR unexpected token
| ^^^^^

error: unexpected token: foo
--> $DIR/invalid.rs:42:15
--> $DIR/invalid.rs:44:15
|
42 | #[project(foo)] //~ ERROR unexpected token
44 | #[project(foo)] //~ ERROR unexpected token
| ^^^

error: duplicate #[project] attribute
--> $DIR/invalid.rs:56:9
--> $DIR/invalid.rs:58:9
|
56 | #[project] //~ ERROR duplicate #[project] attribute
58 | #[project] //~ ERROR duplicate #[project] attribute
| ^^^^^^^^^^

error: duplicate #[project_ref] attribute
--> $DIR/invalid.rs:64:9
--> $DIR/invalid.rs:66:9
|
64 | #[project_ref] //~ ERROR duplicate #[project_ref] attribute
66 | #[project_ref] //~ ERROR duplicate #[project_ref] attribute
| ^^^^^^^^^^^^^^

error: duplicate #[project_replace] attribute
--> $DIR/invalid.rs:72:9
--> $DIR/invalid.rs:74:9
|
72 | #[project_replace] //~ ERROR duplicate #[project_replace] attribute
74 | #[project_replace] //~ ERROR duplicate #[project_replace] attribute
| ^^^^^^^^^^^^^^^^^^

error: attributes `project` and `project_ref` are mutually exclusive
--> $DIR/invalid.rs:80:9
--> $DIR/invalid.rs:82:9
|
80 | #[project_ref] //~ ERROR are mutually exclusive
82 | #[project_ref] //~ ERROR are mutually exclusive
| ^^^^^^^^^^^^^^

error: attributes `project` and `project_replace` are mutually exclusive
--> $DIR/invalid.rs:88:9
--> $DIR/invalid.rs:90:9
|
88 | #[project_replace] //~ ERROR are mutually exclusive
90 | #[project_replace] //~ ERROR are mutually exclusive
| ^^^^^^^^^^^^^^^^^^

error: attributes `project_ref` and `project_replace` are mutually exclusive
--> $DIR/invalid.rs:96:9
--> $DIR/invalid.rs:98:9
|
96 | #[project_replace] //~ ERROR are mutually exclusive
98 | #[project_replace] //~ ERROR are mutually exclusive
| ^^^^^^^^^^^^^^^^^^

error: attributes `project` and `project_ref` are mutually exclusive
--> $DIR/invalid.rs:104:9
--> $DIR/invalid.rs:106:9
|
104 | #[project_ref] //~ ERROR are mutually exclusive
106 | #[project_ref] //~ ERROR are mutually exclusive
| ^^^^^^^^^^^^^^

error: attributes `project` and `project_replace` are mutually exclusive
--> $DIR/invalid.rs:112:9
--> $DIR/invalid.rs:114:9
|
112 | #[project_replace] //~ ERROR are mutually exclusive
114 | #[project_replace] //~ ERROR are mutually exclusive
| ^^^^^^^^^^^^^^^^^^

error: attributes `project_ref` and `project_replace` are mutually exclusive
--> $DIR/invalid.rs:120:9
--> $DIR/invalid.rs:122:9
|
120 | #[project_replace] //~ ERROR are mutually exclusive
122 | #[project_replace] //~ ERROR are mutually exclusive
| ^^^^^^^^^^^^^^^^^^

error: attributes `project` and `project_ref` are mutually exclusive
--> $DIR/invalid.rs:128:9
--> $DIR/invalid.rs:130:9
|
128 | #[project_ref] //~ ERROR are mutually exclusive
130 | #[project_ref] //~ ERROR are mutually exclusive
| ^^^^^^^^^^^^^^

error: attributes `project` and `project_replace` are mutually exclusive
--> $DIR/invalid.rs:136:9
--> $DIR/invalid.rs:138:9
|
136 | #[project_replace] //~ ERROR are mutually exclusive
138 | #[project_replace] //~ ERROR are mutually exclusive
| ^^^^^^^^^^^^^^^^^^

error: attributes `project_ref` and `project_replace` are mutually exclusive
--> $DIR/invalid.rs:144:9
--> $DIR/invalid.rs:146:9
|
144 | #[project_replace] //~ ERROR are mutually exclusive
146 | #[project_replace] //~ ERROR are mutually exclusive
| ^^^^^^^^^^^^^^^^^^

error: duplicate #[project] attribute
--> $DIR/invalid.rs:149:5
--> $DIR/invalid.rs:151:5
|
149 | #[project] //~ ERROR duplicate #[project] attribute
151 | #[project] //~ ERROR duplicate #[project] attribute
| ^^^^^^^^^^

error: duplicate #[project_ref] attribute
--> $DIR/invalid.rs:153:5
--> $DIR/invalid.rs:155:5
|
153 | #[project_ref] //~ ERROR duplicate #[project_ref] attribute
155 | #[project_ref] //~ ERROR duplicate #[project_ref] attribute
| ^^^^^^^^^^^^^^

error: duplicate #[project_replace] attribute
--> $DIR/invalid.rs:157:5
--> $DIR/invalid.rs:159:5
|
157 | #[project_replace] //~ ERROR duplicate #[project_replace] attribute
159 | #[project_replace] //~ ERROR duplicate #[project_replace] attribute
| ^^^^^^^^^^^^^^^^^^

error: duplicate #[project] attribute
--> $DIR/invalid.rs:161:5
--> $DIR/invalid.rs:163:5
|
161 | #[project] //~ ERROR duplicate #[project] attribute
163 | #[project] //~ ERROR duplicate #[project] attribute
| ^^^^^^^^^^

error: duplicate #[project_ref] attribute
--> $DIR/invalid.rs:165:5
--> $DIR/invalid.rs:167:5
|
165 | #[project_ref] //~ ERROR duplicate #[project_ref] attribute
167 | #[project_ref] //~ ERROR duplicate #[project_ref] attribute
| ^^^^^^^^^^^^^^

error: duplicate #[project_replace] attribute
--> $DIR/invalid.rs:169:5
--> $DIR/invalid.rs:171:5
|
169 | #[project_replace] //~ ERROR duplicate #[project_replace] attribute
171 | #[project_replace] //~ ERROR duplicate #[project_replace] attribute
| ^^^^^^^^^^^^^^^^^^

error: duplicate #[project] attribute
--> $DIR/invalid.rs:177:9
--> $DIR/invalid.rs:179:9
|
177 | #[project] //~ ERROR duplicate #[project] attribute
179 | #[project] //~ ERROR duplicate #[project] attribute
| ^^^^^^^^^^

error: duplicate #[project_ref] attribute
--> $DIR/invalid.rs:181:9
--> $DIR/invalid.rs:183:9
|
181 | #[project_ref] //~ ERROR duplicate #[project_ref] attribute
183 | #[project_ref] //~ ERROR duplicate #[project_ref] attribute
| ^^^^^^^^^^^^^^

error: duplicate #[project_replace] attribute
--> $DIR/invalid.rs:185:9
--> $DIR/invalid.rs:187:9
|
185 | #[project_replace] //~ ERROR duplicate #[project_replace] attribute
187 | #[project_replace] //~ ERROR duplicate #[project_replace] attribute
| ^^^^^^^^^^^^^^^^^^
1 change: 1 addition & 0 deletions tests/ui/project/type-mismatch.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(deprecated)]
#![feature(proc_macro_hygiene, stmt_expr_attributes)]

use pin_project::{pin_project, project};
Expand Down
Loading

0 comments on commit 67d1fea

Please sign in to comment.