Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CoercePointee doesn't tightly enforce the restriction to #[repr(transparent)]-only wrappers, if other proc-macros are involved #135206

Open
steffahn opened this issue Jan 7, 2025 · 0 comments
Labels
C-bug Category: This is a bug. F-derive_coerce_pointee Feature: RFC 3621's oft-renamed implementation T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@steffahn
Copy link
Member

steffahn commented Jan 7, 2025

Define a proc macro that strips the #[repr(transparent)].

#[proc_macro_attribute]
pub fn untransparent(_: TokenStream, item: TokenStream) -> TokenStream {
    let mut i = item.into_iter();
    drop(i.next());
    drop(i.next());
    i.collect()
}

use it

#![feature(derive_coerce_pointee)]
use std::marker::CoercePointee;
use:untransparent;

#[derive(CoercePointee)]
#[untransparent]
#[repr(transparent)]
struct Foo<T: ?Sized>(Box<T>);

compiles successfully, expands to

#![feature(prelude_import)]
#![feature(derive_coerce_pointee)]
#[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;
use std::marker::CoercePointee;
use::untransparent;
struct Foo<T: ?Sized>(Box<T>);
#[automatically_derived]
impl<
    T: ?Sized + ::core::marker::Unsize<__S>,
    __S: ?Sized,
> ::core::ops::DispatchFromDyn<Foo<__S>> for Foo<T> {}
#[automatically_derived]
impl<
    T: ?Sized + ::core::marker::Unsize<__S>,
    __S: ?Sized,
> ::core::ops::CoerceUnsized<Foo<__S>> for Foo<T> {}

As far as I understand the RFC and intent, the intended stabilization should only stabilize allowing these (CoerceUnsized & DispatchFromDyn impls) to be generated for #[repr(transparent)] types.

@rustbot label F-derive_coerce_pointee

@steffahn steffahn added the C-bug Category: This is a bug. label Jan 7, 2025
@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. F-derive_coerce_pointee Feature: RFC 3621's oft-renamed implementation labels Jan 7, 2025
@steffahn steffahn changed the title CoercePointee doesn't effectively enforce the restriction to #[repr(transparent)]-only wrappers CoercePointee doesn't tightly enforce the restriction to #[repr(transparent)]-only wrappers, if other proc-macros are involved Jan 7, 2025
@jieyouxu jieyouxu added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jan 7, 2025
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-derive_coerce_pointee Feature: RFC 3621's oft-renamed implementation T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants