-
-
Notifications
You must be signed in to change notification settings - Fork 36
Closed
Labels
A-pin-projectionArea: #[pin_project]Area: #[pin_project]C-bugCategory: related to a bug.Category: related to a bug.I-unsoundA soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessA soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
Description
Given a proc-macro crate like this:
extern crate proc_macro;
use proc_macro::TokenStream;
#[proc_macro_attribute]
pub fn hidden_repr(attr: TokenStream, item: TokenStream) -> TokenStream {
format!("#[repr({})] {}", attr, item).parse().unwrap()
}
Using it along with pin-project
in a project can cause a value to be pinned in one location and dropped in another:
use core::pin::Pin;
use hidden_repr::hidden_repr;
use pin_project::pin_projectable;
#[derive(Debug)]
struct Foo(u16);
impl Foo {
fn foo(self: Pin<&mut Self>) {
println!("{:?} at {:p}", self, self);
}
}
impl Drop for Foo {
fn drop(&mut self) {
println!("{:?} dropped at {:p}", self, self);
}
}
#[pin_projectable]
#[hidden_repr(packed)]
struct Bar {
_bar: u8,
#[pin]
foo: Foo,
}
fn main() {
let mut bar = Box::pin(Bar { _bar: 0, foo: Foo(0) });
bar.as_mut().project().foo.foo();
}
output:
Foo(0) at 0x560220317a41
Foo(0) dropped at 0x7fff2b8510b6
(it appears proc-macro-attribute application order is not defined, so not guaranteed to reproduce, but this seems like the sane order for rustc to apply them in so it's likely to continue working).
Metadata
Metadata
Assignees
Labels
A-pin-projectionArea: #[pin_project]Area: #[pin_project]C-bugCategory: related to a bug.Category: related to a bug.I-unsoundA soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessA soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness