Skip to content

Commit 1b3d8c1

Browse files
bors[bot]taiki-e
andauthored
Merge #326
326: Preserve `self` as segment of path r=taiki-e a=taiki-e Based on dtolnay/async-trait@6029cbf Co-authored-by: Taiki Endo <te316e89@gmail.com>
2 parents 0dca5be + fafa4e5 commit 1b3d8c1

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com
1010

1111
## [Unreleased]
1212

13+
- Fix compile error when using `self::` as prefix of path inside `#[pinned_drop]` impl.
14+
1315
## [1.0.6] - 2021-03-25
1416

1517
- [Suppress `clippy::semicolon_if_nothing_returned` lint in generated code.](https://github.com/taiki-e/pin-project/pull/318)

pin-project-internal/src/utils.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ impl<'a> ParseBufferExt<'a> for ParseBuffer<'a> {
176176
// visitors
177177

178178
// Replace `self`/`Self` with `__self`/`self_ty`.
179-
// Based on https://github.com/dtolnay/async-trait/blob/0.1.35/src/receiver.rs
179+
// Based on:
180+
// - https://github.com/dtolnay/async-trait/blob/0.1.35/src/receiver.rs
181+
// - https://github.com/dtolnay/async-trait/commit/6029cbf375c562ca98fa5748e9d950a8ff93b0e7
180182

181183
pub(crate) struct ReplaceReceiver<'a>(pub(crate) &'a TypePath);
182184

@@ -313,7 +315,6 @@ impl VisitMut for ReplaceReceiver<'_> {
313315
// `Self::method` -> `<Receiver>::method`
314316
fn visit_expr_path_mut(&mut self, expr: &mut ExprPath) {
315317
if expr.qself.is_none() {
316-
prepend_underscore_to_self(&mut expr.path.segments[0].ident);
317318
self.self_to_qself(&mut expr.qself, &mut expr.path);
318319
}
319320
visit_mut::visit_expr_path_mut(self, expr);
@@ -341,6 +342,16 @@ impl VisitMut for ReplaceReceiver<'_> {
341342
visit_mut::visit_pat_tuple_struct_mut(self, pat);
342343
}
343344

345+
fn visit_path_mut(&mut self, path: &mut Path) {
346+
if path.segments.len() == 1 {
347+
// Replace `self`, but not `self::function`.
348+
prepend_underscore_to_self(&mut path.segments[0].ident);
349+
}
350+
for segment in &mut path.segments {
351+
self.visit_path_arguments_mut(&mut segment.arguments);
352+
}
353+
}
354+
344355
fn visit_item_mut(&mut self, item: &mut Item) {
345356
match item {
346357
// Visit `macro_rules!` because locally defined macros can refer to `self`.

tests/pinned_drop.rs

+20
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,23 @@ fn inside_macro() {
262262

263263
mac!(1);
264264
}
265+
266+
pub mod self_path {
267+
use super::*;
268+
269+
#[pin_project(PinnedDrop)]
270+
pub struct S<T: Unpin>(T);
271+
272+
fn f() {}
273+
274+
#[pinned_drop]
275+
impl<T: Unpin> PinnedDrop for self::S<T> {
276+
fn drop(mut self: Pin<&mut Self>) {
277+
self::f();
278+
let _: self::S<()> = self::S(());
279+
let _: self::S<Pin<&mut Self>> = self::S(self.as_mut());
280+
let self::S(()) = self::S(());
281+
let self::S(&mut Self(_)) = self::S(&mut *self);
282+
}
283+
}
284+
}

0 commit comments

Comments
 (0)