Skip to content

Commit

Permalink
Handle methods in try diagnostic
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
phi-gamma committed Jan 21, 2020
1 parent ce361fb commit 5dee7dd
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/librustc/traits/error_reporting/on_unimplemented.rs
Expand Up @@ -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),
..
Expand Down

0 comments on commit 5dee7dd

Please sign in to comment.