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

Input to a #[proc_macro_derive] sees underlying derives on the item #85854

Closed
MihirLuthra opened this issue May 31, 2021 · 3 comments · Fixed by #86339
Closed

Input to a #[proc_macro_derive] sees underlying derives on the item #85854

MihirLuthra opened this issue May 31, 2021 · 3 comments · Fixed by #86339
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-bug Category: This is a bug.

Comments

@MihirLuthra
Copy link

MihirLuthra commented May 31, 2021

Input to #[proc_macro_derive] is able to see underlying derive attributes. This is not supposed to happen as per the change in version 1.17.0. A pull request was merged to remove this effect.

But version 1.52.0 onwards, underlying attributes are visible again to derive and this is not mentioned in RELEASES.md.

Code

Example code is available here: https://github.com/MihirLuthra/derive_issue_example

In the following code below, #[derive(Abc)] generates a function named print_all_attributes() which prints all derive attributes visible to it.

// main.rs

use abc_derive::Abc;

#[derive(Abc)]
#[derive(Debug, PartialEq, Eq)]
struct Xyz;

fn main() {
    print_all_attributes();
}

#[derive(Abc)] is defined as:

use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, DeriveInput};

#[proc_macro_derive(Abc)]
pub fn abc_derive(input: TokenStream) -> TokenStream {
    let derive_input = parse_macro_input!(input as DeriveInput);

    let attrs = &derive_input.attrs;

    (quote! {
        fn print_all_attributes() {
            println!(
                stringify!(#( #attrs )*)
            );
        }
    })
    .into()
}

Output on Version 1.51.0

Ouputs a blank line:


rustc --version --verbose:

rustc 1.51.0 (2fd73fabe 2021-03-23)
binary: rustc
commit-hash: 2fd73fabe469357a12c2c974c140f67e7cdd76d0
commit-date: 2021-03-23
host: x86_64-apple-darwin
release: 1.51.0
LLVM version: 11.0.1

Output on Version 1.52.1

#[derive(Debug, PartialEq, Eq)]

rustc --version --verbose:

rustc 1.52.1 (9bc8c42bb 2021-05-09)
binary: rustc
commit-hash: 9bc8c42bb2f19e745a63f3445f1ac248fb015e53
commit-date: 2021-05-09
host: x86_64-apple-darwin
release: 1.52.1
LLVM version: 12.0.0
@MihirLuthra MihirLuthra added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels May 31, 2021
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label May 31, 2021
@Aaron1011
Copy link
Member

cc @petrochenkov - I believe the new behavior is the one we want, since it makes derived 'just another attribute'. If so, we should document it more clearly in the release notes.

@Aaron1011
Copy link
Member

This change was made by #79078, but that PR was never tagged with relnotes for some reason.

@JohnTitor
Copy link
Member

Triage: dropping regression-untriaged and I-prioritize as this isn't an actual regression.

@JohnTitor JohnTitor added A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. regression-untriaged Untriaged performance or correctness regression. labels Jun 7, 2021
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jun 16, 2021
…s, r=petrochenkov

Mention rust-lang#79078 on compatibility notes of 1.52

Closes rust-lang#85854
r? `@petrochenkov`
@bors bors closed this as completed in 4e9dc76 Jun 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants