Skip to content

Commit fda3011

Browse files
committed
Deprecate project* attributes
1 parent 755673f commit fda3011

22 files changed

Lines changed: 192 additions & 76 deletions

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,33 @@ This project adheres to [Semantic Versioning](https://semver.org).
66

77
## [Unreleased]
88

9+
* [Deprecated `#[project]`, `#[project_ref]`, and `#[project_replace]` attributes due to some unfixable limitations.][244]
10+
11+
Consider naming the projected type by passing an argument with the same name as the method to the #[pin_project] attribute instead.
12+
13+
```rust
14+
use pin_project::pin_project;
15+
use std::pin::Pin;
16+
17+
#[pin_project(project = EnumProj)]
18+
enum Enum<T> {
19+
Variant(#[pin] T),
20+
}
21+
22+
fn func<T>(x: Pin<&mut Enum<T>>) {
23+
match x.project() {
24+
EnumProj::Variant(y) => {
25+
let _: Pin<&mut T> = y;
26+
}
27+
}
28+
}
29+
```
30+
31+
See [#225][225] for more details.
32+
33+
[225]: https://github.com/taiki-e/pin-project/pull/225
34+
[244]: https://github.com/taiki-e/pin-project/pull/244
35+
936
## [0.4.20] - 2020-06-07
1037

1138
* [You can now use project_replace argument without Replace argument.][243]

pin-project-internal/build.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@ fn main() {
99
None => return,
1010
};
1111

12-
// Underscore const names stabilized in Rust 1.37:
13-
// https://github.com/rust-lang/rust/pull/61347/
12+
// Underscore const names requires Rust 1.37:
13+
// https://github.com/rust-lang/rust/pull/61347
1414
if minor >= 37 {
1515
println!("cargo:rustc-cfg=underscore_consts");
1616
}
17+
18+
// #[deprecated] on proc-macro requires Rust 1.40:
19+
// https://github.com/rust-lang/rust/pull/65666
20+
if minor >= 40 {
21+
println!("cargo:rustc-cfg=deprecated_proc_macro");
22+
}
1723
}
1824

1925
fn rustc_minor_version() -> Option<u32> {

pin-project-internal/src/lib.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ pub fn pinned_drop(args: TokenStream, input: TokenStream) -> TokenStream {
546546
/// ## Examples
547547
///
548548
/// ```rust
549+
/// # #![allow(deprecated)]
549550
/// use pin_project::{pin_project, project};
550551
/// use std::pin::Pin;
551552
///
@@ -576,6 +577,7 @@ pub fn pinned_drop(args: TokenStream, input: TokenStream) -> TokenStream {
576577
/// ## Examples
577578
///
578579
/// ```rust
580+
/// # #![allow(deprecated)]
579581
/// use pin_project::{pin_project, project};
580582
/// use std::pin::Pin;
581583
///
@@ -616,6 +618,7 @@ pub fn pinned_drop(args: TokenStream, input: TokenStream) -> TokenStream {
616618
/// ## Examples
617619
///
618620
/// ```rust
621+
/// # #![allow(deprecated)]
619622
/// use pin_project::{pin_project, project};
620623
/// use std::pin::Pin;
621624
///
@@ -650,6 +653,7 @@ pub fn pinned_drop(args: TokenStream, input: TokenStream) -> TokenStream {
650653
/// ## Examples
651654
///
652655
/// ```rust
656+
/// # #![allow(deprecated)]
653657
/// # mod dox {
654658
/// use pin_project::pin_project;
655659
///
@@ -676,6 +680,16 @@ pub fn pinned_drop(args: TokenStream, input: TokenStream) -> TokenStream {
676680
/// }
677681
/// # }
678682
/// ```
683+
#[cfg_attr(
684+
deprecated_proc_macro,
685+
deprecated(
686+
since = "0.4.21",
687+
note = "consider naming projected type by passing `project` \
688+
argument to #[pin_project] attribute instead, see release note \
689+
<https://github.com/taiki-e/pin-project/releases/tag/v0.4.21> \
690+
for details"
691+
)
692+
)]
679693
#[proc_macro_attribute]
680694
pub fn project(args: TokenStream, input: TokenStream) -> TokenStream {
681695
let input = syn::parse_macro_input!(input);
@@ -691,6 +705,16 @@ pub fn project(args: TokenStream, input: TokenStream) -> TokenStream {
691705
/// See [`#[project]`][`project`] attribute for more details.
692706
///
693707
/// [`project`]: ./attr.project.html
708+
#[cfg_attr(
709+
deprecated_proc_macro,
710+
deprecated(
711+
since = "0.4.21",
712+
note = "consider naming projected type by passing `project_ref` \
713+
argument to #[pin_project] attribute instead, see release note \
714+
<https://github.com/taiki-e/pin-project/releases/tag/v0.4.21> \
715+
for details"
716+
)
717+
)]
694718
#[proc_macro_attribute]
695719
pub fn project_ref(args: TokenStream, input: TokenStream) -> TokenStream {
696720
let input = syn::parse_macro_input!(input);
@@ -706,6 +730,16 @@ pub fn project_ref(args: TokenStream, input: TokenStream) -> TokenStream {
706730
/// See [`#[project]`][`project`] attribute for more details.
707731
///
708732
/// [`project`]: ./attr.project.html
733+
#[cfg_attr(
734+
deprecated_proc_macro,
735+
deprecated(
736+
since = "0.4.21",
737+
note = "consider naming projected type by passing `project_replace` \
738+
argument to #[pin_project] attribute instead, see release note \
739+
<https://github.com/taiki-e/pin-project/releases/tag/v0.4.21> \
740+
for details"
741+
)
742+
)]
709743
#[proc_macro_attribute]
710744
pub fn project_replace(args: TokenStream, input: TokenStream) -> TokenStream {
711745
let input = syn::parse_macro_input!(input);

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,15 @@ pub use pin_project_internal::pin_project;
5555
#[doc(inline)]
5656
pub use pin_project_internal::pinned_drop;
5757

58+
#[allow(deprecated)]
5859
#[doc(inline)]
5960
pub use pin_project_internal::project;
6061

62+
#[allow(deprecated)]
6163
#[doc(inline)]
6264
pub use pin_project_internal::project_ref;
6365

66+
#[allow(deprecated)]
6467
#[doc(inline)]
6568
pub use pin_project_internal::project_replace;
6669

tests/project.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![warn(rust_2018_idioms, single_use_lifetimes)]
22
#![allow(dead_code)]
3+
#![allow(deprecated)]
34

45
// Ceurrently, `#[attr] if true {}` doesn't even *parse* on MSRV,
56
// which means that it will error even behind a `#[rustversion::since(..)]`

tests/project_ref.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![warn(rust_2018_idioms, single_use_lifetimes)]
22
#![allow(dead_code)]
3+
#![allow(deprecated)]
34

45
use pin_project::{pin_project, project_ref};
56
use std::pin::Pin;

tests/project_replace.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![warn(rust_2018_idioms, single_use_lifetimes)]
22
#![allow(dead_code)]
3+
#![allow(deprecated)]
34

45
use pin_project::{pin_project, project_replace};
56
use std::{marker::PhantomData, pin::Pin};

tests/ui/project/ambiguous-let.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(deprecated)]
2+
13
use pin_project::{pin_project, project};
24

35
#[pin_project]
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: Both initializer expression and pattern are replaceable, you need to split the initializer expression into separate let bindings to avoid ambiguity
2-
--> $DIR/ambiguous-let.rs:16:9
2+
--> $DIR/ambiguous-let.rs:18:9
33
|
4-
16 | let Struct(x) = match Pin::new(&mut foo).project() {
4+
18 | let Struct(x) = match Pin::new(&mut foo).project() {
55
| ^^^^^^^^^

tests/ui/project/deprecated.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![deny(deprecated)]
2+
3+
use pin_project::{project, project_ref, project_replace};
4+
5+
#[project]
6+
#[project_ref]
7+
#[project_replace]
8+
fn main() {}

0 commit comments

Comments
 (0)