Skip to content

Unit struct or const cannot be interpolated inside repetition #300

@dtolnay

Description

@dtolnay
use proc_macro2::{Ident, Span, TokenStream};
use quote::{ToTokens, quote};

struct Private;

impl ToTokens for Private {
    fn to_tokens(&self, tokens: &mut TokenStream) {
        Ident::new("private", Span::call_site()).to_tokens(tokens);
    }
}

fn main() {
    let _ = quote! {
        // Okay
        ... #Private ...
    };

    let iter = vec!['0', '1', '2'];
    let _ = quote! {
        // Fail
        #(#Private #iter)*
    };
}
error[E0530]: let bindings cannot shadow unit structs
  --> src/main.rs:21:12
   |
 4 | struct Private;
   | --------------- the unit struct `Private` is defined here
...
21 |         #(#Private #iter)*
   |            ^^^^^^^ cannot be named the same as a unit struct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions