1 use rustc::hir::map::Map;
2 use rustc::session::{self, config, DiagnosticOutput};
3 use rustc::util::common::ErrorReported;
4 use rustc_data_structures::sync::Lrc;
5 use rustc_feature::UnstableFeatures;
7 use rustc_hir::intravisit;
8 use rustc_interface::interface;
9 use rustc_span::edition::Edition;
10 use rustc_span::source_map::SourceMap;
11 use rustc_span::symbol::sym;
12 use rustc_span::{BytePos, FileName, Pos, Span, DUMMY_SP};
13 use rustc_target::spec::TargetTriple;
15 use std::io::{self, Write};
17 use std::path::PathBuf;
18 use std::process::{self, Command, Stdio};
21 use syntax::with_globals;
22 use tempfile::Builder as TempFileBuilder;
25 use crate::clean::Attributes;
26 use crate::config::Options;
27 use crate::html::markdown::{self, ErrorCodes, Ignore, LangString};
29 #[derive(Clone, Default)]
30 pub struct TestOptions {
31 /// Whether to disable the default `extern crate my_crate;` when creating doctests.
32 pub no_crate_inject: bool,
33 /// Whether to emit compilation warnings when compiling doctests. Setting this will suppress
34 /// the default `#![allow(unused)]`.
35 pub display_warnings: bool,
36 /// Additional crate-level attributes to add to doctests.
37 pub attrs: Vec<String>,
40 pub fn run(options: Options) -> i32 {
41 let input = config::Input::File(options.input.clone());
43 let crate_types = if options.proc_macro_crate {
44 vec![config::CrateType::ProcMacro]
46 vec![config::CrateType::Dylib]
49 let sessopts = config::Options {
50 maybe_sysroot: options.maybe_sysroot.clone(),
51 search_paths: options.libs.clone(),
53 cg: options.codegen_options.clone(),
54 externs: options.externs.clone(),
55 unstable_features: UnstableFeatures::from_environment(),
56 lint_cap: Some(::rustc::lint::Level::Allow),
57 actually_rustdoc: true,
58 debugging_opts: config::DebuggingOptions { ..config::basic_debugging_options() },
59 edition: options.edition,
60 target_triple: options.target.clone(),
61 ..config::Options::default()
64 let mut cfgs = options.cfgs.clone();
65 cfgs.push("doc".to_owned());
66 cfgs.push("doctest".to_owned());
67 let config = interface::Config {
69 crate_cfg: interface::parse_cfgspecs(cfgs),
75 diagnostic_output: DiagnosticOutput::Default,
77 crate_name: options.crate_name.clone(),
78 lint_caps: Default::default(),
80 override_queries: None,
81 registry: rustc_driver::diagnostics_registry(),
84 let mut test_args = options.test_args.clone();
85 let display_warnings = options.display_warnings;
87 let tests = interface::run_compiler(config, |compiler| {
88 compiler.enter(|queries| {
89 let lower_to_hir = queries.lower_to_hir()?;
91 let mut opts = scrape_test_config(lower_to_hir.peek().0.krate());
92 opts.display_warnings |= options.display_warnings;
93 let enable_per_target_ignores = options.enable_per_target_ignores;
94 let mut collector = Collector::new(
95 queries.crate_name()?.peek().to_string(),
99 Some(compiler.source_map().clone()),
101 enable_per_target_ignores,
104 let mut global_ctxt = queries.global_ctxt()?.take();
106 global_ctxt.enter(|tcx| {
107 let krate = tcx.hir().krate();
108 let mut hir_collector = HirCollector {
109 sess: compiler.session(),
110 collector: &mut collector,
112 codes: ErrorCodes::from(
113 compiler.session().opts.unstable_features.is_nightly_build(),
116 hir_collector.visit_testable("".to_string(), &krate.attrs, |this| {
117 intravisit::walk_crate(this, krate);
121 let ret: Result<_, ErrorReported> = Ok(collector.tests);
125 .expect("compiler aborted in rustdoc!");
127 test_args.insert(0, "rustdoctest".to_string());
132 Some(testing::Options::new().display_output(display_warnings)),
138 // Look for `#![doc(test(no_crate_inject))]`, used by crates in the std facade.
139 fn scrape_test_config(krate: &::rustc_hir::Crate) -> TestOptions {
140 use syntax::print::pprust;
143 TestOptions { no_crate_inject: false, display_warnings: false, attrs: Vec::new() };
145 let test_attrs: Vec<_> = krate
148 .filter(|a| a.check_name(sym::doc))
149 .flat_map(|a| a.meta_item_list().unwrap_or_else(Vec::new))
150 .filter(|a| a.check_name(sym::test))
152 let attrs = test_attrs.iter().flat_map(|a| a.meta_item_list().unwrap_or(&[]));
155 if attr.check_name(sym::no_crate_inject) {
156 opts.no_crate_inject = true;
158 if attr.check_name(sym::attr) {
159 if let Some(l) = attr.meta_item_list() {
161 opts.attrs.push(pprust::meta_list_item_to_string(item));
170 /// Documentation test failure modes.
172 /// The test failed to compile.
174 /// The test is marked `compile_fail` but compiled successfully.
175 UnexpectedCompilePass,
176 /// The test failed to compile (as expected) but the compiler output did not contain all
177 /// expected error codes.
178 MissingErrorCodes(Vec<String>),
179 /// The test binary was unable to be executed.
180 ExecutionError(io::Error),
181 /// The test binary exited with a non-zero exit code.
183 /// This typically means an assertion in the test failed or another form of panic occurred.
184 ExecutionFailure(process::Output),
185 /// The test is marked `should_panic` but the test binary executed successfully.
197 as_test_harness: bool,
198 runtool: Option<String>,
199 runtool_args: Vec<String>,
200 target: TargetTriple,
202 mut error_codes: Vec<String>,
205 ) -> Result<(), TestFailure> {
206 let (test, line_offset) = make_test(test, Some(cratename), as_test_harness, opts, edition);
208 // FIXME(#44940): if doctests ever support path remapping, then this filename
209 // needs to be the result of `SourceMap::span_to_unmapped_path`.
210 let path = match filename {
211 FileName::Real(path) => path.clone(),
212 _ => PathBuf::from(r"doctest.rs"),
216 Temp(tempfile::TempDir),
221 fn path(&self) -> &std::path::Path {
223 DirState::Temp(t) => t.path(),
224 DirState::Perm(p) => p.as_path(),
229 let outdir = if let Some(mut path) = options.persist_doctests {
232 filename.to_string().rsplit('/').next().unwrap().replace(".", "_"),
235 std::fs::create_dir_all(&path).expect("Couldn't create directory for doctest executables");
240 TempFileBuilder::new()
241 .prefix("rustdoctest")
243 .expect("rustdoc needs a tempdir"),
246 let output_file = outdir.path().join("rust_out");
248 let rustc_binary = options
252 .unwrap_or_else(|| rustc_interface::util::rustc_path().expect("found rustc"));
253 let mut compiler = Command::new(&rustc_binary);
254 compiler.arg("--crate-type").arg("bin");
255 for cfg in &options.cfgs {
256 compiler.arg("--cfg").arg(&cfg);
258 if let Some(sysroot) = options.maybe_sysroot {
259 compiler.arg("--sysroot").arg(sysroot);
261 compiler.arg("--edition").arg(&edition.to_string());
262 compiler.env("UNSTABLE_RUSTDOC_TEST_PATH", path);
263 compiler.env("UNSTABLE_RUSTDOC_TEST_LINE", format!("{}", line as isize - line_offset as isize));
264 compiler.arg("-o").arg(&output_file);
266 compiler.arg("--test");
268 for lib_str in &options.lib_strs {
269 compiler.arg("-L").arg(&lib_str);
271 for extern_str in &options.extern_strs {
272 compiler.arg("--extern").arg(&extern_str);
274 compiler.arg("-Ccodegen-units=1");
275 for codegen_options_str in &options.codegen_options_strs {
276 compiler.arg("-C").arg(&codegen_options_str);
278 for debugging_option_str in &options.debugging_options_strs {
279 compiler.arg("-Z").arg(&debugging_option_str);
282 compiler.arg("--emit=metadata");
284 compiler.arg("--target").arg(target.to_string());
287 compiler.stdin(Stdio::piped());
288 compiler.stderr(Stdio::piped());
290 let mut child = compiler.spawn().expect("Failed to spawn rustc process");
292 let stdin = child.stdin.as_mut().expect("Failed to open stdin");
293 stdin.write_all(test.as_bytes()).expect("could write out test sources");
295 let output = child.wait_with_output().expect("Failed to read stdout");
297 struct Bomb<'a>(&'a str);
298 impl Drop for Bomb<'_> {
300 eprint!("{}", self.0);
304 let out = str::from_utf8(&output.stderr).unwrap();
305 let _bomb = Bomb(&out);
306 match (output.status.success(), compile_fail) {
308 return Err(TestFailure::UnexpectedCompilePass);
312 if !error_codes.is_empty() {
313 error_codes.retain(|err| !out.contains(err));
315 if !error_codes.is_empty() {
316 return Err(TestFailure::MissingErrorCodes(error_codes));
321 return Err(TestFailure::CompileError);
332 if let Some(tool) = runtool {
333 cmd = Command::new(tool);
334 cmd.arg(output_file);
335 cmd.args(runtool_args);
337 cmd = Command::new(output_file);
341 Err(e) => return Err(TestFailure::ExecutionError(e)),
343 if should_panic && out.status.success() {
344 return Err(TestFailure::UnexpectedRunPass);
345 } else if !should_panic && !out.status.success() {
346 return Err(TestFailure::ExecutionFailure(out));
354 /// Transforms a test into code that can be compiled into a Rust binary, and returns the number of
355 /// lines before the test code begins.
358 cratename: Option<&str>,
359 dont_insert_main: bool,
362 ) -> (String, usize) {
363 let (crate_attrs, everything_else, crates) = partition_source(s);
364 let everything_else = everything_else.trim();
365 let mut line_offset = 0;
366 let mut prog = String::new();
368 if opts.attrs.is_empty() && !opts.display_warnings {
369 // If there aren't any attributes supplied by #![doc(test(attr(...)))], then allow some
370 // lints that are commonly triggered in doctests. The crate-level test attributes are
371 // commonly used to make tests fail in case they trigger warnings, so having this there in
372 // that case may cause some tests to pass when they shouldn't have.
373 prog.push_str("#![allow(unused)]\n");
377 // Next, any attributes that came from the crate root via #![doc(test(attr(...)))].
378 for attr in &opts.attrs {
379 prog.push_str(&format!("#![{}]\n", attr));
383 // Now push any outer attributes from the example, assuming they
384 // are intended to be crate attributes.
385 prog.push_str(&crate_attrs);
386 prog.push_str(&crates);
388 // Uses libsyntax to parse the doctest and find if there's a main fn and the extern
389 // crate already is included.
390 let result = rustc_driver::catch_fatal_errors(|| {
391 with_globals(edition, || {
392 use rustc_errors::emitter::EmitterWriter;
393 use rustc_errors::Handler;
394 use rustc_parse::maybe_new_parser_from_source_str;
395 use rustc_span::source_map::FilePathMapping;
396 use syntax::sess::ParseSess;
398 let filename = FileName::anon_source_code(s);
399 let source = crates + &everything_else;
401 // Any errors in parsing should also appear when the doctest is compiled for real, so just
402 // send all the errors that libsyntax emits directly into a `Sink` instead of stderr.
403 let cm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
405 EmitterWriter::new(box io::sink(), None, false, false, false, None, false);
406 // FIXME(misdreavus): pass `-Z treat-err-as-bug` to the doctest parser
407 let handler = Handler::with_emitter(false, None, box emitter);
408 let sess = ParseSess::with_span_handler(handler, cm);
410 let mut found_main = false;
411 let mut found_extern_crate = cratename.is_none();
412 let mut found_macro = false;
414 let mut parser = match maybe_new_parser_from_source_str(&sess, filename, source) {
417 for mut err in errs {
421 return (found_main, found_extern_crate, found_macro);
426 match parser.parse_item() {
429 if let ast::ItemKind::Fn(..) = item.kind {
430 if item.ident.name == sym::main {
436 if !found_extern_crate {
437 if let ast::ItemKind::ExternCrate(original) = item.kind {
438 // This code will never be reached if `cratename` is none because
439 // `found_extern_crate` is initialized to `true` if it is none.
440 let cratename = cratename.unwrap();
443 Some(name) => found_extern_crate = name.as_str() == cratename,
444 None => found_extern_crate = item.ident.as_str() == cratename,
450 if let ast::ItemKind::Mac(..) = item.kind {
455 if found_main && found_extern_crate {
467 (found_main, found_extern_crate, found_macro)
470 let (already_has_main, already_has_extern_crate, found_macro) = match result {
471 Ok(result) => result,
472 Err(ErrorReported) => {
473 // If the parser panicked due to a fatal error, pass the test code through unchanged.
474 // The error will be reported during compilation.
475 return (s.to_owned(), 0);
479 // If a doctest's `fn main` is being masked by a wrapper macro, the parsing loop above won't
480 // see it. In that case, run the old text-based scan to see if they at least have a main
481 // function written inside a macro invocation. See
482 // https://github.com/rust-lang/rust/issues/56898
483 let already_has_main = if found_macro && !already_has_main {
486 let comment = line.find("//");
487 if let Some(comment_begins) = comment { &line[0..comment_begins] } else { line }
489 .any(|code| code.contains("fn main"))
494 // Don't inject `extern crate std` because it's already injected by the
496 if !already_has_extern_crate && !opts.no_crate_inject && cratename != Some("std") {
497 if let Some(cratename) = cratename {
498 // Make sure its actually used if not included.
499 if s.contains(cratename) {
500 prog.push_str(&format!("extern crate {};\n", cratename));
506 // FIXME: This code cannot yet handle no_std test cases yet
507 if dont_insert_main || already_has_main || prog.contains("![no_std]") {
508 prog.push_str(everything_else);
510 let returns_result = everything_else.trim_end().ends_with("(())");
511 let (main_pre, main_post) = if returns_result {
513 "fn main() { fn _inner() -> Result<(), impl core::fmt::Debug> {",
514 "}\n_inner().unwrap() }",
517 ("fn main() {\n", "\n}")
519 prog.extend([main_pre, everything_else, main_post].iter().cloned());
523 debug!("final doctest:\n{}", prog);
528 // FIXME(aburka): use a real parser to deal with multiline attributes
529 fn partition_source(s: &str) -> (String, String, String) {
530 #[derive(Copy, Clone, PartialEq)]
531 enum PartitionState {
536 let mut state = PartitionState::Attrs;
537 let mut before = String::new();
538 let mut crates = String::new();
539 let mut after = String::new();
541 for line in s.lines() {
542 let trimline = line.trim();
544 // FIXME(misdreavus): if a doc comment is placed on an extern crate statement, it will be
545 // shunted into "everything else"
547 PartitionState::Attrs => {
548 state = if trimline.starts_with("#![")
549 || trimline.chars().all(|c| c.is_whitespace())
550 || (trimline.starts_with("//") && !trimline.starts_with("///"))
552 PartitionState::Attrs
553 } else if trimline.starts_with("extern crate")
554 || trimline.starts_with("#[macro_use] extern crate")
556 PartitionState::Crates
558 PartitionState::Other
561 PartitionState::Crates => {
562 state = if trimline.starts_with("extern crate")
563 || trimline.starts_with("#[macro_use] extern crate")
564 || trimline.chars().all(|c| c.is_whitespace())
565 || (trimline.starts_with("//") && !trimline.starts_with("///"))
567 PartitionState::Crates
569 PartitionState::Other
572 PartitionState::Other => {}
576 PartitionState::Attrs => {
577 before.push_str(line);
578 before.push_str("\n");
580 PartitionState::Crates => {
581 crates.push_str(line);
582 crates.push_str("\n");
584 PartitionState::Other => {
585 after.push_str(line);
586 after.push_str("\n");
591 debug!("before:\n{}", before);
592 debug!("crates:\n{}", crates);
593 debug!("after:\n{}", after);
595 (before, after, crates)
599 fn add_test(&mut self, test: String, config: LangString, line: usize);
600 fn get_line(&self) -> usize {
603 fn register_header(&mut self, _name: &str, _level: u32) {}
606 pub struct Collector {
607 pub tests: Vec<testing::TestDescAndFn>,
609 // The name of the test displayed to the user, separated by `::`.
611 // In tests from Rust source, this is the path to the item
612 // e.g., `["std", "vec", "Vec", "push"]`.
614 // In tests from a markdown file, this is the titles of all headers (h1~h6)
615 // of the sections that contain the code block, e.g., if the markdown file is
628 // the `names` vector of that test will be `["Title", "Subtitle"]`.
633 enable_per_target_ignores: bool,
637 source_map: Option<Lrc<SourceMap>>,
638 filename: Option<PathBuf>,
647 source_map: Option<Lrc<SourceMap>>,
648 filename: Option<PathBuf>,
649 enable_per_target_ignores: bool,
656 enable_per_target_ignores,
665 fn generate_name(&self, line: usize, filename: &FileName) -> String {
666 format!("{} - {} (line {})", filename, self.names.join("::"), line)
669 pub fn set_position(&mut self, position: Span) {
670 self.position = position;
673 fn get_filename(&self) -> FileName {
674 if let Some(ref source_map) = self.source_map {
675 let filename = source_map.span_to_filename(self.position);
676 if let FileName::Real(ref filename) = filename {
677 if let Ok(cur_dir) = env::current_dir() {
678 if let Ok(path) = filename.strip_prefix(&cur_dir) {
679 return path.to_owned().into();
684 } else if let Some(ref filename) = self.filename {
685 filename.clone().into()
687 FileName::Custom("input".to_owned())
692 impl Tester for Collector {
693 fn add_test(&mut self, test: String, config: LangString, line: usize) {
694 let filename = self.get_filename();
695 let name = self.generate_name(line, &filename);
696 let cratename = self.cratename.to_string();
697 let opts = self.opts.clone();
698 let edition = config.edition.unwrap_or(self.options.edition.clone());
699 let options = self.options.clone();
700 let runtool = self.options.runtool.clone();
701 let runtool_args = self.options.runtool_args.clone();
702 let target = self.options.target.clone();
703 let target_str = target.to_string();
705 debug!("creating test {}: {}", name, test);
706 self.tests.push(testing::TestDescAndFn {
707 desc: testing::TestDesc {
708 name: testing::DynTestName(name.clone()),
709 ignore: match config.ignore {
711 Ignore::None => false,
712 Ignore::Some(ref ignores) => ignores.iter().any(|s| target_str.contains(s)),
714 // compiler failures are test failures
715 should_panic: testing::ShouldPanic::No,
716 allow_fail: config.allow_fail,
717 test_type: testing::TestType::DocTest,
719 testfn: testing::DynTestFn(box move || {
738 if let Err(err) = res {
740 TestFailure::CompileError => {
741 eprint!("Couldn't compile the test.");
743 TestFailure::UnexpectedCompilePass => {
744 eprint!("Test compiled successfully, but it's marked `compile_fail`.");
746 TestFailure::UnexpectedRunPass => {
747 eprint!("Test executable succeeded, but it's marked `should_panic`.");
749 TestFailure::MissingErrorCodes(codes) => {
750 eprint!("Some expected error codes were not found: {:?}", codes);
752 TestFailure::ExecutionError(err) => {
753 eprint!("Couldn't run the test: {}", err);
754 if err.kind() == io::ErrorKind::PermissionDenied {
755 eprint!(" - maybe your tempdir is mounted with noexec?");
758 TestFailure::ExecutionFailure(out) => {
759 let reason = if let Some(code) = out.status.code() {
760 format!("exit code {}", code)
762 String::from("terminated by signal")
765 eprintln!("Test executable failed ({}).", reason);
767 // FIXME(#12309): An unfortunate side-effect of capturing the test
768 // executable's output is that the relative ordering between the test's
769 // stdout and stderr is lost. However, this is better than the
770 // alternative: if the test executable inherited the parent's I/O
771 // handles the output wouldn't be captured at all, even on success.
773 // The ordering could be preserved if the test process' stderr was
774 // redirected to stdout, but that functionality does not exist in the
775 // standard library, so it may not be portable enough.
776 let stdout = str::from_utf8(&out.stdout).unwrap_or_default();
777 let stderr = str::from_utf8(&out.stderr).unwrap_or_default();
779 if !stdout.is_empty() || !stderr.is_empty() {
782 if !stdout.is_empty() {
783 eprintln!("stdout:\n{}", stdout);
786 if !stderr.is_empty() {
787 eprintln!("stderr:\n{}", stderr);
793 panic::resume_unwind(box ());
799 fn get_line(&self) -> usize {
800 if let Some(ref source_map) = self.source_map {
801 let line = self.position.lo().to_usize();
802 let line = source_map.lookup_char_pos(BytePos(line as u32)).line;
803 if line > 0 { line - 1 } else { line }
809 fn register_header(&mut self, name: &str, level: u32) {
810 if self.use_headers {
811 // We use these headings as test names, so it's good if
812 // they're valid identifiers.
817 if (i == 0 && rustc_lexer::is_id_start(c))
818 || (i != 0 && rustc_lexer::is_id_continue(c))
825 .collect::<String>();
827 // Here we try to efficiently assemble the header titles into the
828 // test name in the form of `h1::h2::h3::h4::h5::h6`.
830 // Suppose that originally `self.names` contains `[h1, h2, h3]`...
831 let level = level as usize;
832 if level <= self.names.len() {
833 // ... Consider `level == 2`. All headers in the lower levels
834 // are irrelevant in this new level. So we should reset
835 // `self.names` to contain headers until <h2>, and replace that
836 // slot with the new name: `[h1, name]`.
837 self.names.truncate(level);
838 self.names[level - 1] = name;
840 // ... On the other hand, consider `level == 5`. This means we
841 // need to extend `self.names` to contain five headers. We fill
842 // in the missing level (<h4>) with `_`. Thus `self.names` will
843 // become `[h1, h2, h3, "_", name]`.
844 if level - 1 > self.names.len() {
845 self.names.resize(level - 1, "_".to_owned());
847 self.names.push(name);
853 struct HirCollector<'a, 'hir> {
854 sess: &'a session::Session,
855 collector: &'a mut Collector,
860 impl<'a, 'hir> HirCollector<'a, 'hir> {
861 fn visit_testable<F: FnOnce(&mut Self)>(
864 attrs: &[ast::Attribute],
867 let mut attrs = Attributes::from_ast(self.sess.diagnostic(), attrs);
868 if let Some(ref cfg) = attrs.cfg {
869 if !cfg.matches(&self.sess.parse_sess, Some(&self.sess.features_untracked())) {
874 let has_name = !name.is_empty();
876 self.collector.names.push(name);
879 attrs.collapse_doc_comments();
880 attrs.unindent_doc_comments();
881 // The collapse-docs pass won't combine sugared/raw doc attributes, or included files with
882 // anything else, this will combine them for us.
883 if let Some(doc) = attrs.collapsed_doc_value() {
884 self.collector.set_position(attrs.span.unwrap_or(DUMMY_SP));
885 markdown::find_testable_code(
889 self.collector.enable_per_target_ignores,
896 self.collector.names.pop();
901 impl<'a, 'hir> intravisit::Visitor<'hir> for HirCollector<'a, 'hir> {
902 type Map = Map<'hir>;
904 fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<'_, Self::Map> {
905 intravisit::NestedVisitorMap::All(&self.map)
908 fn visit_item(&mut self, item: &'hir hir::Item) {
909 let name = if let hir::ItemKind::Impl(.., ref ty, _) = item.kind {
910 self.map.hir_to_pretty_string(ty.hir_id)
912 item.ident.to_string()
915 self.visit_testable(name, &item.attrs, |this| {
916 intravisit::walk_item(this, item);
920 fn visit_trait_item(&mut self, item: &'hir hir::TraitItem) {
921 self.visit_testable(item.ident.to_string(), &item.attrs, |this| {
922 intravisit::walk_trait_item(this, item);
926 fn visit_impl_item(&mut self, item: &'hir hir::ImplItem) {
927 self.visit_testable(item.ident.to_string(), &item.attrs, |this| {
928 intravisit::walk_impl_item(this, item);
932 fn visit_foreign_item(&mut self, item: &'hir hir::ForeignItem) {
933 self.visit_testable(item.ident.to_string(), &item.attrs, |this| {
934 intravisit::walk_foreign_item(this, item);
940 v: &'hir hir::Variant,
941 g: &'hir hir::Generics,
944 self.visit_testable(v.ident.to_string(), &v.attrs, |this| {
945 intravisit::walk_variant(this, v, g, item_id);
949 fn visit_struct_field(&mut self, f: &'hir hir::StructField) {
950 self.visit_testable(f.ident.to_string(), &f.attrs, |this| {
951 intravisit::walk_struct_field(this, f);
955 fn visit_macro_def(&mut self, macro_def: &'hir hir::MacroDef) {
956 self.visit_testable(macro_def.name.to_string(), ¯o_def.attrs, |_| ());