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

Improve node upmapping into macro inputs #16235

Closed
Veykril opened this issue Jan 3, 2024 · 2 comments · Fixed by #17898
Closed

Improve node upmapping into macro inputs #16235

Veykril opened this issue Jan 3, 2024 · 2 comments · Fixed by #17898
Assignees
Labels
A-proc-macro proc macro C-enhancement Category: enhancement

Comments

@Veykril
Copy link
Member

Veykril commented Jan 3, 2024

Noticed in #16229

Taking async-trait as an example, given:

#[async_trait]
trait Advertisement {
    async fn run(&self);
}

fn f<T: Advertisement>(t: T) {
    t.run()
}

and the expansion of the attribute as:

trait Advertisement {
    #[must_use]
    #[allow(clippy::type_complexity, clippy::type_repetition_in_bounds)]
    fn run<'life0, 'async_trait>(
        &'life0 self,
    ) -> ::core::pin::Pin<
        Box<dyn ::core::future::Future<Output = ()> + ::core::marker::Send + 'async_trait>,
    >
    where
        'life0: 'async_trait,
        Self: 'async_trait;
}

When we are trying to upmap the run function node from the expansion, we will fail due to all the new tokens that have been added that have varying spans and more importantly a differing syntax context from the input name (differing syntax context is an immediate bail currently). Ideally we'd still map the signature out of this, the question is how.

@Veykril Veykril added A-proc-macro proc macro C-enhancement Category: enhancement labels Jan 3, 2024
@JakobDegen
Copy link

@Veykril any idea if changes to async_trait can bypass the issues here?

@Veykril
Copy link
Member Author

Veykril commented Jan 13, 2024

The attribute could accommodate for us here but that would be the wrong way to go about this. The attribute is written with good diagnostic output in mind (that's where spans are mainly relevant). We should be able to improve this on our side, it's just that the logic for that be fleshed out a bit as currently its just very simplistic. That is figure out which tokens we can ignore while upmapping, which ones are relevant etc

@Veykril Veykril self-assigned this Jan 31, 2024
bors added a commit that referenced this issue Mar 12, 2024
internal: Improve rooted upmapping

cc #16235
@bors bors closed this as completed in a84c3d4 Aug 22, 2024
lnicola pushed a commit to lnicola/rust that referenced this issue Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-proc-macro proc macro C-enhancement Category: enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants