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

Syntax extensions (apparently) can not return multiple items. #16723

Closed
SimonSapin opened this issue Aug 24, 2014 · 1 comment
Closed

Syntax extensions (apparently) can not return multiple items. #16723

SimonSapin opened this issue Aug 24, 2014 · 1 comment
Labels
A-syntaxext Area: Syntax extensions E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@SimonSapin
Copy link
Contributor

Since #10649, macro_rules! macros can return multiple items. But there is no easy way to do so from a syntax extension: the result value must implement MacResult and the appropriate implementation appear to be MacItem, but it can only hold one item.

In servo/servo#3142, I worked around this with a new MacItems (plural) type:

struct MacItems {
    items: SmallVector<Gc<ast::Item>>
}

impl MacItems {
    fn new<I: Iterator<Gc<ast::Item>>>(items: I) -> Box<MacResult> {
        box MacItems { items: items.collect() } as Box<MacResult>
    }

impl MacResult for MacItems {
    fn make_items(&self) -> Option<SmallVector<Gc<ast::Item>>> {
        // FIXME: Implement Clone on SmallVector and use it instead of .iter().collect()
        Some(self.items.iter().collect())
    }
}

Perhaps this could be added to libsyntax or merged with MacItem.

@huonw
Copy link
Member

huonw commented Sep 5, 2014

Seems reasonable to just extend MacItem (tagging as easy since a perfectly good implementation is in the issue :) ).

@bors bors closed this as completed in 89b0944 Sep 20, 2014
matthiaskrgr pushed a commit to matthiaskrgr/rust that referenced this issue Mar 10, 2024
…ykril

fix: autocomplete constants inside format strings

Hi! This PR adds autocompletion for constants (including statics) inside format strings and closes rust-lang#16608.

I'm not sure about adding the `constants` field to the `CompletionContext`. It kinda makes sense, since it's in line with the `locals` field, and this way everything looks a bit cleaner, but at the same time does it really need to be there?

Anyway, let me know if anything should/can be changed. :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-syntaxext Area: Syntax extensions E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

2 participants