Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #91945

Merged
merged 32 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3f2a1c9
Use `OutputFilenames` to generate output file for `-Zllvm-time-trace`
tmiasko Dec 13, 2021
7f2f9c6
Iterator::cycle() — document empty iterator special case
xkr47 Dec 13, 2021
715c562
[ReviewFix] Linguistics
xkr47 Dec 13, 2021
7227a87
When `.await` is called on a non-`Future` expression, suggest removal
estebank Nov 16, 2021
75b6275
Reduce verbosity when calling `for`-loop on non-`Iterator` expression
estebank Nov 16, 2021
caf0c1b
Reduce verbosity for `?` on non-`Try` expressions
estebank Nov 16, 2021
81a3b90
Further silence `?` errors
estebank Nov 16, 2021
79749d6
Remove yet more output from `for`-loop and `?` errors
estebank Nov 16, 2021
4f2b1c0
Remove unnecessary argument
estebank Nov 16, 2021
d45e030
Fix mistake
estebank Nov 16, 2021
f640438
Keep info on pre-desugaring expression for better "incorrect `.await`…
estebank Nov 16, 2021
8888d0d
Fix clippy uses of QPath::LangItem
estebank Nov 16, 2021
b825b0f
Fix rebase and clippy tests
estebank Nov 16, 2021
9ecb141
tidy fix
estebank Nov 16, 2021
d59f74a
Simplify diagnostic logic
estebank Nov 17, 2021
64dea33
review comments
estebank Dec 2, 2021
1a7f2d5
review comment: change wording of suggestion
estebank Dec 10, 2021
64f88e8
fix clippy tests
estebank Dec 10, 2021
f2fc84f
fix coverage report test
estebank Dec 13, 2021
3011154
Revert "Set MACOSX_DEPLOYMENT_TARGET env var to default for linking i…
hkratz Dec 13, 2021
ae21dd0
Remove in_band_lifetimes
Patrick-Poitras Dec 14, 2021
a586e7d
Make suggestions from @jackh726; run fmt
Patrick-Poitras Dec 14, 2021
304ede6
Stabilize iter::zip.
Patrick-Poitras Dec 13, 2021
047adb5
Remove iter::zip feature gate from clippy
Patrick-Poitras Dec 14, 2021
d9dd360
Update cargo
ehuss Dec 14, 2021
272188e
Rollup merge of #90939 - estebank:wg-af-polish, r=tmandry
matthiaskrgr Dec 15, 2021
d6c802e
Rollup merge of #91859 - xkr47:patch-2, r=yaahc
matthiaskrgr Dec 15, 2021
ccfc22b
Rollup merge of #91868 - tmiasko:llvm-time-trace-out, r=oli-obk
matthiaskrgr Dec 15, 2021
2f270e4
Rollup merge of #91870 - rusticstuff:macosx_min_version_revert, r=Mar…
matthiaskrgr Dec 15, 2021
4e7497b
Rollup merge of #91881 - Patrick-Poitras:stabilize-iter-zip, r=scottmcm
matthiaskrgr Dec 15, 2021
6abad4c
Rollup merge of #91882 - Patrick-Poitras:remove-in-band-lifetimes-fro…
matthiaskrgr Dec 15, 2021
22fc403
Rollup merge of #91940 - ehuss:update-cargo, r=ehuss
matthiaskrgr Dec 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix rebase and clippy tests
  • Loading branch information
estebank committed Dec 13, 2021
commit b825b0fe6333ff08552aefa1fb25dfdc932b8bca
24 changes: 17 additions & 7 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
}
Loading