use rustc_hir::{AsyncGeneratorKind, GeneratorKind, Node};
use rustc_middle::ty::{
self, suggest_arbitrary_trait_bound, suggest_constraining_type_param, AdtKind, DefIdTree,
- Infer, InferTy, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness,
+ Infer, InferTy, ToPredicate, Ty, TyCtxt, TypeFoldable,
};
use rustc_middle::ty::{TypeAndMut, TypeckResults};
use rustc_session::Limit;
trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>,
);
+ fn suggest_remove_await(
+ &self,
+ obligation: &PredicateObligation<'tcx>,
+ err: &mut DiagnosticBuilder<'_>,
+ );
+
fn suggest_change_mut(
&self,
obligation: &PredicateObligation<'tcx>,
}
}
+ fn suggest_remove_await(
+ &self,
+ obligation: &PredicateObligation<'tcx>,
+ err: &mut DiagnosticBuilder<'_>,
+ ) {
+ let span = obligation.cause.span;
+
+ if let ObligationCauseCode::AwaitableExpr = 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,
+ );
+ }
+ }
+
/// Check if the trait bound is implemented for a different mutability and note it in the
/// final error.
fn suggest_change_mut(
| ObligationCauseCode::ReturnType
| ObligationCauseCode::ReturnValue(_)
| ObligationCauseCode::BlockTailExpression(_)
+ | ObligationCauseCode::AwaitableExpr
+ | ObligationCauseCode::ForLoopIterator
+ | ObligationCauseCode::QuestionMark
| ObligationCauseCode::LetElse => {}
ObligationCauseCode::SliceOrArrayElem => {
err.note("slice and array elements must have `Sized` type");