Skip to content

Commit 6b2725f

Browse files
authored
Preserve spans in macro invocations (#72)
1 parent e1373e4 commit 6b2725f

File tree

5 files changed

+27
-14
lines changed

5 files changed

+27
-14
lines changed

async-stream-impl/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,9 @@ fn replace_for_await(input: impl IntoIterator<Item = TokenTree>) -> TokenStream2
289289
}
290290
TokenTree::Group(group) => {
291291
let stream = replace_for_await(group.stream());
292-
tokens.push(Group::new(group.delimiter(), stream).into());
292+
let mut new_group = Group::new(group.delimiter(), stream);
293+
new_group.set_span(group.span());
294+
tokens.push(new_group.into());
293295
}
294296
_ => tokens.push(token),
295297
}

async-stream/tests/spans_preserved.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use async_stream::stream;
2+
use futures_util::pin_mut;
3+
use futures_util::stream::StreamExt;
4+
5+
#[tokio::test]
6+
async fn spans_preserved() {
7+
let s = stream! {
8+
assert_eq!(line!(), 8);
9+
};
10+
pin_mut!(s);
11+
12+
while s.next().await.is_some() {
13+
unreachable!();
14+
}
15+
}

async-stream/tests/try_stream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async fn multi_try() {
6666
fn test() -> impl Stream<Item = Result<i32, String>> {
6767
try_stream! {
6868
let a = Ok::<_, String>(Ok::<_, String>(123))??;
69-
for _ in (1..10) {
69+
for _ in 1..10 {
7070
yield a;
7171
}
7272
}

async-stream/tests/ui/yield_in_async.stderr

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,17 @@ error[E0727]: `async` generators are not yet supported
1212
6 | yield 123;
1313
| ^^^^^^^^^
1414

15-
error[E0271]: type mismatch resolving `<[static generator@$DIR/src/lib.rs:201:9: 201:67] as Generator<ResumeTy>>::Yield == ()`
16-
--> tests/ui/yield_in_async.rs:4:5
15+
error[E0271]: type mismatch resolving `<[static generator@$DIR/tests/ui/yield_in_async.rs:5:23: 7:10] as Generator<ResumeTy>>::Yield == ()`
16+
--> tests/ui/yield_in_async.rs:5:23
1717
|
18-
4 | / stream! {
19-
5 | | let f = async {
18+
5 | let f = async {
19+
| _______________________^
2020
6 | | yield 123;
2121
7 | | };
22-
8 | |
23-
9 | | let v = f.await;
24-
10 | | };
25-
| |_____^ expected `()`, found integer
22+
| |_________^ expected `()`, found integer
2623
|
2724
note: required by a bound in `from_generator`
2825
--> $RUST/core/src/future/mod.rs
2926
|
3027
| T: Generator<ResumeTy, Yield = ()>,
3128
| ^^^^^^^^^^ required by this bound in `from_generator`
32-
= note: this error originates in the macro `stream` (in Nightly builds, run with -Z macro-backtrace for more info)

async-stream/tests/ui/yield_in_closure.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ error[E0658]: yield syntax is experimental
66
|
77
= note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information
88

9-
error[E0277]: expected a `FnOnce<(&str,)>` closure, found `[generator@$DIR/src/lib.rs:201:9: 201:67]`
9+
error[E0277]: expected a `FnOnce<(&str,)>` closure, found `[generator@$DIR/tests/ui/yield_in_closure.rs:6:23: 9:14]`
1010
--> tests/ui/yield_in_closure.rs:6:14
1111
|
1212
6 | .and_then(|v| {
13-
| ^^^^^^^^ expected an `FnOnce<(&str,)>` closure, found `[generator@$DIR/src/lib.rs:201:9: 201:67]`
13+
| ^^^^^^^^ expected an `FnOnce<(&str,)>` closure, found `[generator@$DIR/tests/ui/yield_in_closure.rs:6:23: 9:14]`
1414
|
15-
= help: the trait `FnOnce<(&str,)>` is not implemented for `[generator@$DIR/src/lib.rs:201:9: 201:67]`
15+
= help: the trait `FnOnce<(&str,)>` is not implemented for `[generator@$DIR/tests/ui/yield_in_closure.rs:6:23: 9:14]`
1616
note: required by a bound in `Result::<T, E>::and_then`
1717
--> $RUST/core/src/result.rs
1818
|

0 commit comments

Comments
 (0)