From 8efb9ebe733faf3586e514e2c3f662bce5888365 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Thu, 5 Mar 2020 15:24:53 +0900 Subject: [PATCH] Avoid using `unwrap()` in suggestions --- src/librustc_typeck/check/method/suggest.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 95faa353e9b65..084601fbde1d4 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -547,10 +547,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { (&self_ty.kind, parent_pred) { if let ty::Adt(def, _) = p.skip_binder().trait_ref.self_ty().kind { - let id = self.tcx.hir().as_local_hir_id(def.did).unwrap(); - let node = self.tcx.hir().get(id); + let node = self + .tcx + .hir() + .as_local_hir_id(def.did) + .map(|id| self.tcx.hir().get(id)); match node { - hir::Node::Item(hir::Item { kind, .. }) => { + Some(hir::Node::Item(hir::Item { kind, .. })) => { if let Some(g) = kind.generics() { let key = match &g.where_clause.predicates[..] { [.., pred] => {