]> git.lizzy.rs Git - rust.git/blobdiff - src/librustdoc/doctest.rs
Rollup merge of #92274 - woppopo:const_deallocate, r=oli-obk
[rust.git] / src / librustdoc / doctest.rs
index 96ed9a15454d14df0a9cf8515ef7e30e065be7d5..024fe6345d295a694b3f2e8b91ac378c4b41795d 100644 (file)
@@ -8,6 +8,7 @@
 use rustc_hir::{HirId, CRATE_HIR_ID};
 use rustc_interface::interface;
 use rustc_middle::hir::map::Map;
+use rustc_middle::hir::nested_filter;
 use rustc_middle::ty::TyCtxt;
 use rustc_session::config::{self, CrateType, ErrorOutputType};
 use rustc_session::{lint, DiagnosticOutput, Session};
@@ -29,7 +30,7 @@
 use std::sync::{Arc, Mutex};
 
 use crate::clean::{types::AttributesExt, Attributes};
-use crate::config::Options;
+use crate::config::Options as RustdocOptions;
 use crate::html::markdown::{self, ErrorCodes, Ignore, LangString};
 use crate::lint::init_lints;
 use crate::passes::span_of_attrs;
@@ -43,7 +44,7 @@
     crate attrs: Vec<String>,
 }
 
-crate fn run(options: Options) -> Result<(), ErrorReported> {
+crate fn run(options: RustdocOptions) -> Result<(), ErrorReported> {
     let input = config::Input::File(options.input.clone());
 
     let invalid_codeblock_attributes_name = crate::lint::INVALID_CODEBLOCK_ATTRIBUTES.name;
@@ -293,7 +294,7 @@ fn run_test(
     test: &str,
     crate_name: &str,
     line: usize,
-    options: Options,
+    rustdoc_options: RustdocOptions,
     mut lang_string: LangString,
     no_run: bool,
     runtool: Option<String>,
@@ -311,16 +312,16 @@ fn run_test(
 
     let output_file = outdir.path().join("rust_out");
 
-    let rustc_binary = options
+    let rustc_binary = rustdoc_options
         .test_builder
         .as_deref()
         .unwrap_or_else(|| rustc_interface::util::rustc_path().expect("found rustc"));
     let mut compiler = Command::new(&rustc_binary);
     compiler.arg("--crate-type").arg("bin");
-    for cfg in &options.cfgs {
+    for cfg in &rustdoc_options.cfgs {
         compiler.arg("--cfg").arg(&cfg);
     }
-    if let Some(sysroot) = options.maybe_sysroot {
+    if let Some(sysroot) = rustdoc_options.maybe_sysroot {
         compiler.arg("--sysroot").arg(sysroot);
     }
     compiler.arg("--edition").arg(&edition.to_string());
@@ -330,26 +331,26 @@ fn run_test(
     if lang_string.test_harness {
         compiler.arg("--test");
     }
-    if options.json_unused_externs && !lang_string.compile_fail {
+    if rustdoc_options.json_unused_externs && !lang_string.compile_fail {
         compiler.arg("--error-format=json");
         compiler.arg("--json").arg("unused-externs");
         compiler.arg("-Z").arg("unstable-options");
         compiler.arg("-W").arg("unused_crate_dependencies");
     }
-    for lib_str in &options.lib_strs {
+    for lib_str in &rustdoc_options.lib_strs {
         compiler.arg("-L").arg(&lib_str);
     }
-    for extern_str in &options.extern_strs {
+    for extern_str in &rustdoc_options.extern_strs {
         compiler.arg("--extern").arg(&extern_str);
     }
     compiler.arg("-Ccodegen-units=1");
-    for codegen_options_str in &options.codegen_options_strs {
+    for codegen_options_str in &rustdoc_options.codegen_options_strs {
         compiler.arg("-C").arg(&codegen_options_str);
     }
-    for debugging_option_str in &options.debugging_opts_strs {
+    for debugging_option_str in &rustdoc_options.debugging_opts_strs {
         compiler.arg("-Z").arg(&debugging_option_str);
     }
-    if no_run && !lang_string.compile_fail && options.persist_doctests.is_none() {
+    if no_run && !lang_string.compile_fail && rustdoc_options.persist_doctests.is_none() {
         compiler.arg("--emit=metadata");
     }
     compiler.arg("--target").arg(match target {
@@ -358,7 +359,7 @@ fn run_test(
             path.to_str().expect("target path must be valid unicode").to_string()
         }
     });
-    if let ErrorOutputType::HumanReadable(kind) = options.error_format {
+    if let ErrorOutputType::HumanReadable(kind) = rustdoc_options.error_format {
         let (short, color_config) = kind.unzip();
 
         if short {
@@ -452,11 +453,11 @@ fn drop(&mut self) {
     } else {
         cmd = Command::new(output_file);
     }
-    if let Some(run_directory) = options.test_run_directory {
+    if let Some(run_directory) = rustdoc_options.test_run_directory {
         cmd.current_dir(run_directory);
     }
 
-    let result = if options.nocapture {
+    let result = if rustdoc_options.nocapture {
         cmd.status().map(|status| process::Output {
             status,
             stdout: Vec::new(),
@@ -802,7 +803,7 @@ fn register_header(&mut self, _name: &str, _level: u32) {}
     // the `names` vector of that test will be `["Title", "Subtitle"]`.
     names: Vec<String>,
 
-    options: Options,
+    rustdoc_options: RustdocOptions,
     use_headers: bool,
     enable_per_target_ignores: bool,
     crate_name: Symbol,
@@ -818,7 +819,7 @@ fn register_header(&mut self, _name: &str, _level: u32) {}
 impl Collector {
     crate fn new(
         crate_name: Symbol,
-        options: Options,
+        rustdoc_options: RustdocOptions,
         use_headers: bool,
         opts: GlobalTestOptions,
         source_map: Option<Lrc<SourceMap>>,
@@ -828,7 +829,7 @@ impl Collector {
         Collector {
             tests: Vec::new(),
             names: Vec::new(),
-            options,
+            rustdoc_options,
             use_headers,
             enable_per_target_ignores,
             crate_name,
@@ -882,14 +883,14 @@ fn add_test(&mut self, test: String, config: LangString, line: usize) {
         let name = self.generate_name(line, &filename);
         let crate_name = self.crate_name.to_string();
         let opts = self.opts.clone();
-        let edition = config.edition.unwrap_or(self.options.edition);
-        let options = self.options.clone();
-        let runtool = self.options.runtool.clone();
-        let runtool_args = self.options.runtool_args.clone();
-        let target = self.options.target.clone();
+        let edition = config.edition.unwrap_or(self.rustdoc_options.edition);
+        let rustdoc_options = self.rustdoc_options.clone();
+        let runtool = self.rustdoc_options.runtool.clone();
+        let runtool_args = self.rustdoc_options.runtool_args.clone();
+        let target = self.rustdoc_options.target.clone();
         let target_str = target.to_string();
         let unused_externs = self.unused_extern_reports.clone();
-        let no_run = config.no_run || options.no_run;
+        let no_run = config.no_run || rustdoc_options.no_run;
         if !config.compile_fail {
             self.compiling_test_count.fetch_add(1, Ordering::SeqCst);
         }
@@ -923,7 +924,7 @@ fn add_test(&mut self, test: String, config: LangString, line: usize) {
                 self.visited_tests.entry((file.clone(), line)).and_modify(|v| *v += 1).or_insert(0)
             },
         );
-        let outdir = if let Some(mut path) = options.persist_doctests.clone() {
+        let outdir = if let Some(mut path) = rustdoc_options.persist_doctests.clone() {
             path.push(&test_id);
 
             std::fs::create_dir_all(&path)
@@ -963,7 +964,7 @@ fn add_test(&mut self, test: String, config: LangString, line: usize) {
                     &test,
                     &crate_name,
                     line,
-                    options,
+                    rustdoc_options,
                     config,
                     no_run,
                     runtool,
@@ -1154,10 +1155,10 @@ fn visit_testable<F: FnOnce(&mut Self)>(
 }
 
 impl<'a, 'hir, 'tcx> intravisit::Visitor<'hir> for HirCollector<'a, 'hir, 'tcx> {
-    type Map = Map<'hir>;
+    type NestedFilter = nested_filter::All;
 
-    fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<Self::Map> {
-        intravisit::NestedVisitorMap::All(self.map)
+    fn nested_visit_map(&mut self) -> Self::Map {
+        self.map
     }
 
     fn visit_item(&mut self, item: &'hir hir::Item<'_>) {