diff options
| author | Yotam Ofek <yotam.ofek@gmail.com> | 2025-03-06 07:59:11 +0000 |
|---|---|---|
| committer | Yotam Ofek <yotam.ofek@gmail.com> | 2025-03-06 08:16:28 +0000 |
| commit | fde37335aab7df1f9fcdfb0f5079ba76e56d7fe1 (patch) | |
| tree | 1307fcc46e9f46914e7eed02451f9d82640498c5 /src/librustdoc/html/render/span_map.rs | |
| parent | 4559163ccb500affc424fb9228dae5003672ffc7 (diff) | |
| download | rust-fde37335aab7df1f9fcdfb0f5079ba76e56d7fe1.tar.gz rust-fde37335aab7df1f9fcdfb0f5079ba76e56d7fe1.zip | |
`librustdoc`: flatten nested ifs
Diffstat (limited to 'src/librustdoc/html/render/span_map.rs')
| -rw-r--r-- | src/librustdoc/html/render/span_map.rs | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/src/librustdoc/html/render/span_map.rs b/src/librustdoc/html/render/span_map.rs index ce9c42c01cc..82385c1c4db 100644 --- a/src/librustdoc/html/render/span_map.rs +++ b/src/librustdoc/html/render/span_map.rs @@ -95,10 +95,8 @@ impl SpanMapVisitor<'_> { .unwrap_or(path.span); self.matches.insert(span, link); } - Res::Local(_) => { - if let Some(span) = self.tcx.hir().res_span(path.res) { - self.matches.insert(path.span, LinkFromSrc::Local(clean::Span::new(span))); - } + Res::Local(_) if let Some(span) = self.tcx.hir().res_span(path.res) => { + self.matches.insert(path.span, LinkFromSrc::Local(clean::Span::new(span))); } Res::PrimTy(p) => { // FIXME: Doesn't handle "path-like" primitives like arrays or tuples. @@ -111,15 +109,15 @@ impl SpanMapVisitor<'_> { /// Used to generate links on items' definition to go to their documentation page. pub(crate) fn extract_info_from_hir_id(&mut self, hir_id: HirId) { - if let Node::Item(item) = self.tcx.hir_node(hir_id) { - if let Some(span) = self.tcx.def_ident_span(item.owner_id) { - let cspan = clean::Span::new(span); - // If the span isn't from the current crate, we ignore it. - if cspan.inner().is_dummy() || cspan.cnum(self.tcx.sess) != LOCAL_CRATE { - return; - } - self.matches.insert(span, LinkFromSrc::Doc(item.owner_id.to_def_id())); + if let Node::Item(item) = self.tcx.hir_node(hir_id) + && let Some(span) = self.tcx.def_ident_span(item.owner_id) + { + let cspan = clean::Span::new(span); + // If the span isn't from the current crate, we ignore it. + if cspan.inner().is_dummy() || cspan.cnum(self.tcx.sess) != LOCAL_CRATE { + return; } + self.matches.insert(span, LinkFromSrc::Doc(item.owner_id.to_def_id())); } } |
