Fix rebase and clippy tests

This commit is contained in:
Esteban Kuber 2021-11-16 22:06:25 +00:00
parent 8888d0d61e
commit b825b0fe63
21 changed files with 136 additions and 184 deletions

View file

@ -130,7 +130,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir::AsyncGeneratorKind::Block, hir::AsyncGeneratorKind::Block,
|this| this.with_new_scopes(|this| this.lower_block_expr(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( ExprKind::Closure(
capture_clause, capture_clause,
asyncness, asyncness,
@ -639,6 +647,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.allow_gen_future.clone(), self.allow_gen_future.clone(),
); );
let expr = self.lower_expr_mut(expr); 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_ident = Ident::with_dummy_span(sym::pinned);
let (pinned_pat, pinned_pat_hid) = let (pinned_pat, pinned_pat_hid) =
@ -665,19 +674,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
span, span,
hir::LangItem::PinNewUnchecked, hir::LangItem::PinNewUnchecked,
arena_vec![self; ref_mut_pinned], arena_vec![self; ref_mut_pinned],
Some(expr.hir_id), Some(expr_hir_id),
); );
let get_context = self.expr_call_lang_item_fn_mut( let get_context = self.expr_call_lang_item_fn_mut(
gen_future_span, gen_future_span,
hir::LangItem::GetContext, hir::LangItem::GetContext,
arena_vec![self; task_context], arena_vec![self; task_context],
Some(expr.hir_id), Some(expr_hir_id),
); );
let call = self.expr_call_lang_item_fn( let call = self.expr_call_lang_item_fn(
span, span,
hir::LangItem::FuturePoll, hir::LangItem::FuturePoll,
arena_vec![self; new_unchecked, get_context], arena_vec![self; new_unchecked, get_context],
Some(expr.hir_id), Some(expr_hir_id),
); );
self.arena.alloc(self.expr_unsafe(call)) self.arena.alloc(self.expr_unsafe(call))
}; };
@ -694,7 +703,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
span, span,
hir::LangItem::PollReady, hir::LangItem::PollReady,
ready_field, ready_field,
Some(expr.hir_id), Some(expr_hir_id),
); );
let break_x = self.with_loop_scope(loop_node_id, move |this| { let break_x = self.with_loop_scope(loop_node_id, move |this| {
let expr_break = let expr_break =
@ -710,7 +719,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
span, span,
hir::LangItem::PollPending, hir::LangItem::PollPending,
&[], &[],
Some(expr.hir_id), Some(expr_hir_id),
); );
let empty_block = self.expr_block_empty(span); let empty_block = self.expr_block_empty(span);
self.arm(pending_pat, empty_block) self.arm(pending_pat, empty_block)
@ -731,7 +740,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let unit = self.expr_unit(span); let unit = self.expr_unit(span);
let yield_expr = self.expr( let yield_expr = self.expr(
span, 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(), ThinVec::new(),
); );
let yield_expr = self.arena.alloc(yield_expr); let yield_expr = self.arena.alloc(yield_expr);
@ -778,6 +787,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
into_future_span, into_future_span,
hir::LangItem::IntoFutureIntoFuture, hir::LangItem::IntoFutureIntoFuture,
arena_vec![self; expr], arena_vec![self; expr],
Some(expr_hir_id),
); );
// match <into_future_expr> { // match <into_future_expr> {

View file

@ -1153,7 +1153,7 @@ impl<'a> Parser<'a> {
/// Assuming we have just parsed `.`, continue parsing into an expression. /// 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>> { 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) { 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; let fn_span_lo = self.token.span;
@ -2838,8 +2838,8 @@ impl<'a> Parser<'a> {
ExprKind::Call(f, args) ExprKind::Call(f, args)
} }
fn mk_await_expr(&mut self, self_arg: P<Expr>) -> P<Expr> { fn mk_await_expr(&mut self, self_arg: P<Expr>, lo: Span) -> P<Expr> {
let span = self.prev_token.span; let span = lo.to(self.prev_token.span);
let await_expr = self.mk_expr(span, ExprKind::Await(self_arg), AttrVec::new()); let await_expr = self.mk_expr(span, ExprKind::Await(self_arg), AttrVec::new());
self.recover_from_await_method_call(); self.recover_from_await_method_call();
await_expr await_expr

View file

@ -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`. // 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 }; let mut scope = Scope { id: expr.hir_id.local_id, data: ScopeData::Node };
loop { loop {
let data = YieldData { let span = match expr.kind {
span: expr.span, hir::ExprKind::Yield(expr, hir::YieldSource::Await { .. }) => {
expr_and_pat_count: visitor.expr_and_pat_count, expr.span.shrink_to_hi().to(expr.span)
source: *source, }
_ => 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); visitor.scope_tree.yield_in_scope.insert(scope, data);
if visitor.pessimistic_yield { if visitor.pessimistic_yield {
debug!("resolve_expr in pessimistic_yield - marking scope {:?} for fixup", scope); debug!("resolve_expr in pessimistic_yield - marking scope {:?} for fixup", scope);

View file

@ -886,46 +886,48 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
) { ) {
let span = obligation.cause.span; let span = obligation.cause.span;
if let ObligationCauseCode::AwaitableExpr(hir_id) = obligation.cause.code { if let ObligationCauseCode::AwaitableExpr(hir_id) = obligation.cause.code.peel_derives() {
// 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.
let hir = self.tcx.hir(); let hir = self.tcx.hir();
if let Some(node) = hir_id.and_then(|hir_id| hir.find(hir_id)) { if let Some(node) = hir_id.and_then(|hir_id| hir.find(hir_id)) {
if let hir::Node::Expr(hir::Expr { if let hir::Node::Expr(expr) = node {
span, kind: hir::ExprKind::Call(base, _), .. // FIXME: use `obligation.predicate.kind()...trait_ref.self_ty()` to see if we have `()`
}) = node // 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
if let ty::PredicateKind::Trait(pred) = // it is from the local crate.
obligation.predicate.kind().skip_binder() err.span_suggestion_verbose(
{ expr.span.shrink_to_hi().with_hi(span.hi()),
err.span_label(*span, &format!("this call returns `{}`", pred.self_ty())); "do not `.await` the expression",
} String::new(),
if let Some(typeck_results) = Applicability::MachineApplicable,
self.in_progress_typeck_results.map(|t| t.borrow()) );
{ // FIXME: account for associated `async fn`s.
let ty = typeck_results.expr_ty_adjusted(base); if let hir::Expr { span, kind: hir::ExprKind::Call(base, _), .. } = expr {
if let ty::FnDef(def_id, _substs) = ty.kind() { if let ty::PredicateKind::Trait(pred) =
if let Some(hir::Node::Item(hir::Item { span, ident, .. })) = obligation.predicate.kind().skip_binder()
hir.get_if_local(*def_id) {
{ err.span_label(
err.span_suggestion_verbose( *span,
span.shrink_to_lo(), &format!("this call returns `{}`", pred.self_ty()),
&format!( );
"alternatively, consider making `fn {}` asynchronous", }
ident if let Some(typeck_results) =
), self.in_progress_typeck_results.map(|t| t.borrow())
"async ".to_string(), {
Applicability::MaybeIncorrect, 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,
);
}
} }
} }
} }

View file

@ -810,7 +810,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
def_id, def_id,
&substs, &substs,
match lang_item { 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 => { hir::LangItem::IteratorNext | hir::LangItem::IntoIterIntoIter => {
ObligationCauseCode::ForLoopIterator ObligationCauseCode::ForLoopIterator
} }

View file

@ -162,68 +162,68 @@ 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 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<(), ()> { LL | fn foo13() -> Result<(), ()> {
| ----- this is not `async` | ----- this is not `async`
LL | let _ = bar().await(); 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 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<(), ()> { LL | fn foo14() -> Result<(), ()> {
| ----- this is not `async` | ----- this is not `async`
LL | let _ = bar().await()?; 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 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<(), ()> { LL | fn foo15() -> Result<(), ()> {
| ----- this is not `async` | ----- this is not `async`
LL | let _ = bar().await; 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 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<(), ()> { LL | fn foo16() -> Result<(), ()> {
| ----- this is not `async` | ----- this is not `async`
LL | let _ = bar().await?; 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 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<(), ()> { LL | fn foo() -> Result<(), ()> {
| --- this is not `async` | --- this is not `async`
LL | let _ = bar().await?; 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 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 = || { LL | let foo = || {
| -- this is not `async` | -- this is not `async`
LL | let _ = bar().await?; 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 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<(), ()> { LL | fn foo() -> Result<(), ()> {
| --- this is not `async` | --- this is not `async`
LL | let _ = await!(bar())?; 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 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 = || { LL | let foo = || {
| -- this is not `async` | -- this is not `async`
LL | let _ = await!(bar())?; 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 error: aborting due to 33 previous errors

View file

@ -6,7 +6,6 @@ async fn fun() {
//~| error: `.await` is not allowed in a `const` //~| error: `.await` is not allowed in a `const`
//~| 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
//~| error: `()` is not a future
} }
fn main() {} fn main() {}

View file

@ -1,16 +1,16 @@
error[E0728]: `await` is only allowed inside `async` functions and blocks 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() { LL | async fn fun() {
| --- this is not `async` | --- this is not `async`
LL | [1; ().await]; 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` error[E0744]: `.await` is not allowed in a `const`
--> $DIR/issue-70594.rs:4:12 --> $DIR/issue-70594.rs:4:9
| |
LL | [1; ().await]; LL | [1; ().await];
| ^^^^^ | ^^^^^^^^
error[E0744]: `.await` is not allowed in a `const` error[E0744]: `.await` is not allowed in a `const`
--> $DIR/issue-70594.rs:4:11 --> $DIR/issue-70594.rs:4:11
@ -18,16 +18,6 @@ error[E0744]: `.await` is not allowed in a `const`
LL | [1; ().await]; 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 error[E0277]: `()` is not a future
--> $DIR/issue-70594.rs:4:11 --> $DIR/issue-70594.rs:4:11
| |
@ -36,13 +26,14 @@ LL | [1; ().await];
| |
= help: the trait `Future` is not implemented for `()` = help: the trait `Future` is not implemented for `()`
= note: () must be a future or must implement `IntoFuture` to be awaited = 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 help: do not `.await` the expression
| |
LL - [1; ().await]; LL - [1; ().await];
LL + [1; ()]; LL + [1; ()];
| |
error: aborting due to 5 previous errors error: aborting due to 4 previous errors
Some errors have detailed explanations: E0277, E0728, E0744. Some errors have detailed explanations: E0277, E0728, E0744.
For more information about an error, try `rustc --explain E0277`. For more information about an error, try `rustc --explain E0277`.

View file

@ -1,8 +1,8 @@
error[E0728]: `await` is only allowed inside `async` functions and blocks 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; LL | let _gen = || foo().await;
| -- ^^^^^ only allowed inside `async` functions and blocks | -- ^^^^^^ only allowed inside `async` functions and blocks
| | | |
| this is not `async` | this is not `async`

View file

@ -1,11 +1,11 @@
error[E0728]: `await` is only allowed inside `async` functions and blocks 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() { LL | fn main() {
| ---- this is not `async` | ---- this is not `async`
LL | let result = inc(10000); LL | let result = inc(10000);
LL | let finished = result.await; 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 error: aborting due to previous error

View file

@ -12,5 +12,4 @@ fn main() {
(|_| 2333).await; (|_| 2333).await;
//~^ ERROR `await` is only allowed inside `async` functions and blocks //~^ ERROR `await` is only allowed inside `async` functions and blocks
//~| ERROR is not a future //~| ERROR is not a future
//~| ERROR is not a future
} }

View file

@ -1,38 +1,28 @@
error[E0728]: `await` is only allowed inside `async` functions and blocks error[E0728]: `await` is only allowed inside `async` functions and blocks
--> $DIR/issue-62009-1.rs:6:23 --> $DIR/issue-62009-1.rs:6:22
| |
LL | fn main() { LL | fn main() {
| ---- this is not `async` | ---- this is not `async`
LL | async { let (); }.await; LL | async { let (); }.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 error[E0728]: `await` is only allowed inside `async` functions and blocks
--> $DIR/issue-62009-1.rs:10:7 --> $DIR/issue-62009-1.rs:10:6
| |
LL | fn main() { LL | fn main() {
| ---- this is not `async` | ---- this is not `async`
... ...
LL | }.await; LL | }.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 error[E0728]: `await` is only allowed inside `async` functions and blocks
--> $DIR/issue-62009-1.rs:12:16 --> $DIR/issue-62009-1.rs:12:15
| |
LL | fn main() { LL | fn main() {
| ---- this is not `async` | ---- this is not `async`
... ...
LL | (|_| 2333).await; LL | (|_| 2333).await;
| ^^^^^ only allowed inside `async` functions and blocks | ^^^^^^ only allowed inside `async` functions and blocks
error[E0277]: `[closure@$DIR/issue-62009-1.rs:12:5: 12:15]` is not a future
--> $DIR/issue-62009-1.rs:12:16
|
LL | (|_| 2333).await;
| ^^^^^ `[closure@$DIR/issue-62009-1.rs:12:5: 12:15]` is not a future
|
= help: the trait `Future` is not implemented for `[closure@$DIR/issue-62009-1.rs:12:5: 12:15]`
= note: [closure@$DIR/issue-62009-1.rs:12:5: 12:15] must be a future or must implement `IntoFuture` to be awaited
= note: required because of the requirements on the impl of `IntoFuture` for `[closure@$DIR/issue-62009-1.rs:12:5: 12:15]`
error[E0277]: `[closure@$DIR/issue-62009-1.rs:12:5: 12:15]` is not a future error[E0277]: `[closure@$DIR/issue-62009-1.rs:12:5: 12:15]` is not a future
--> $DIR/issue-62009-1.rs:12:15 --> $DIR/issue-62009-1.rs:12:15
@ -42,13 +32,14 @@ LL | (|_| 2333).await;
| |
= help: the trait `Future` is not implemented for `[closure@$DIR/issue-62009-1.rs:12:5: 12:15]` = help: the trait `Future` is not implemented for `[closure@$DIR/issue-62009-1.rs:12:5: 12:15]`
= note: [closure@$DIR/issue-62009-1.rs:12:5: 12:15] must be a future or must implement `IntoFuture` to be awaited = note: [closure@$DIR/issue-62009-1.rs:12:5: 12:15] must be a future or must implement `IntoFuture` to be awaited
= note: required because of the requirements on the impl of `IntoFuture` for `[closure@$DIR/issue-62009-1.rs:12:5: 12:15]`
help: do not `.await` the expression help: do not `.await` the expression
| |
LL - (|_| 2333).await; LL - (|_| 2333).await;
LL + (|_| 2333); LL + (|_| 2333);
| |
error: aborting due to 5 previous errors error: aborting due to 4 previous errors
Some errors have detailed explanations: E0277, E0728. Some errors have detailed explanations: E0277, E0728.
For more information about an error, try `rustc --explain E0277`. For more information about an error, try `rustc --explain E0277`.

View file

@ -1,10 +1,10 @@
error[E0728]: `await` is only allowed inside `async` functions and blocks error[E0728]: `await` is only allowed inside `async` functions and blocks
--> $DIR/issue-62009-2.rs:8:23 --> $DIR/issue-62009-2.rs:8:22
| |
LL | fn main() { LL | fn main() {
| ---- this is not `async` | ---- this is not `async`
LL | (async || 2333)().await; LL | (async || 2333)().await;
| ^^^^^ only allowed inside `async` functions and blocks | ^^^^^^ only allowed inside `async` functions and blocks
error: aborting due to previous error error: aborting due to previous error

View file

@ -1,11 +1,11 @@
error[E0728]: `await` is only allowed inside `async` functions and blocks error[E0728]: `await` is only allowed inside `async` functions and blocks
--> $DIR/non-async-enclosing-span.rs:9:28 --> $DIR/non-async-enclosing-span.rs:9:27
| |
LL | fn main() { LL | fn main() {
| ---- this is not `async` | ---- this is not `async`
LL | let x = move || {}; LL | let x = move || {};
LL | let y = do_the_thing().await; LL | let y = do_the_thing().await;
| ^^^^^ only allowed inside `async` functions and blocks | ^^^^^^ only allowed inside `async` functions and blocks
error: aborting due to previous error error: aborting due to previous error

View file

@ -39,7 +39,7 @@ LL | dummy();
| + | +
error[E0308]: `if` and `else` have incompatible types error[E0308]: `if` and `else` have incompatible types
--> $DIR/suggest-missing-await.rs:35:17 --> $DIR/suggest-missing-await.rs:35:9
| |
LL | let _x = if true { LL | let _x = if true {
| ______________- | ______________-
@ -48,7 +48,7 @@ LL | | dummy()
LL | | LL | |
LL | | } else { LL | | } else {
LL | | dummy().await LL | | dummy().await
| | ^^^^^ expected opaque type, found `()` | | ^^^^^^^^^^^^^ expected opaque type, found `()`
LL | | LL | |
LL | | }; LL | | };
| |_____- `if` and `else` have incompatible types | |_____- `if` and `else` have incompatible types
@ -61,7 +61,7 @@ LL | dummy().await
| ++++++ | ++++++
error[E0308]: `match` arms have incompatible types error[E0308]: `match` arms have incompatible types
--> $DIR/suggest-missing-await.rs:45:22 --> $DIR/suggest-missing-await.rs:45:14
| |
LL | let _x = match 0usize { LL | let _x = match 0usize {
| ______________- | ______________-
@ -70,7 +70,7 @@ LL | | 0 => dummy(),
LL | | 1 => dummy(), LL | | 1 => dummy(),
| | ------- this is found to be of type `impl Future<Output = ()>` | | ------- this is found to be of type `impl Future<Output = ()>`
LL | | 2 => dummy().await, LL | | 2 => dummy().await,
| | ^^^^^ expected opaque type, found `()` | | ^^^^^^^^^^^^^ expected opaque type, found `()`
LL | | LL | |
LL | | }; LL | | };
| |_____- `match` arms have incompatible types | |_____- `match` arms have incompatible types

View file

@ -7,6 +7,8 @@ LL | boo().await;
| this call returns `()` | this call returns `()`
| |
= help: the trait `Future` is not implemented for `()` = 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 help: do not `.await` the expression
| |
LL - boo().await; LL - boo().await;

View file

@ -23,20 +23,6 @@ LL | for _ in HashMap::new().iter().cloned() {}
= note: required because of the requirements on the impl of `Iterator` for `Cloned<std::collections::hash_map::Iter<'_, _, _>>` = note: required because of the requirements on the impl of `Iterator` for `Cloned<std::collections::hash_map::Iter<'_, _, _>>`
= note: required because of the requirements on the impl of `IntoIterator` for `Cloned<std::collections::hash_map::Iter<'_, _, _>>` = note: required because of the requirements on the impl of `IntoIterator` for `Cloned<std::collections::hash_map::Iter<'_, _, _>>`
<<<<<<< HEAD
error: aborting due to 2 previous errors error: aborting due to 2 previous errors
=======
error[E0271]: type mismatch resolving `<std::collections::hash_map::Iter<'_, _, _> as Iterator>::Item == &_`
--> $DIR/issue-33941.rs:4:14
|
LL | for _ in HashMap::new().iter().cloned() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected tuple, found reference
|
= note: expected tuple `(&_, &_)`
found reference `&_`
= note: required because of the requirements on the impl of `Iterator` for `Cloned<std::collections::hash_map::Iter<'_, _, _>>`
error: aborting due to 3 previous errors
>>>>>>> 330b90f5fc1 (Remove yet more output from `for`-loop and `?` errors)
For more information about this error, try `rustc --explain E0271`. For more information about this error, try `rustc --explain E0271`.

View file

@ -73,7 +73,7 @@ fn contains_assign_expr<'tcx>(cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'tcx>) ->
seen seen
} }
#[derive(Debug)] #[derive(Debug, Clone)]
struct LocalAssign { struct LocalAssign {
lhs_id: HirId, lhs_id: HirId,
lhs_span: Span, lhs_span: Span,
@ -154,9 +154,14 @@ fn assignment_suggestions<'tcx>(
assignments.push(assign); assignments.push(assign);
} }
let suggestions = assignments let suggestions = assignments.clone()
.into_iter() .into_iter()
.map(|assignment| Some((assignment.span, snippet_opt(cx, assignment.rhs_span)?))) .map(|assignment| Some((assignment.span.until(assignment.rhs_span), String::new())))
.chain(
assignments
.into_iter()
.map(|assignment| Some((assignment.rhs_span.shrink_to_hi().with_hi(assignment.span.hi()), String::new())))
)
.collect::<Option<Vec<(Span, String)>>>()?; .collect::<Option<Vec<(Span, String)>>>()?;
let applicability = if suggestions.len() > 1 { let applicability = if suggestions.len() > 1 {

View file

@ -1,38 +0,0 @@
// run-rustfix
#![allow(unused, clippy::assign_op_pattern)]
fn main() {
let a = "zero";
let b = 1;
let c = 2;
let d: usize = 1;
let mut e = 1;
e = 2;
let f = match 1 {
1 => "three",
_ => return,
}; // has semi
let g: usize = if true {
5
} else {
panic!();
};
let h = format!("{}", e);
println!("{}", a);
}

View file

@ -1,5 +1,3 @@
// run-rustfix
#![allow(unused, clippy::assign_op_pattern)] #![allow(unused, clippy::assign_op_pattern)]
fn main() { fn main() {

View file

@ -1,5 +1,5 @@
error: unneeded late initalization error: unneeded late initalization
--> $DIR/needless_late_init_fixable.rs:6:5 --> $DIR/needless_late_init_fixable.rs:4:5
| |
LL | let a; LL | let a;
| ^^^^^^ | ^^^^^^
@ -11,7 +11,7 @@ LL | let a = "zero";
| ~~~~~ | ~~~~~
error: unneeded late initalization error: unneeded late initalization
--> $DIR/needless_late_init_fixable.rs:9:5 --> $DIR/needless_late_init_fixable.rs:7:5
| |
LL | let b; LL | let b;
| ^^^^^^ | ^^^^^^
@ -22,7 +22,7 @@ LL | let b = 1;
| ~~~~~ | ~~~~~
error: unneeded late initalization error: unneeded late initalization
--> $DIR/needless_late_init_fixable.rs:10:5 --> $DIR/needless_late_init_fixable.rs:8:5
| |
LL | let c; LL | let c;
| ^^^^^^ | ^^^^^^
@ -33,7 +33,7 @@ LL | let c = 2;
| ~~~~~ | ~~~~~
error: unneeded late initalization error: unneeded late initalization
--> $DIR/needless_late_init_fixable.rs:14:5 --> $DIR/needless_late_init_fixable.rs:12:5
| |
LL | let d: usize; LL | let d: usize;
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
@ -44,7 +44,7 @@ LL | let d: usize = 1;
| ~~~~~~~~~~~~ | ~~~~~~~~~~~~
error: unneeded late initalization error: unneeded late initalization
--> $DIR/needless_late_init_fixable.rs:17:5 --> $DIR/needless_late_init_fixable.rs:15:5
| |
LL | let mut e; LL | let mut e;
| ^^^^^^^^^^ | ^^^^^^^^^^
@ -55,7 +55,7 @@ LL | let mut e = 1;
| ~~~~~~~~~ | ~~~~~~~~~
error: unneeded late initalization error: unneeded late initalization
--> $DIR/needless_late_init_fixable.rs:21:5 --> $DIR/needless_late_init_fixable.rs:19:5
| |
LL | let f; LL | let f;
| ^^^^^^ | ^^^^^^
@ -66,11 +66,12 @@ LL | let f = match 1 {
| +++++++ | +++++++
help: remove the assignments from the `match` arms help: remove the assignments from the `match` arms
| |
LL | 1 => "three", LL - 1 => f = "three",
| ~~~~~~~ LL + 1 => "three",
|
error: unneeded late initalization error: unneeded late initalization
--> $DIR/needless_late_init_fixable.rs:27:5 --> $DIR/needless_late_init_fixable.rs:25:5
| |
LL | let g: usize; LL | let g: usize;
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
@ -81,15 +82,16 @@ LL | let g: usize = if true {
| ++++++++++++++ | ++++++++++++++
help: remove the assignments from the branches help: remove the assignments from the branches
| |
LL | 5 LL - g = 5;
| LL + 5
|
help: add a semicolon after the `if` expression help: add a semicolon after the `if` expression
| |
LL | }; LL | };
| + | +
error: unneeded late initalization error: unneeded late initalization
--> $DIR/needless_late_init_fixable.rs:34:5 --> $DIR/needless_late_init_fixable.rs:32:5
| |
LL | let h; LL | let h;
| ^^^^^^ | ^^^^^^