diff options
| author | Philipp Gesang <phg@phi-gamma.net> | 2020-01-21 21:49:23 +0100 |
|---|---|---|
| committer | Philipp Gesang <phg@phi-gamma.net> | 2020-01-21 18:49:18 +0100 |
| commit | 5dee7dddf24a022184a743b714b5062e83516a87 (patch) | |
| tree | 7377458b2ecf27c42df7a4ba210ca37b839bea8b | |
| parent | ce361fb24f0896bf7d983549117cbe1f70f32dcf (diff) | |
| download | rust-5dee7dddf24a022184a743b714b5062e83516a87.tar.gz rust-5dee7dddf24a022184a743b714b5062e83516a87.zip | |
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>
| -rw-r--r-- | src/librustc/traits/error_reporting/on_unimplemented.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/librustc/traits/error_reporting/on_unimplemented.rs b/src/librustc/traits/error_reporting/on_unimplemented.rs index 9f3fc91548b..8f55540cae3 100644 --- a/src/librustc/traits/error_reporting/on_unimplemented.rs +++ b/src/librustc/traits/error_reporting/on_unimplemented.rs @@ -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), .. |
