Skip to content

Commit a3cdbc4

Browse files
committed
Fix rebase and clippy tests
1 parent fc2298c commit a3cdbc4

File tree

21 files changed

+136
-184
lines changed

21 files changed

+136
-184
lines changed

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
130130
hir::AsyncGeneratorKind::Block,
131131
|this| this.with_new_scopes(|this| this.lower_block_expr(block)),
132132
),
133-
ExprKind::Await(ref expr) => self.lower_expr_await(e.span, expr),
133+
ExprKind::Await(ref expr) => {
134+
let span = if expr.span.hi() < e.span.hi() {
135+
expr.span.shrink_to_hi().with_hi(e.span.hi())
136+
} else {
137+
// this is a recovered `await expr`
138+
e.span
139+
};
140+
self.lower_expr_await(span, expr)
141+
}
134142
ExprKind::Closure(
135143
capture_clause,
136144
asyncness,
@@ -639,6 +647,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
639647
self.allow_gen_future.clone(),
640648
);
641649
let expr = self.lower_expr_mut(expr);
650+
let expr_hir_id = expr.hir_id;
642651

643652
let pinned_ident = Ident::with_dummy_span(sym::pinned);
644653
let (pinned_pat, pinned_pat_hid) =
@@ -665,19 +674,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
665674
span,
666675
hir::LangItem::PinNewUnchecked,
667676
arena_vec![self; ref_mut_pinned],
668-
Some(expr.hir_id),
677+
Some(expr_hir_id),
669678
);
670679
let get_context = self.expr_call_lang_item_fn_mut(
671680
gen_future_span,
672681
hir::LangItem::GetContext,
673682
arena_vec![self; task_context],
674-
Some(expr.hir_id),
683+
Some(expr_hir_id),
675684
);
676685
let call = self.expr_call_lang_item_fn(
677686
span,
678687
hir::LangItem::FuturePoll,
679688
arena_vec![self; new_unchecked, get_context],
680-
Some(expr.hir_id),
689+
Some(expr_hir_id),
681690
);
682691
self.arena.alloc(self.expr_unsafe(call))
683692
};
@@ -694,7 +703,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
694703
span,
695704
hir::LangItem::PollReady,
696705
ready_field,
697-
Some(expr.hir_id),
706+
Some(expr_hir_id),
698707
);
699708
let break_x = self.with_loop_scope(loop_node_id, move |this| {
700709
let expr_break =
@@ -710,7 +719,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
710719
span,
711720
hir::LangItem::PollPending,
712721
&[],
713-
Some(expr.hir_id),
722+
Some(expr_hir_id),
714723
);
715724
let empty_block = self.expr_block_empty(span);
716725
self.arm(pending_pat, empty_block)
@@ -731,7 +740,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
731740
let unit = self.expr_unit(span);
732741
let yield_expr = self.expr(
733742
span,
734-
hir::ExprKind::Yield(unit, hir::YieldSource::Await { expr: Some(expr.hir_id) }),
743+
hir::ExprKind::Yield(unit, hir::YieldSource::Await { expr: Some(expr_hir_id) }),
735744
ThinVec::new(),
736745
);
737746
let yield_expr = self.arena.alloc(yield_expr);
@@ -778,6 +787,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
778787
into_future_span,
779788
hir::LangItem::IntoFutureIntoFuture,
780789
arena_vec![self; expr],
790+
Some(expr_hir_id),
781791
);
782792

783793
// match <into_future_expr> {

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ impl<'a> Parser<'a> {
11461146
/// Assuming we have just parsed `.`, continue parsing into an expression.
11471147
fn parse_dot_suffix(&mut self, self_arg: P<Expr>, lo: Span) -> PResult<'a, P<Expr>> {
11481148
if self.token.uninterpolated_span().rust_2018() && self.eat_keyword(kw::Await) {
1149-
return Ok(self.mk_await_expr(self_arg));
1149+
return Ok(self.mk_await_expr(self_arg, lo));
11501150
}
11511151

11521152
let fn_span_lo = self.token.span;
@@ -2831,8 +2831,8 @@ impl<'a> Parser<'a> {
28312831
ExprKind::Call(f, args)
28322832
}
28332833

2834-
fn mk_await_expr(&mut self, self_arg: P<Expr>) -> P<Expr> {
2835-
let span = self.prev_token.span;
2834+
fn mk_await_expr(&mut self, self_arg: P<Expr>, lo: Span) -> P<Expr> {
2835+
let span = lo.to(self.prev_token.span);
28362836
let await_expr = self.mk_expr(span, ExprKind::Await(self_arg), AttrVec::new());
28372837
self.recover_from_await_method_call();
28382838
await_expr

compiler/rustc_passes/src/region.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,14 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
421421
// Mark this expr's scope and all parent scopes as containing `yield`.
422422
let mut scope = Scope { id: expr.hir_id.local_id, data: ScopeData::Node };
423423
loop {
424-
let data = YieldData {
425-
span: expr.span,
426-
expr_and_pat_count: visitor.expr_and_pat_count,
427-
source: *source,
424+
let span = match expr.kind {
425+
hir::ExprKind::Yield(expr, hir::YieldSource::Await { .. }) => {
426+
expr.span.shrink_to_hi().to(expr.span)
427+
}
428+
_ => expr.span,
428429
};
430+
let data =
431+
YieldData { span, expr_and_pat_count: visitor.expr_and_pat_count, source: *source };
429432
visitor.scope_tree.yield_in_scope.insert(scope, data);
430433
if visitor.pessimistic_yield {
431434
debug!("resolve_expr in pessimistic_yield - marking scope {:?} for fixup", scope);

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

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -886,46 +886,48 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
886886
) {
887887
let span = obligation.cause.span;
888888

889-
if let ObligationCauseCode::AwaitableExpr(hir_id) = obligation.cause.code {
890-
// FIXME: use `obligation.predicate.kind()...trait_ref.self_ty()` to see if we have `()`
891-
// and if not maybe suggest doing something else? If we kept the expression around we
892-
// could also check if it is an fn call (very likely) and suggest changing *that*, if
893-
// it is from the local crate.
894-
err.span_suggestion_verbose(
895-
span,
896-
"do not `.await` the expression",
897-
String::new(),
898-
Applicability::MachineApplicable,
899-
);
900-
// FIXME: account for associated `async fn`s.
889+
if let ObligationCauseCode::AwaitableExpr(hir_id) = obligation.cause.code.peel_derives() {
901890
let hir = self.tcx.hir();
902891
if let Some(node) = hir_id.and_then(|hir_id| hir.find(hir_id)) {
903-
if let hir::Node::Expr(hir::Expr {
904-
span, kind: hir::ExprKind::Call(base, _), ..
905-
}) = node
906-
{
907-
if let ty::PredicateKind::Trait(pred) =
908-
obligation.predicate.kind().skip_binder()
909-
{
910-
err.span_label(*span, &format!("this call returns `{}`", pred.self_ty()));
911-
}
912-
if let Some(typeck_results) =
913-
self.in_progress_typeck_results.map(|t| t.borrow())
914-
{
915-
let ty = typeck_results.expr_ty_adjusted(base);
916-
if let ty::FnDef(def_id, _substs) = ty.kind() {
917-
if let Some(hir::Node::Item(hir::Item { span, ident, .. })) =
918-
hir.get_if_local(*def_id)
919-
{
920-
err.span_suggestion_verbose(
921-
span.shrink_to_lo(),
922-
&format!(
923-
"alternatively, consider making `fn {}` asynchronous",
924-
ident
925-
),
926-
"async ".to_string(),
927-
Applicability::MaybeIncorrect,
928-
);
892+
if let hir::Node::Expr(expr) = node {
893+
// FIXME: use `obligation.predicate.kind()...trait_ref.self_ty()` to see if we have `()`
894+
// and if not maybe suggest doing something else? If we kept the expression around we
895+
// could also check if it is an fn call (very likely) and suggest changing *that*, if
896+
// it is from the local crate.
897+
err.span_suggestion_verbose(
898+
expr.span.shrink_to_hi().with_hi(span.hi()),
899+
"do not `.await` the expression",
900+
String::new(),
901+
Applicability::MachineApplicable,
902+
);
903+
// FIXME: account for associated `async fn`s.
904+
if let hir::Expr { span, kind: hir::ExprKind::Call(base, _), .. } = expr {
905+
if let ty::PredicateKind::Trait(pred) =
906+
obligation.predicate.kind().skip_binder()
907+
{
908+
err.span_label(
909+
*span,
910+
&format!("this call returns `{}`", pred.self_ty()),
911+
);
912+
}
913+
if let Some(typeck_results) =
914+
self.in_progress_typeck_results.map(|t| t.borrow())
915+
{
916+
let ty = typeck_results.expr_ty_adjusted(base);
917+
if let ty::FnDef(def_id, _substs) = ty.kind() {
918+
if let Some(hir::Node::Item(hir::Item { span, ident, .. })) =
919+
hir.get_if_local(*def_id)
920+
{
921+
err.span_suggestion_verbose(
922+
span.shrink_to_lo(),
923+
&format!(
924+
"alternatively, consider making `fn {}` asynchronous",
925+
ident
926+
),
927+
"async ".to_string(),
928+
Applicability::MaybeIncorrect,
929+
);
930+
}
929931
}
930932
}
931933
}

compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
816816
def_id,
817817
&substs,
818818
match lang_item {
819-
hir::LangItem::FuturePoll => ObligationCauseCode::AwaitableExpr(expr_hir_id),
819+
hir::LangItem::IntoFutureIntoFuture => {
820+
ObligationCauseCode::AwaitableExpr(expr_hir_id)
821+
}
820822
hir::LangItem::IteratorNext | hir::LangItem::IntoIterIntoIter => {
821823
ObligationCauseCode::ForLoopIterator
822824
}

src/test/ui/async-await/await-keyword/incorrect-syntax-suggestions.stderr

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -162,68 +162,68 @@ LL | let _ = (await bar())?;
162162
| ^^^^^^^^^^^ only allowed inside `async` functions and blocks
163163

164164
error[E0728]: `await` is only allowed inside `async` functions and blocks
165-
--> $DIR/incorrect-syntax-suggestions.rs:71:19
165+
--> $DIR/incorrect-syntax-suggestions.rs:71:18
166166
|
167167
LL | fn foo13() -> Result<(), ()> {
168168
| ----- this is not `async`
169169
LL | let _ = bar().await();
170-
| ^^^^^ only allowed inside `async` functions and blocks
170+
| ^^^^^^ only allowed inside `async` functions and blocks
171171

172172
error[E0728]: `await` is only allowed inside `async` functions and blocks
173-
--> $DIR/incorrect-syntax-suggestions.rs:76:19
173+
--> $DIR/incorrect-syntax-suggestions.rs:76:18
174174
|
175175
LL | fn foo14() -> Result<(), ()> {
176176
| ----- this is not `async`
177177
LL | let _ = bar().await()?;
178-
| ^^^^^ only allowed inside `async` functions and blocks
178+
| ^^^^^^ only allowed inside `async` functions and blocks
179179

180180
error[E0728]: `await` is only allowed inside `async` functions and blocks
181-
--> $DIR/incorrect-syntax-suggestions.rs:81:19
181+
--> $DIR/incorrect-syntax-suggestions.rs:81:18
182182
|
183183
LL | fn foo15() -> Result<(), ()> {
184184
| ----- this is not `async`
185185
LL | let _ = bar().await;
186-
| ^^^^^ only allowed inside `async` functions and blocks
186+
| ^^^^^^ only allowed inside `async` functions and blocks
187187

188188
error[E0728]: `await` is only allowed inside `async` functions and blocks
189-
--> $DIR/incorrect-syntax-suggestions.rs:85:19
189+
--> $DIR/incorrect-syntax-suggestions.rs:85:18
190190
|
191191
LL | fn foo16() -> Result<(), ()> {
192192
| ----- this is not `async`
193193
LL | let _ = bar().await?;
194-
| ^^^^^ only allowed inside `async` functions and blocks
194+
| ^^^^^^ only allowed inside `async` functions and blocks
195195

196196
error[E0728]: `await` is only allowed inside `async` functions and blocks
197-
--> $DIR/incorrect-syntax-suggestions.rs:90:23
197+
--> $DIR/incorrect-syntax-suggestions.rs:90:22
198198
|
199199
LL | fn foo() -> Result<(), ()> {
200200
| --- this is not `async`
201201
LL | let _ = bar().await?;
202-
| ^^^^^ only allowed inside `async` functions and blocks
202+
| ^^^^^^ only allowed inside `async` functions and blocks
203203

204204
error[E0728]: `await` is only allowed inside `async` functions and blocks
205-
--> $DIR/incorrect-syntax-suggestions.rs:97:23
205+
--> $DIR/incorrect-syntax-suggestions.rs:97:22
206206
|
207207
LL | let foo = || {
208208
| -- this is not `async`
209209
LL | let _ = bar().await?;
210-
| ^^^^^ only allowed inside `async` functions and blocks
210+
| ^^^^^^ only allowed inside `async` functions and blocks
211211

212212
error[E0728]: `await` is only allowed inside `async` functions and blocks
213-
--> $DIR/incorrect-syntax-suggestions.rs:113:17
213+
--> $DIR/incorrect-syntax-suggestions.rs:113:29
214214
|
215215
LL | fn foo() -> Result<(), ()> {
216216
| --- this is not `async`
217217
LL | let _ = await!(bar())?;
218-
| ^^^^^^^^^^^^^ only allowed inside `async` functions and blocks
218+
| ^ only allowed inside `async` functions and blocks
219219

220220
error[E0728]: `await` is only allowed inside `async` functions and blocks
221-
--> $DIR/incorrect-syntax-suggestions.rs:121:17
221+
--> $DIR/incorrect-syntax-suggestions.rs:121:29
222222
|
223223
LL | let foo = || {
224224
| -- this is not `async`
225225
LL | let _ = await!(bar())?;
226-
| ^^^^^^^^^^^^^ only allowed inside `async` functions and blocks
226+
| ^ only allowed inside `async` functions and blocks
227227

228228
error: aborting due to 33 previous errors
229229

src/test/ui/async-await/issue-70594.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ async fn fun() {
66
//~| error: `.await` is not allowed in a `const`
77
//~| error: `.await` is not allowed in a `const`
88
//~| error: `()` is not a future
9-
//~| error: `()` is not a future
109
}
1110

1211
fn main() {}
Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,23 @@
11
error[E0728]: `await` is only allowed inside `async` functions and blocks
2-
--> $DIR/issue-70594.rs:4:12
2+
--> $DIR/issue-70594.rs:4:11
33
|
44
LL | async fn fun() {
55
| --- this is not `async`
66
LL | [1; ().await];
7-
| ^^^^^ only allowed inside `async` functions and blocks
7+
| ^^^^^^ only allowed inside `async` functions and blocks
88

99
error[E0744]: `.await` is not allowed in a `const`
10-
--> $DIR/issue-70594.rs:4:12
10+
--> $DIR/issue-70594.rs:4:9
1111
|
1212
LL | [1; ().await];
13-
| ^^^^^
13+
| ^^^^^^^^
1414

1515
error[E0744]: `.await` is not allowed in a `const`
1616
--> $DIR/issue-70594.rs:4:11
1717
|
1818
LL | [1; ().await];
1919
| ^^^^^^
2020

21-
error[E0277]: `()` is not a future
22-
--> $DIR/issue-70594.rs:4:12
23-
|
24-
LL | [1; ().await];
25-
| ^^^^^ `()` is not a future
26-
|
27-
= help: the trait `Future` is not implemented for `()`
28-
= note: () must be a future or must implement `IntoFuture` to be awaited
29-
= note: required because of the requirements on the impl of `IntoFuture` for `()`
30-
3121
error[E0277]: `()` is not a future
3222
--> $DIR/issue-70594.rs:4:11
3323
|
@@ -36,13 +26,14 @@ LL | [1; ().await];
3626
|
3727
= help: the trait `Future` is not implemented for `()`
3828
= note: () must be a future or must implement `IntoFuture` to be awaited
29+
= note: required because of the requirements on the impl of `IntoFuture` for `()`
3930
help: do not `.await` the expression
4031
|
4132
LL - [1; ().await];
4233
LL + [1; ()];
4334
|
4435

45-
error: aborting due to 5 previous errors
36+
error: aborting due to 4 previous errors
4637

4738
Some errors have detailed explanations: E0277, E0728, E0744.
4839
For more information about an error, try `rustc --explain E0277`.

src/test/ui/async-await/issues/issue-51719.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0728]: `await` is only allowed inside `async` functions and blocks
2-
--> $DIR/issue-51719.rs:8:25
2+
--> $DIR/issue-51719.rs:8:24
33
|
44
LL | let _gen = || foo().await;
5-
| -- ^^^^^ only allowed inside `async` functions and blocks
5+
| -- ^^^^^^ only allowed inside `async` functions and blocks
66
| |
77
| this is not `async`
88

src/test/ui/async-await/issues/issue-51751.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0728]: `await` is only allowed inside `async` functions and blocks
2-
--> $DIR/issue-51751.rs:9:27
2+
--> $DIR/issue-51751.rs:9:26
33
|
44
LL | fn main() {
55
| ---- this is not `async`
66
LL | let result = inc(10000);
77
LL | let finished = result.await;
8-
| ^^^^^ only allowed inside `async` functions and blocks
8+
| ^^^^^^ only allowed inside `async` functions and blocks
99

1010
error: aborting due to previous error
1111

src/test/ui/async-await/issues/issue-62009-1.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ fn main() {
1212
(|_| 2333).await;
1313
//~^ ERROR `await` is only allowed inside `async` functions and blocks
1414
//~| ERROR is not a future
15-
//~| ERROR is not a future
1615
}

0 commit comments

Comments
 (0)