Skip to content

Commit

Permalink
Fix rebase and clippy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Dec 13, 2021
1 parent 8888d0d commit b825b0f
Show file tree
Hide file tree
Showing 21 changed files with 136 additions and 184 deletions.
24 changes: 17 additions & 7 deletions compiler/rustc_ast_lowering/src/expr.rs
Expand Up @@ -130,7 +130,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir::AsyncGeneratorKind::Block,
|this| this.with_new_scopes(|this| this.lower_block_expr(block)),
),
ExprKind::Await(ref expr) => self.lower_expr_await(e.span, expr),
ExprKind::Await(ref expr) => {
let span = if expr.span.hi() < e.span.hi() {
expr.span.shrink_to_hi().with_hi(e.span.hi())
} else {
// this is a recovered `await expr`
e.span
};
self.lower_expr_await(span, expr)
}
ExprKind::Closure(
capture_clause,
asyncness,
Expand Down Expand Up @@ -639,6 +647,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.allow_gen_future.clone(),
);
let expr = self.lower_expr_mut(expr);
let expr_hir_id = expr.hir_id;

let pinned_ident = Ident::with_dummy_span(sym::pinned);
let (pinned_pat, pinned_pat_hid) =
Expand All @@ -665,19 +674,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
span,
hir::LangItem::PinNewUnchecked,
arena_vec![self; ref_mut_pinned],
Some(expr.hir_id),
Some(expr_hir_id),
);
let get_context = self.expr_call_lang_item_fn_mut(
gen_future_span,
hir::LangItem::GetContext,
arena_vec![self; task_context],
Some(expr.hir_id),
Some(expr_hir_id),
);
let call = self.expr_call_lang_item_fn(
span,
hir::LangItem::FuturePoll,
arena_vec![self; new_unchecked, get_context],
Some(expr.hir_id),
Some(expr_hir_id),
);
self.arena.alloc(self.expr_unsafe(call))
};
Expand All @@ -694,7 +703,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
span,
hir::LangItem::PollReady,
ready_field,
Some(expr.hir_id),
Some(expr_hir_id),
);
let break_x = self.with_loop_scope(loop_node_id, move |this| {
let expr_break =
Expand All @@ -710,7 +719,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
span,
hir::LangItem::PollPending,
&[],
Some(expr.hir_id),
Some(expr_hir_id),
);
let empty_block = self.expr_block_empty(span);
self.arm(pending_pat, empty_block)
Expand All @@ -731,7 +740,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let unit = self.expr_unit(span);
let yield_expr = self.expr(
span,
hir::ExprKind::Yield(unit, hir::YieldSource::Await { expr: Some(expr.hir_id) }),
hir::ExprKind::Yield(unit, hir::YieldSource::Await { expr: Some(expr_hir_id) }),
ThinVec::new(),
);
let yield_expr = self.arena.alloc(yield_expr);
Expand Down Expand Up @@ -778,6 +787,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
into_future_span,
hir::LangItem::IntoFutureIntoFuture,
arena_vec![self; expr],
Some(expr_hir_id),
);

// match <into_future_expr> {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_parse/src/parser/expr.rs
Expand Up @@ -1153,7 +1153,7 @@ impl<'a> Parser<'a> {
/// Assuming we have just parsed `.`, continue parsing into an expression.
fn parse_dot_suffix(&mut self, self_arg: P<Expr>, lo: Span) -> PResult<'a, P<Expr>> {
if self.token.uninterpolated_span().rust_2018() && self.eat_keyword(kw::Await) {
return Ok(self.mk_await_expr(self_arg));
return Ok(self.mk_await_expr(self_arg, lo));
}

let fn_span_lo = self.token.span;
Expand Down Expand Up @@ -2838,8 +2838,8 @@ impl<'a> Parser<'a> {
ExprKind::Call(f, args)
}

fn mk_await_expr(&mut self, self_arg: P<Expr>) -> P<Expr> {
let span = self.prev_token.span;
fn mk_await_expr(&mut self, self_arg: P<Expr>, lo: Span) -> P<Expr> {
let span = lo.to(self.prev_token.span);
let await_expr = self.mk_expr(span, ExprKind::Await(self_arg), AttrVec::new());
self.recover_from_await_method_call();
await_expr
Expand Down
11 changes: 7 additions & 4 deletions compiler/rustc_passes/src/region.rs
Expand Up @@ -421,11 +421,14 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
// Mark this expr's scope and all parent scopes as containing `yield`.
let mut scope = Scope { id: expr.hir_id.local_id, data: ScopeData::Node };
loop {
let data = YieldData {
span: expr.span,
expr_and_pat_count: visitor.expr_and_pat_count,
source: *source,
let span = match expr.kind {
hir::ExprKind::Yield(expr, hir::YieldSource::Await { .. }) => {
expr.span.shrink_to_hi().to(expr.span)
}
_ => expr.span,
};
let data =
YieldData { span, expr_and_pat_count: visitor.expr_and_pat_count, source: *source };
visitor.scope_tree.yield_in_scope.insert(scope, data);
if visitor.pessimistic_yield {
debug!("resolve_expr in pessimistic_yield - marking scope {:?} for fixup", scope);
Expand Down
Expand Up @@ -886,46 +886,48 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
) {
let span = obligation.cause.span;

if let ObligationCauseCode::AwaitableExpr(hir_id) = obligation.cause.code {
// FIXME: use `obligation.predicate.kind()...trait_ref.self_ty()` to see if we have `()`
// and if not maybe suggest doing something else? If we kept the expression around we
// could also check if it is an fn call (very likely) and suggest changing *that*, if
// it is from the local crate.
err.span_suggestion_verbose(
span,
"do not `.await` the expression",
String::new(),
Applicability::MachineApplicable,
);
// FIXME: account for associated `async fn`s.
if let ObligationCauseCode::AwaitableExpr(hir_id) = obligation.cause.code.peel_derives() {
let hir = self.tcx.hir();
if let Some(node) = hir_id.and_then(|hir_id| hir.find(hir_id)) {
if let hir::Node::Expr(hir::Expr {
span, kind: hir::ExprKind::Call(base, _), ..
}) = node
{
if let ty::PredicateKind::Trait(pred) =
obligation.predicate.kind().skip_binder()
{
err.span_label(*span, &format!("this call returns `{}`", pred.self_ty()));
}
if let Some(typeck_results) =
self.in_progress_typeck_results.map(|t| t.borrow())
{
let ty = typeck_results.expr_ty_adjusted(base);
if let ty::FnDef(def_id, _substs) = ty.kind() {
if let Some(hir::Node::Item(hir::Item { span, ident, .. })) =
hir.get_if_local(*def_id)
{
err.span_suggestion_verbose(
span.shrink_to_lo(),
&format!(
"alternatively, consider making `fn {}` asynchronous",
ident
),
"async ".to_string(),
Applicability::MaybeIncorrect,
);
if let hir::Node::Expr(expr) = node {
// FIXME: use `obligation.predicate.kind()...trait_ref.self_ty()` to see if we have `()`
// and if not maybe suggest doing something else? If we kept the expression around we
// could also check if it is an fn call (very likely) and suggest changing *that*, if
// it is from the local crate.
err.span_suggestion_verbose(
expr.span.shrink_to_hi().with_hi(span.hi()),
"do not `.await` the expression",
String::new(),
Applicability::MachineApplicable,
);
// FIXME: account for associated `async fn`s.
if let hir::Expr { span, kind: hir::ExprKind::Call(base, _), .. } = expr {
if let ty::PredicateKind::Trait(pred) =
obligation.predicate.kind().skip_binder()
{
err.span_label(
*span,
&format!("this call returns `{}`", pred.self_ty()),
);
}
if let Some(typeck_results) =
self.in_progress_typeck_results.map(|t| t.borrow())
{
let ty = typeck_results.expr_ty_adjusted(base);
if let ty::FnDef(def_id, _substs) = ty.kind() {
if let Some(hir::Node::Item(hir::Item { span, ident, .. })) =
hir.get_if_local(*def_id)
{
err.span_suggestion_verbose(
span.shrink_to_lo(),
&format!(
"alternatively, consider making `fn {}` asynchronous",
ident
),
"async ".to_string(),
Applicability::MaybeIncorrect,
);
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs
Expand Up @@ -810,7 +810,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
def_id,
&substs,
match lang_item {
hir::LangItem::FuturePoll => ObligationCauseCode::AwaitableExpr(expr_hir_id),
hir::LangItem::IntoFutureIntoFuture => {
ObligationCauseCode::AwaitableExpr(expr_hir_id)
}
hir::LangItem::IteratorNext | hir::LangItem::IntoIterIntoIter => {
ObligationCauseCode::ForLoopIterator
}
Expand Down
Expand Up @@ -162,68 +162,68 @@ LL | let _ = (await bar())?;
| ^^^^^^^^^^^ only allowed inside `async` functions and blocks

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

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

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

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

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

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

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

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

error: aborting due to 33 previous errors

Expand Down
1 change: 0 additions & 1 deletion src/test/ui/async-await/issue-70594.rs
Expand Up @@ -6,7 +6,6 @@ async fn fun() {
//~| error: `.await` is not allowed in a `const`
//~| error: `.await` is not allowed in a `const`
//~| error: `()` is not a future
//~| error: `()` is not a future
}

fn main() {}
21 changes: 6 additions & 15 deletions src/test/ui/async-await/issue-70594.stderr
@@ -1,33 +1,23 @@
error[E0728]: `await` is only allowed inside `async` functions and blocks
--> $DIR/issue-70594.rs:4:12
--> $DIR/issue-70594.rs:4:11
|
LL | async fn fun() {
| --- this is not `async`
LL | [1; ().await];
| ^^^^^ only allowed inside `async` functions and blocks
| ^^^^^^ only allowed inside `async` functions and blocks

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

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

error[E0277]: `()` is not a future
--> $DIR/issue-70594.rs:4:12
|
LL | [1; ().await];
| ^^^^^ `()` is not a future
|
= help: the trait `Future` is not implemented for `()`
= note: () must be a future or must implement `IntoFuture` to be awaited
= note: required because of the requirements on the impl of `IntoFuture` for `()`

error[E0277]: `()` is not a future
--> $DIR/issue-70594.rs:4:11
|
Expand All @@ -36,13 +26,14 @@ LL | [1; ().await];
|
= help: the trait `Future` is not implemented for `()`
= note: () must be a future or must implement `IntoFuture` to be awaited
= note: required because of the requirements on the impl of `IntoFuture` for `()`
help: do not `.await` the expression
|
LL - [1; ().await];
LL + [1; ()];
|

error: aborting due to 5 previous errors
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0277, E0728, E0744.
For more information about an error, try `rustc --explain E0277`.
4 changes: 2 additions & 2 deletions src/test/ui/async-await/issues/issue-51719.stderr
@@ -1,8 +1,8 @@
error[E0728]: `await` is only allowed inside `async` functions and blocks
--> $DIR/issue-51719.rs:8:25
--> $DIR/issue-51719.rs:8:24
|
LL | let _gen = || foo().await;
| -- ^^^^^ only allowed inside `async` functions and blocks
| -- ^^^^^^ only allowed inside `async` functions and blocks
| |
| this is not `async`

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/async-await/issues/issue-51751.stderr
@@ -1,11 +1,11 @@
error[E0728]: `await` is only allowed inside `async` functions and blocks
--> $DIR/issue-51751.rs:9:27
--> $DIR/issue-51751.rs:9:26
|
LL | fn main() {
| ---- this is not `async`
LL | let result = inc(10000);
LL | let finished = result.await;
| ^^^^^ only allowed inside `async` functions and blocks
| ^^^^^^ only allowed inside `async` functions and blocks

error: aborting due to previous error

Expand Down
1 change: 0 additions & 1 deletion src/test/ui/async-await/issues/issue-62009-1.rs
Expand Up @@ -12,5 +12,4 @@ fn main() {
(|_| 2333).await;
//~^ ERROR `await` is only allowed inside `async` functions and blocks
//~| ERROR is not a future
//~| ERROR is not a future
}

0 comments on commit b825b0f

Please sign in to comment.