]> git.lizzy.rs Git - rust.git/blobdiff - src/librustdoc/scrape_examples.rs
Fix macro reexports duplicates in the sidebar
[rust.git] / src / librustdoc / scrape_examples.rs
index 899c9e4c62956cb3ec4b385501de85ee730c76a4..16882cf83d09cdd058873d0cb5688ce9b7e981de 100644 (file)
@@ -196,7 +196,8 @@ fn visit_expr(&mut self, ex: &'tcx hir::Expr<'tcx>) {
                 return;
             }
 
-            let file = tcx.sess.source_map().lookup_char_pos(span.lo()).file;
+            let source_map = tcx.sess.source_map();
+            let file = source_map.lookup_char_pos(span.lo()).file;
             let file_path = match file.name.clone() {
                 FileName::Real(real_filename) => real_filename.into_local_path(),
                 _ => None,
@@ -217,6 +218,8 @@ fn visit_expr(&mut self, ex: &'tcx hir::Expr<'tcx>) {
                 let fn_entries = self.calls.entry(fn_key).or_default();
 
                 trace!("Including expr: {:?}", span);
+                let enclosing_item_span =
+                    source_map.span_extend_to_prev_char(enclosing_item_span, '\n', false);
                 let location = CallLocation::new(span, enclosing_item_span, &file);
                 fn_entries.entry(abs_path).or_insert_with(mk_call_data).locations.push(location);
             }
@@ -247,8 +250,7 @@ fn visit_expr(&mut self, ex: &'tcx hir::Expr<'tcx>) {
         let target_crates = options
             .target_crates
             .into_iter()
-            .map(|target| all_crates.iter().filter(move |(_, name)| name.as_str() == target))
-            .flatten()
+            .flat_map(|target| all_crates.iter().filter(move |(_, name)| name.as_str() == target))
             .map(|(crate_num, _)| **crate_num)
             .collect::<Vec<_>>();