Skip to content

Commit df5439c

Browse files
committed
review comments
1 parent d94eaa5 commit df5439c

File tree

5 files changed

+37
-17
lines changed

5 files changed

+37
-17
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+20-8
Original file line numberDiff line numberDiff line change
@@ -1735,16 +1735,13 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
17351735
// | |
17361736
// LL | | foo(tx.clone());
17371737
// LL | | }).await;
1738-
// | | - ^^^^^^- value is later dropped here
1739-
// | | | |
1740-
// | |__________| await occurs here, with value maybe used later
1738+
// | | - ^^^^^^ await occurs here, with value maybe used later
1739+
// | |__________|
17411740
// | has type `closure` which is not `Send`
1741+
// note: value is later dropped here
1742+
// LL | | }).await;
1743+
// | | ^
17421744
//
1743-
// If available, use the scope span to annotate the drop location.
1744-
if let Some(scope_span) = scope_span {
1745-
let scope_span = source_map.end_point(scope_span);
1746-
span.push_span_label(scope_span, format!("{} is later dropped here", snippet));
1747-
}
17481745
span.push_span_label(
17491746
yield_span,
17501747
format!("{} occurs here, with {} maybe used later", await_or_yield, snippet),
@@ -1753,13 +1750,28 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
17531750
interior_span,
17541751
format!("has type `{}` which {}", target_ty, trait_explanation),
17551752
);
1753+
// If available, use the scope span to annotate the drop location.
1754+
let mut scope_note = None;
1755+
if let Some(scope_span) = scope_span {
1756+
let scope_span = source_map.end_point(scope_span);
1757+
1758+
let msg = format!("{} is later dropped here", snippet);
1759+
if source_map.is_multiline(yield_span.between(scope_span)) {
1760+
span.push_span_label(scope_span, msg);
1761+
} else {
1762+
scope_note = Some((scope_span, msg));
1763+
}
1764+
}
17561765
err.span_note(
17571766
span,
17581767
&format!(
17591768
"{} {} as this value is used across {}",
17601769
future_or_generator, trait_explanation, an_await_or_yield
17611770
),
17621771
);
1772+
if let Some((span, msg)) = scope_note {
1773+
err.span_note(span, &msg);
1774+
}
17631775
}
17641776
};
17651777
match interior_or_upvar_span {

src/test/ui/async-await/issue-70935-complex-spans.stderr

+7-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ LL | baz(|| async{
1212
| _____________-
1313
LL | | foo(tx.clone());
1414
LL | | }).await;
15-
| | - ^^^^^^- the value is later dropped here
16-
| | | |
17-
| |_________| await occurs here, with the value maybe used later
15+
| | - ^^^^^^ await occurs here, with the value maybe used later
16+
| |_________|
1817
| has type `[closure@$DIR/issue-70935-complex-spans.rs:13:13: 15:10]` which is not `Send`
18+
note: the value is later dropped here
19+
--> $DIR/issue-70935-complex-spans.rs:15:17
20+
|
21+
LL | }).await;
22+
| ^
1923

2024
error: aborting due to previous error
2125

src/test/ui/async-await/issues/issue-65436-raw-ptr-not-send.stderr

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ note: future is not `Send` as this value is used across an await
99
--> $DIR/issue-65436-raw-ptr-not-send.rs:14:35
1010
|
1111
LL | bar(Foo(std::ptr::null())).await;
12-
| ---------------- ^^^^^^- `std::ptr::null()` is later dropped here
13-
| | |
14-
| | await occurs here, with `std::ptr::null()` maybe used later
12+
| ---------------- ^^^^^^ await occurs here, with `std::ptr::null()` maybe used later
13+
| |
1514
| has type `*const u8` which is not `Send`
15+
note: `std::ptr::null()` is later dropped here
16+
--> $DIR/issue-65436-raw-ptr-not-send.rs:14:41
17+
|
18+
LL | bar(Foo(std::ptr::null())).await;
19+
| ^
1620
help: consider moving this into a `let` binding to create a shorter lived borrow
1721
--> $DIR/issue-65436-raw-ptr-not-send.rs:14:13
1822
|

src/test/ui/async-await/unnecessary-await.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// edition:2018
22

33
async fn foo () { }
4-
fn bar () -> impl std::future::Future { async {} }
5-
fn boo () {}
4+
fn bar() -> impl std::future::Future { async {} }
5+
fn boo() {}
66

77
async fn baz() -> std::io::Result<()> {
88
foo().await;

src/test/ui/async-await/unnecessary-await.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ LL + boo();
1616
|
1717
help: alternatively, consider making `fn boo` asynchronous
1818
|
19-
LL | async fn boo () {}
19+
LL | async fn boo() {}
2020
| +++++
2121

2222
error: aborting due to previous error

0 commit comments

Comments
 (0)