diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2024-10-27 19:12:16 +0000 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2025-01-30 18:38:42 +0000 |
| commit | d2a781a2ecbf02edf11deb5b3320d10ae5f34830 (patch) | |
| tree | 42c693947a86e2605be09747f5867b55df57e911 /compiler/rustc_trait_selection | |
| parent | 87d323c81e77545fc9a3878277430c1e0d58805f (diff) | |
| download | rust-d2a781a2ecbf02edf11deb5b3320d10ae5f34830.tar.gz rust-d2a781a2ecbf02edf11deb5b3320d10ae5f34830.zip | |
Remove `unwrap()`s
Diffstat (limited to 'compiler/rustc_trait_selection')
| -rw-r--r-- | compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index 22e88b36af3..3b313530a60 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -1521,12 +1521,15 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let fn_kind = self_ty.prefix_string(self.tcx); let (span, closure_span) = if let ty::Closure(def_id, _) = self_ty.kind() { let def_span = self.tcx.def_span(def_id); - let node = self.tcx.hir_node_by_def_id(def_id.as_local().unwrap()); - if let Some(fn_decl) = node.fn_decl() { + if let Some(local_def_id) = def_id.as_local() + && let node = self.tcx.hir_node_by_def_id(local_def_id) + && let Some(fn_decl) = node.fn_decl() + && let Some(id) = node.body_id() + { span = match fn_decl.output { hir::FnRetTy::Return(ty) => ty.span, hir::FnRetTy::DefaultReturn(_) => { - let body = self.tcx.hir().body(node.body_id().unwrap()); + let body = self.tcx.hir().body(id); match body.value.kind { hir::ExprKind::Block( hir::Block { expr: Some(expr), .. }, |
