Skip to content

Commit 6df63cc

Browse files
Replace def_site-&-privacy implementation with a stability-based one.
Since `decl_macro`s and/or `Span::def_site()` is deemed quite unstable, no public-facing macro that relies on it can hope to be, itself, stabilized. We circumvent the issue by no longer relying on field privacy for safety and, instead, relying on an unstable feature-gate to act as the gate keeper for non users of the macro (thanks to `allow_internal_unstable`). This is technically not correct (since a `nightly` user could technically enable the feature and cause unsoundness with it); or, in other words, this makes the feature-gate used to gate the access to the field be (technically unsound, and in practice) `unsafe`. Hence it having `unsafe` in its name. Back to the macro, we go back to `macro_rules!` / `mixed_site()`-span rules thanks to declaring the `decl_macro` as `semitransparent`, which is a hack to basically have `pub macro_rules!` Co-Authored-By: Mara Bos <[email protected]>
1 parent 54e443d commit 6df63cc

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

library/core/src/pin.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,9 @@ use crate::ops::{CoerceUnsized, Deref, DerefMut, DispatchFromDyn, Receiver};
406406
#[repr(transparent)]
407407
#[derive(Copy, Clone)]
408408
pub struct Pin<P> {
409-
pointer: P,
409+
#[unstable(feature = "unsafe_pin_internals", issue = "none")]
410+
#[doc(hidden)]
411+
pub pointer: P,
410412
}
411413

412414
// The following implementations aren't derived in order to avoid soundness
@@ -1074,6 +1076,8 @@ impl<P, U> DispatchFromDyn<Pin<U>> for Pin<P> where P: DispatchFromDyn<U> {}
10741076
///
10751077
/// [`Box::pin`]: ../../std/boxed/struct.Box.html#method.pin
10761078
#[unstable(feature = "pin_macro", issue = "93178")]
1079+
#[rustc_macro_transparency = "semitransparent"]
1080+
#[allow_internal_unstable(unsafe_pin_internals)]
10771081
pub macro pin($value:expr $(,)?) {
10781082
// This is `Pin::new_unchecked(&mut { $value })`, so, for starters, let's
10791083
// review such a hypothetical macro (that any user-code could define):
@@ -1145,8 +1149,5 @@ pub macro pin($value:expr $(,)?) {
11451149
//
11461150
// See https://doc.rust-lang.org/1.58.1/reference/destructors.html#temporary-lifetime-extension
11471151
// for more info.
1148-
//
1149-
// Finally, we don't hit problems _w.r.t._ the privacy of the `pointer` field, or the
1150-
// unqualified `Pin` name, thanks to `decl_macro`s being _fully_ hygienic (`def_site` hygiene).
1151-
Pin::<&mut _> { pointer: &mut { $value } }
1152+
$crate::pin::Pin::<&mut _> { pointer: &mut { $value } }
11521153
}

0 commit comments

Comments
 (0)