Skip to content

Commit 5dee7dd

Browse files
committed
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 <[email protected]>
1 parent ce361fb commit 5dee7dd

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/librustc/traits/error_reporting/on_unimplemented.rs

+18
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,24 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
6767
"a function"
6868
})
6969
})
70+
} else if let hir::Node::TraitItem(hir::TraitItem {
71+
kind: hir::TraitItemKind::Method(_, hir::TraitMethod::Provided(body_id)),
72+
..
73+
}) = &node
74+
{
75+
self.describe_generator(*body_id).or_else(|| Some("a trait method"))
76+
} else if let hir::Node::ImplItem(hir::ImplItem {
77+
kind: hir::ImplItemKind::Method(sig, body_id),
78+
..
79+
}) = &node
80+
{
81+
self.describe_generator(*body_id).or_else(|| {
82+
Some(if let hir::FnHeader { asyncness: hir::IsAsync::Async, .. } = sig.header {
83+
"an async method"
84+
} else {
85+
"a method"
86+
})
87+
})
7088
} else if let hir::Node::Expr(hir::Expr {
7189
kind: hir::ExprKind::Closure(_is_move, _, body_id, _, gen_movability),
7290
..

0 commit comments

Comments
 (0)