1
Fork 0

Handle methods in try diagnostic

The diagnostic for diagnostic for methods and trait provided
methods would only show the empty string:

    error[E0277]: the `?` operator can only be used in  that returns `Result` or `Option` (or another type that implements `std::ops::Try`)

Handle the missing cases so it reads ``a method'' / ``an async
method'' / ``a trait method'' respectively.

Signed-off-by: Philipp Gesang <phg@phi-gamma.net>
This commit is contained in:
Philipp Gesang 2020-01-21 21:49:23 +01:00
parent ce361fb24f
commit 5dee7dddf2
No known key found for this signature in database
GPG key ID: 1360EC0B3CC3D66D

View file

@ -67,6 +67,24 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
"a function"
})
})
} else if let hir::Node::TraitItem(hir::TraitItem {
kind: hir::TraitItemKind::Method(_, hir::TraitMethod::Provided(body_id)),
..
}) = &node
{
self.describe_generator(*body_id).or_else(|| Some("a trait method"))
} else if let hir::Node::ImplItem(hir::ImplItem {
kind: hir::ImplItemKind::Method(sig, body_id),
..
}) = &node
{
self.describe_generator(*body_id).or_else(|| {
Some(if let hir::FnHeader { asyncness: hir::IsAsync::Async, .. } = sig.header {
"an async method"
} else {
"a method"
})
})
} else if let hir::Node::Expr(hir::Expr {
kind: hir::ExprKind::Closure(_is_move, _, body_id, _, gen_movability),
..