You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto merge of #70091 - Aaron1011:feature/more-tokens, r=<try>
[WIP] Store tokens alongside more AST expressions
See #43081 (comment)
This PR calls `collect_tokens` during the parsing of more AST nodes, and stores the captured tokens in the parsed AST structs. These tokens are then used in `nt_to_tokenstream` to avoid needing to stringify AST nodes.
Since this implementation completely ignores attributes, it will probably explode when given any kind of complicated input. This PR is intended mainly to estimate the performance impact of collecting and storing more tokens - a correct implementation will most likely have to do more work than this.
I've only implemented token collecting for a few types of expressions - the current expression parsing implementation makes it difficult to get the proper tokens for every expression.
Nevertheless, this is able to bootstrap libstd, and generate better error messages for a simple proc-macro example: (https://github.com/Aaron1011/for-await-test)
```rust
#![feature(stmt_expr_attributes, proc_macro_hygiene)]
use futures::stream::Stream;
use futures_async_stream::for_await;
async fn collect(stream: impl Stream<Item = i32>) -> Vec<i32> {
let mut vec = Vec::new();
#[for_await]
for value in stream.foo() {
vec.push(value);
}
vec
}
fn main() {
println!("Hello, world!");
}
```
on the latest nightly:
```
error[E0599]: no method named `foo` found for type parameter `impl Stream<Item = i32>` in the current scope
--> src/main.rs:7:5
|
7 | #[for_await]
| ^^^^^^^^^^^^ method not found in `impl Stream<Item = i32>`
error: aborting due to previous error
```
with this PR:
```
error[E0599]: no method named `foo` found for type parameter `impl Stream<Item = i32>` in the current scope
--> src/main.rs:8:25
|
8 | for value in stream.foo() {
| ^^^ method not found in `impl Stream<Item = i32>`
```
0 commit comments