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

Repeat trait fn name collision #7

Open
Goncalerta opened this issue Feb 25, 2019 · 0 comments
Open

Repeat trait fn name collision #7

Goncalerta opened this issue Feb 25, 2019 · 0 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@Goncalerta
Copy link
Owner

Although __proc_macro__as_repeat is a very unique name, in theory it can collide if the struct being interpolated in a repetition also implements some function with that name.

Trying to solve this with the fully qualified syntax Repeat::__proc_macro__as_repeat(something), would raise a new issue.

While iterators have to be consumed to be used (transfer ownership), slices and ToTokens shouldn't (borrow reference). On the other hand, the macro must generate code that simultaneously can work in both situations. This means Repeat::__proc_macro__as_repeat(&something) couldn't be generated, otherwise iterators wouldn't work. On the other hand, using Repeat::__proc_macro__as_repeat(something), the compiler doesn't infer the reference for some reason (while something.__proc_macro__as_repeat() does), so slices and ToTokens wouldn't work directly.

The user would need to borrow the variables before passing them into the macro, which could get very annoying:

let a = vec!["a", "b", "c"];
let b = [5,6,7];
let c = 5;
let d = "a";
let e = X;

let a = &a;
let b = &b;
let c = &c;
let d = &d;
let e = &e;
let q = quote!{ #(#a #b #c #d #e)* };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant