Don't call await a method
This commit is contained in:
parent
e6077fc1b8
commit
6c9249f689
8 changed files with 43 additions and 7 deletions
|
@ -203,6 +203,15 @@ borrowck_moved_due_to_method_call =
|
||||||
*[false] call
|
*[false] call
|
||||||
}
|
}
|
||||||
|
|
||||||
|
borrowck_moved_due_to_await =
|
||||||
|
{$place_name} {$is_partial ->
|
||||||
|
[true] partially moved
|
||||||
|
*[false] moved
|
||||||
|
} due to this {$is_loop_message ->
|
||||||
|
[true] await, in previous iteration of loop
|
||||||
|
*[false] await
|
||||||
|
}
|
||||||
|
|
||||||
borrowck_value_moved_here =
|
borrowck_value_moved_here =
|
||||||
value {$is_partial ->
|
value {$is_partial ->
|
||||||
[true] partially moved
|
[true] partially moved
|
||||||
|
|
|
@ -1084,6 +1084,14 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if let Some((CallDesugaringKind::Await, _)) = desugaring {
|
||||||
|
err.subdiagnostic(CaptureReasonLabel::Await {
|
||||||
|
fn_call_span,
|
||||||
|
place_name: &place_name,
|
||||||
|
is_partial,
|
||||||
|
is_loop_message,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
err.subdiagnostic(CaptureReasonLabel::MethodCall {
|
err.subdiagnostic(CaptureReasonLabel::MethodCall {
|
||||||
fn_call_span,
|
fn_call_span,
|
||||||
|
@ -1091,6 +1099,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
is_partial,
|
is_partial,
|
||||||
is_loop_message,
|
is_loop_message,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
// Erase and shadow everything that could be passed to the new infcx.
|
// Erase and shadow everything that could be passed to the new infcx.
|
||||||
let ty = moved_place.ty(self.body, tcx).ty;
|
let ty = moved_place.ty(self.body, tcx).ty;
|
||||||
|
|
||||||
|
|
|
@ -338,6 +338,14 @@ pub(crate) enum CaptureReasonLabel<'a> {
|
||||||
is_partial: bool,
|
is_partial: bool,
|
||||||
is_loop_message: bool,
|
is_loop_message: bool,
|
||||||
},
|
},
|
||||||
|
#[label(borrowck_moved_due_to_await)]
|
||||||
|
Await {
|
||||||
|
#[primary_span]
|
||||||
|
fn_call_span: Span,
|
||||||
|
place_name: &'a str,
|
||||||
|
is_partial: bool,
|
||||||
|
is_loop_message: bool,
|
||||||
|
},
|
||||||
#[label(borrowck_value_moved_here)]
|
#[label(borrowck_value_moved_here)]
|
||||||
MovedHere {
|
MovedHere {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
|
|
|
@ -184,6 +184,9 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
||||||
CallDesugaringKind::TryBlockFromOutput => {
|
CallDesugaringKind::TryBlockFromOutput => {
|
||||||
error!("`try` block cannot convert `{}` to the result in {}s")
|
error!("`try` block cannot convert `{}` to the result in {}s")
|
||||||
}
|
}
|
||||||
|
CallDesugaringKind::Await => {
|
||||||
|
error!("cannot convert `{}` into a future in {}s")
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
diag_trait(&mut err, self_ty, kind.trait_def_id(tcx));
|
diag_trait(&mut err, self_ty, kind.trait_def_id(tcx));
|
||||||
|
|
|
@ -19,6 +19,8 @@ pub enum CallDesugaringKind {
|
||||||
QuestionFromResidual,
|
QuestionFromResidual,
|
||||||
/// try { ..; x } calls type_of(x)::from_output(x)
|
/// try { ..; x } calls type_of(x)::from_output(x)
|
||||||
TryBlockFromOutput,
|
TryBlockFromOutput,
|
||||||
|
/// `.await` calls `IntoFuture::into_future`
|
||||||
|
Await,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CallDesugaringKind {
|
impl CallDesugaringKind {
|
||||||
|
@ -29,6 +31,7 @@ impl CallDesugaringKind {
|
||||||
tcx.require_lang_item(LangItem::Try, None)
|
tcx.require_lang_item(LangItem::Try, None)
|
||||||
}
|
}
|
||||||
Self::QuestionFromResidual => tcx.get_diagnostic_item(sym::FromResidual).unwrap(),
|
Self::QuestionFromResidual => tcx.get_diagnostic_item(sym::FromResidual).unwrap(),
|
||||||
|
Self::Await => tcx.get_diagnostic_item(sym::IntoFuture).unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,6 +132,8 @@ pub fn call_kind<'tcx>(
|
||||||
&& fn_call_span.desugaring_kind() == Some(DesugaringKind::TryBlock)
|
&& fn_call_span.desugaring_kind() == Some(DesugaringKind::TryBlock)
|
||||||
{
|
{
|
||||||
Some((CallDesugaringKind::TryBlockFromOutput, method_substs.type_at(0)))
|
Some((CallDesugaringKind::TryBlockFromOutput, method_substs.type_at(0)))
|
||||||
|
} else if fn_call_span.is_desugaring(DesugaringKind::Await) {
|
||||||
|
Some((CallDesugaringKind::Await, method_substs.type_at(0)))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
|
@ -208,6 +208,7 @@ symbols! {
|
||||||
Input,
|
Input,
|
||||||
Into,
|
Into,
|
||||||
IntoDiagnostic,
|
IntoDiagnostic,
|
||||||
|
IntoFuture,
|
||||||
IntoIterator,
|
IntoIterator,
|
||||||
IoRead,
|
IoRead,
|
||||||
IoWrite,
|
IoWrite,
|
||||||
|
|
|
@ -99,6 +99,7 @@ use crate::future::Future;
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "into_future", since = "1.64.0")]
|
#[stable(feature = "into_future", since = "1.64.0")]
|
||||||
|
#[rustc_diagnostic_item = "IntoFuture"]
|
||||||
pub trait IntoFuture {
|
pub trait IntoFuture {
|
||||||
/// The output that the future will produce on completion.
|
/// The output that the future will produce on completion.
|
||||||
#[stable(feature = "into_future", since = "1.64.0")]
|
#[stable(feature = "into_future", since = "1.64.0")]
|
||||||
|
|
|
@ -4,7 +4,7 @@ error[E0382]: use of moved value: `f`
|
||||||
LL | let f = SharedFuture;
|
LL | let f = SharedFuture;
|
||||||
| - move occurs because `f` has type `SharedFuture`, which does not implement the `Copy` trait
|
| - move occurs because `f` has type `SharedFuture`, which does not implement the `Copy` trait
|
||||||
LL | f.await;
|
LL | f.await;
|
||||||
| ----- `f` moved due to this method call
|
| ----- `f` moved due to this await
|
||||||
LL | f.await;
|
LL | f.await;
|
||||||
| ^ value used here after move
|
| ^ value used here after move
|
||||||
|
|
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue