From 0185ff7dab78e7b118e5ed298392ead01464ed53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Mon, 10 Oct 2022 17:12:33 +0200 Subject: [PATCH 1/2] Remove `extern crate tracing` from `librustdoc` --- src/librustdoc/clean/auto_trait.rs | 25 +++++-- src/librustdoc/clean/blanket_impl.rs | 6 +- src/librustdoc/clean/inline.rs | 8 +-- src/librustdoc/clean/mod.rs | 10 +-- src/librustdoc/clean/types.rs | 10 +-- src/librustdoc/clean/utils.rs | 8 +-- src/librustdoc/core.rs | 10 +-- src/librustdoc/doctest.rs | 14 ++-- src/librustdoc/formats/cache.rs | 4 +- src/librustdoc/formats/renderer.rs | 2 +- src/librustdoc/html/format.rs | 14 ++-- src/librustdoc/html/markdown.rs | 20 +++--- src/librustdoc/html/render/context.rs | 4 +- src/librustdoc/html/render/mod.rs | 20 +++--- src/librustdoc/html/render/print_item.rs | 12 +++- src/librustdoc/html/render/search_index.rs | 2 +- src/librustdoc/html/sources.rs | 2 +- src/librustdoc/json/mod.rs | 16 ++--- src/librustdoc/lib.rs | 10 +-- src/librustdoc/passes/bare_urls.rs | 2 +- .../passes/calculate_doc_coverage.rs | 2 +- .../passes/check_doc_test_visibility.rs | 2 +- .../passes/collect_intra_doc_links.rs | 65 +++++++++++-------- src/librustdoc/passes/collect_trait_impls.rs | 2 +- src/librustdoc/passes/strip_hidden.rs | 2 +- src/librustdoc/passes/stripper.rs | 12 ++-- src/librustdoc/scrape_examples.rs | 33 ++++++---- src/librustdoc/visit_ast.rs | 4 +- 28 files changed, 181 insertions(+), 140 deletions(-) diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index efa9242a46784..fdfadb2720544 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -45,7 +45,10 @@ where let tcx = self.cx.tcx; let trait_ref = ty::TraitRef { def_id: trait_def_id, substs: tcx.mk_substs_trait(ty, &[]) }; if !self.cx.generated_synthetics.insert((ty, trait_def_id)) { - debug!("get_auto_trait_impl_for({:?}): already generated, aborting", trait_ref); + tracing::debug!( + "get_auto_trait_impl_for({:?}): already generated, aborting", + trait_ref + ); return None; } @@ -70,10 +73,12 @@ where info.vid_to_region, ); - debug!( + tracing::debug!( "find_auto_trait_generics(item_def_id={:?}, trait_def_id={:?}): \ finished with {:?}", - item_def_id, trait_def_id, new_generics + item_def_id, + trait_def_id, + new_generics ); new_generics @@ -139,7 +144,7 @@ where let ty = tcx.type_of(item_def_id); let f = auto_trait::AutoTraitFinder::new(tcx); - debug!("get_auto_trait_impls({:?})", ty); + tracing::debug!("get_auto_trait_impls({:?})", ty); let auto_traits: Vec<_> = self.cx.auto_traits.iter().copied().collect(); let mut auto_traits: Vec = auto_traits .into_iter() @@ -432,10 +437,12 @@ where mut existing_predicates: Vec, vid_to_region: FxHashMap>, ) -> Generics { - debug!( + tracing::debug!( "param_env_to_generics(item_def_id={:?}, param_env={:?}, \ existing_predicates={:?})", - item_def_id, param_env, existing_predicates + item_def_id, + param_env, + existing_predicates ); let tcx = self.cx.tcx; @@ -466,7 +473,11 @@ where ); let mut generic_params = raw_generics.params; - debug!("param_env_to_generics({:?}): generic_params={:?}", item_def_id, generic_params); + tracing::debug!( + "param_env_to_generics({:?}): generic_params={:?}", + item_def_id, + generic_params + ); let mut has_sized = FxHashSet::default(); let mut ty_to_bounds: FxHashMap<_, FxHashSet<_>> = Default::default(); diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index 7c59e785752dc..4efa4d7023445 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -17,7 +17,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> { let param_env = cx.tcx.param_env(item_def_id); let ty = cx.tcx.bound_type_of(item_def_id); - trace!("get_blanket_impls({:?})", ty); + tracing::trace!("get_blanket_impls({:?})", ty); let mut impls = Vec::new(); for trait_def_id in cx.tcx.all_traits() { if !cx.cache.access_levels.is_public(trait_def_id) @@ -28,7 +28,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> { // NOTE: doesn't use `for_each_relevant_impl` to avoid looking at anything besides blanket impls let trait_impls = cx.tcx.trait_impls_of(trait_def_id); 'blanket_impls: for &impl_def_id in trait_impls.blanket_impls() { - trace!( + tracing::trace!( "get_blanket_impls: Considering impl for trait '{:?}' {:?}", trait_def_id, impl_def_id @@ -74,7 +74,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> { .to_predicate(infcx.tcx), )); for predicate in predicates { - debug!("testing predicate {:?}", predicate); + tracing::debug!("testing predicate {:?}", predicate); let obligation = traits::Obligation::new( traits::ObligationCause::dummy(), param_env, diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 432d318907fa0..ede6621d84569 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -54,7 +54,7 @@ pub(crate) fn try_inline( } let mut ret = Vec::new(); - debug!("attrs={:?}", attrs); + tracing::debug!("attrs={:?}", attrs); let attrs_clone = attrs; let kind = match res { @@ -493,9 +493,9 @@ pub(crate) fn build_impl( } let (merged_attrs, cfg) = merge_attrs(cx, parent_module, load_attrs(cx, did), attrs); - trace!("merged_attrs={:?}", merged_attrs); + tracing::trace!("merged_attrs={:?}", merged_attrs); - trace!( + tracing::trace!( "build_impl: impl {:?} for {:?}", trait_.as_ref().map(|t| t.def_id()), for_.def_id(&cx.cache) @@ -715,7 +715,7 @@ pub(crate) fn record_extern_trait(cx: &mut DocContext<'_>, did: DefId) { cx.active_extern_traits.insert(did); } - debug!("record_extern_trait: {:?}", did); + tracing::debug!("record_extern_trait: {:?}", did); let trait_ = build_external_trait(cx, did); cx.external_traits.borrow_mut().insert(did, trait_); diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index d86a268264164..a3917c247a602 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -166,7 +166,7 @@ pub(crate) fn clean_trait_ref_with_bindings<'tcx>( inline::record_extern_fqn(cx, trait_ref.def_id, kind); let path = external_path(cx, trait_ref.def_id, true, bindings, trait_ref.substs); - debug!("ty::TraitRef\n subst: {:?}\n", trait_ref.substs); + tracing::debug!("ty::TraitRef\n subst: {:?}\n", trait_ref.substs); path } @@ -249,7 +249,7 @@ pub(crate) fn clean_middle_region<'tcx>(region: ty::Region<'tcx>) -> Option { - debug!("cannot clean region {:?}", region); + tracing::debug!("cannot clean region {:?}", region); None } } @@ -1587,11 +1587,11 @@ fn normalize<'tcx>(cx: &mut DocContext<'tcx>, ty: Ty<'tcx>) -> Option> .map(|resolved| infcx.resolve_vars_if_possible(resolved.value)); match normalized { Ok(normalized_value) => { - debug!("normalized {:?} to {:?}", ty, normalized_value); + tracing::debug!("normalized {:?} to {:?}", ty, normalized_value); Some(normalized_value) } Err(err) => { - debug!("failed to normalize {:?}: {:?}", ty, err); + tracing::debug!("failed to normalize {:?}: {:?}", ty, err); None } } @@ -1602,7 +1602,7 @@ pub(crate) fn clean_middle_ty<'tcx>( cx: &mut DocContext<'tcx>, def_id: Option, ) -> Type { - trace!("cleaning type: {:?}", ty); + tracing::trace!("cleaning type: {:?}", ty); let ty = normalize(cx, ty).unwrap_or(ty); match *ty.kind() { ty::Never => Primitive(PrimitiveType::Never), diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 4c130b2ffec75..45018c7800bef 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -475,7 +475,7 @@ impl Item { cx: &mut DocContext<'_>, cfg: Option>, ) -> Item { - trace!("name={:?}, def_id={:?} cfg={:?}", name, def_id, cfg); + tracing::trace!("name={:?}, def_id={:?} cfg={:?}", name, def_id, cfg); // Primitives and Keywords are written in the source code as private modules. // The modules need to be private so that nobody actually uses them, but the @@ -504,9 +504,9 @@ impl Item { .map_or(&[][..], |v| v.as_slice()) .iter() .filter_map(|ItemLink { link: s, link_text, page_id: did, ref fragment }| { - debug!(?did); + tracing::debug!(?did); if let Ok((mut href, ..)) = href(*did, cx) { - debug!(?href); + tracing::debug!(?href); if let Some(ref fragment) = *fragment { fragment.render(&mut href, cx.tcx()) } @@ -1197,7 +1197,7 @@ impl Attributes { let mut other_attrs = ast::AttrVec::new(); for (attr, parent_module) in attrs { if let Some((doc_str, comment_kind)) = attr.doc_str_and_comment_kind() { - trace!("got doc_str={doc_str:?}"); + tracing::trace!("got doc_str={doc_str:?}"); let doc = beautify_doc_string(doc_str, comment_kind); let kind = if attr.is_doc_comment() { DocFragmentKind::SugaredDoc @@ -1929,7 +1929,7 @@ impl PrimitiveType { for &crate_num in tcx.crates(()) { let e = ExternalCrate { crate_num }; let crate_name = e.name(tcx); - debug!(?crate_num, ?crate_name); + tracing::debug!(?crate_num, ?crate_name); for &(def_id, prim) in &e.primitives(tcx) { // HACK: try to link to std instead where possible if crate_name == sym::core && primitive_locations.contains_key(&prim) { diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 4572a712258ab..1bf904abe8830 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -201,7 +201,7 @@ pub(crate) fn build_deref_target_impls( pub(crate) fn name_from_pat(p: &hir::Pat<'_>) -> Symbol { use rustc_hir::*; - debug!("trying to get a name from pattern: {:?}", p); + tracing::debug!("trying to get a name from pattern: {:?}", p); Symbol::intern(&match p.kind { PatKind::Wild | PatKind::Struct(..) => return kw::Underscore, @@ -217,7 +217,7 @@ pub(crate) fn name_from_pat(p: &hir::Pat<'_>) -> Symbol { PatKind::Box(p) => return name_from_pat(&*p), PatKind::Ref(p, _) => return name_from_pat(&*p), PatKind::Lit(..) => { - warn!( + tracing::warn!( "tried to get argument name from PatKind::Lit, which is silly in function arguments" ); return Symbol::intern("()"); @@ -450,7 +450,7 @@ pub(crate) fn print_const_expr(tcx: TyCtxt<'_>, body: hir::BodyId) -> String { /// Given a type Path, resolve it to a Type using the TyCtxt pub(crate) fn resolve_type(cx: &mut DocContext<'_>, path: Path) -> Type { - debug!("resolve_type({:?})", path); + tracing::debug!("resolve_type({:?})", path); match path.res { Res::PrimTy(p) => Primitive(PrimitiveType::from(p)), @@ -489,7 +489,7 @@ pub(crate) fn get_auto_trait_and_blanket_impls( /// [`href()`]: crate::html::format::href pub(crate) fn register_res(cx: &mut DocContext<'_>, res: Res) -> DefId { use DefKind::*; - debug!("register_res({:?})", res); + tracing::debug!("register_res({:?})", res); let (kind, did) = match res { Res::Def( diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 8232353f915b9..f1e3dd48a1981 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -304,7 +304,7 @@ pub(crate) fn create_config( let hir = tcx.hir(); let body = hir.body(hir.body_owned_by(def_id)); - debug!("visiting body for {:?}", def_id); + tracing::debug!("visiting body for {:?}", def_id); EmitIgnoredResolutionErrors::new(tcx).visit_body(body); (rustc_interface::DEFAULT_QUERY_PROVIDERS.typeck)(tcx, def_id) }; @@ -376,7 +376,7 @@ pub(crate) fn run_global_ctxt( ctxt.external_traits.borrow_mut().insert(sized_trait_did, sized_trait); } - debug!("crate: {:?}", tcx.hir().krate()); + tracing::debug!("crate: {:?}", tcx.hir().krate()); let mut krate = tcx.sess.time("clean_crate", || clean::krate(&mut ctxt)); @@ -439,7 +439,7 @@ pub(crate) fn run_global_ctxt( } } - info!("Executing passes"); + tracing::info!("Executing passes"); for p in passes::defaults(show_coverage) { let run = match p.condition { @@ -449,7 +449,7 @@ pub(crate) fn run_global_ctxt( WhenNotDocumentHidden => !ctxt.render_options.document_hidden, }; if run { - debug!("running pass {}", p.pass.name); + tracing::debug!("running pass {}", p.pass.name); krate = tcx.sess.time(p.pass.name, || (p.pass.run)(krate, &mut ctxt)); } } @@ -489,7 +489,7 @@ impl<'tcx> Visitor<'tcx> for EmitIgnoredResolutionErrors<'tcx> { } fn visit_path(&mut self, path: &'tcx Path<'_>, _id: HirId) { - debug!("visiting path {:?}", path); + tracing::debug!("visiting path {:?}", path); if path.res == Res::Err { // We have less context here than in rustc_resolve, // so we can only emit the name and span. diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index db70029f6ec59..f065dceefa406 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -66,7 +66,7 @@ pub(crate) fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> { } }); - debug!(?lint_opts); + tracing::debug!(?lint_opts); let crate_types = if options.proc_macro_crate { vec![CrateType::ProcMacro] } else { vec![CrateType::Rlib] }; @@ -715,7 +715,7 @@ pub(crate) fn make_test( prog.extend([&main_pre, everything_else, &main_post].iter().cloned()); } - debug!("final doctest:\n{prog}"); + tracing::debug!("final doctest:\n{prog}"); (prog, line_offset, supports_color) } @@ -756,7 +756,7 @@ fn check_if_attr_is_complete(source: &str, edition: Edition) -> bool { match maybe_new_parser_from_source_str(&sess, filename, source.to_owned()) { Ok(p) => p, Err(_) => { - debug!("Cannot build a parser to check mod attr so skipping..."); + tracing::debug!("Cannot build a parser to check mod attr so skipping..."); return true; } }; @@ -865,9 +865,9 @@ fn partition_source(s: &str, edition: Edition) -> (String, String, String) { } } - debug!("before:\n{before}"); - debug!("crates:\n{crates}"); - debug!("after:\n{after}"); + tracing::debug!("before:\n{before}"); + tracing::debug!("crates:\n{crates}"); + tracing::debug!("after:\n{after}"); (before, after, crates) } @@ -1044,7 +1044,7 @@ impl Tester for Collector { ) }; - debug!("creating test {name}: {test}"); + tracing::debug!("creating test {name}: {test}"); self.tests.push(test::TestDescAndFn { desc: test::TestDesc { name: test::DynTestName(name), diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs index 2e428cfddcf0a..d7c3edf9c7d1b 100644 --- a/src/librustdoc/formats/cache.rs +++ b/src/librustdoc/formats/cache.rs @@ -142,7 +142,7 @@ impl Cache { let tcx = cx.tcx; // Crawl the crate to build various caches used for the output - debug!(?cx.cache.crate_version); + tracing::debug!(?cx.cache.crate_version); cx.cache.traits = krate.external_traits.take(); // Cache where all our extern crates are located @@ -195,7 +195,7 @@ impl Cache { impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> { fn fold_item(&mut self, item: clean::Item) -> Option { if item.item_id.is_local() { - debug!("folding {} \"{:?}\", id {:?}", item.type_(), item.name, item.item_id); + tracing::debug!("folding {} \"{:?}\", id {:?}", item.type_(), item.name, item.item_id); } // If this is a stripped module, diff --git a/src/librustdoc/formats/renderer.rs b/src/librustdoc/formats/renderer.rs index 6f9cc026675b6..bf866989f6df3 100644 --- a/src/librustdoc/formats/renderer.rs +++ b/src/librustdoc/formats/renderer.rs @@ -80,7 +80,7 @@ pub(crate) fn run_format<'tcx, T: FormatRenderer<'tcx>>( let (clean::StrippedItem(box clean::ModuleItem(module)) | clean::ModuleItem(module)) = *item.kind else { unreachable!() }; for it in module.items { - debug!("Adding {:?} to worklist", it.name); + tracing::debug!("Adding {:?} to worklist", it.name); work.push((cx.make_child_renderer(), it)); } diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 7d00002d05bee..a29c3c4c3aaf2 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -592,7 +592,7 @@ fn generate_macro_def_id_path( let cstore = CStore::from_tcx(tcx); // We need this to prevent a `panic` when this function is used from intra doc links... if !cstore.has_crate_data(def_id.krate) { - debug!("No data for crate {}", crate_name); + tracing::debug!("No data for crate {}", crate_name); return Err(HrefError::NotInExternalCache); } // Check to see if it is a macro 2.0 or built-in macro. @@ -613,7 +613,7 @@ fn generate_macro_def_id_path( if path.len() < 2 { // The minimum we can have is the crate name followed by the macro name. If shorter, then // it means that `relative` was empty, which is an error. - debug!("macro path cannot be empty!"); + tracing::debug!("macro path cannot be empty!"); return Err(HrefError::NotInExternalCache); } @@ -631,7 +631,7 @@ fn generate_macro_def_id_path( format!("{}{}/{}", root_path.unwrap_or(""), crate_name, path.join("/")) } ExternalLocation::Unknown => { - debug!("crate {} not in cache when linkifying macros", crate_name); + tracing::debug!("crate {} not in cache when linkifying macros", crate_name); return Err(HrefError::NotInExternalCache); } }; @@ -670,7 +670,7 @@ pub(crate) fn href_with_root_path( let (fqp, shortty, mut url_parts) = match cache.paths.get(&did) { Some(&(ref fqp, shortty)) => (fqp, shortty, { let module_fqp = to_module_fqp(shortty, fqp.as_slice()); - debug!(?fqp, ?shortty, ?module_fqp); + tracing::debug!(?fqp, ?shortty, ?module_fqp); href_relative_parts(module_fqp, relative_to).collect() }), None => { @@ -706,7 +706,7 @@ pub(crate) fn href_with_root_path( url_parts.push_front(root); } } - debug!(?url_parts); + tracing::debug!(?url_parts); match shortty { ItemType::Module => { url_parts.push("index.html"); @@ -918,7 +918,7 @@ fn fmt_type<'cx>( use_absolute: bool, cx: &'cx Context<'_>, ) -> fmt::Result { - trace!("fmt_type(t = {:?})", t); + tracing::trace!("fmt_type(t = {:?})", t); match *t { clean::Generic(name) => write!(f, "{}", name), @@ -1450,7 +1450,7 @@ impl clean::Visibility { "pub(super) ".into() } else { let path = cx.tcx().def_path(vis_did); - debug!("path={:?}", path); + tracing::debug!("path={:?}", path); // modified from `resolved_path()` to work with `DefPathData` let last_name = path.data.last().unwrap().data.get_opt_name().unwrap(); let anchor = anchor(vis_did, last_name, cx).to_string(); diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 5ce62224d35e5..f8bbff6981627 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -380,14 +380,14 @@ impl<'a, I: Iterator>> Iterator for LinkReplacer<'a, I> { dest, title, ))) => { - debug!("saw start of shortcut link to {} with title {}", dest, title); + tracing::debug!("saw start of shortcut link to {} with title {}", dest, title); // If this is a shortcut link, it was resolved by the broken_link_callback. // So the URL will already be updated properly. let link = self.links.iter().find(|&link| *link.href == **dest); // Since this is an external iterator, we can't replace the inner text just yet. // Store that we saw a link so we know to replace it later. if let Some(link) = link { - trace!("it matched"); + tracing::trace!("it matched"); assert!(self.shortcut_link.is_none(), "shortcut links cannot be nested"); self.shortcut_link = Some(link); } @@ -398,7 +398,7 @@ impl<'a, I: Iterator>> Iterator for LinkReplacer<'a, I> { dest, _, ))) => { - debug!("saw end of shortcut link to {}", dest); + tracing::debug!("saw end of shortcut link to {}", dest); if self.links.iter().any(|link| *link.href == **dest) { assert!(self.shortcut_link.is_some(), "saw closing link without opening tag"); self.shortcut_link = None; @@ -407,9 +407,9 @@ impl<'a, I: Iterator>> Iterator for LinkReplacer<'a, I> { // Handle backticks in inline code blocks, but only if we're in the middle of a shortcut link. // [`fn@f`] Some(Event::Code(text)) => { - trace!("saw code {}", text); + tracing::trace!("saw code {}", text); if let Some(link) = self.shortcut_link { - trace!("original text was {}", link.original_text); + tracing::trace!("original text was {}", link.original_text); // NOTE: this only replaces if the code block is the *entire* text. // If only part of the link has code highlighting, the disambiguator will not be removed. // e.g. [fn@`f`] @@ -420,7 +420,7 @@ impl<'a, I: Iterator>> Iterator for LinkReplacer<'a, I> { // // NOTE: &[1..len() - 1] is to strip the backticks if **text == link.original_text[1..link.original_text.len() - 1] { - debug!("replacing {} with {}", text, link.new_text); + tracing::debug!("replacing {} with {}", text, link.new_text); *text = CowStr::Borrowed(&link.new_text); } } @@ -428,12 +428,12 @@ impl<'a, I: Iterator>> Iterator for LinkReplacer<'a, I> { // Replace plain text in links, but only in the middle of a shortcut link. // [fn@f] Some(Event::Text(text)) => { - trace!("saw text {}", text); + tracing::trace!("saw text {}", text); if let Some(link) = self.shortcut_link { - trace!("original text was {}", link.original_text); + tracing::trace!("original text was {}", link.original_text); // NOTE: same limitations as `Event::Code` if **text == *link.original_text { - debug!("replacing {} with {}", text, link.new_text); + tracing::debug!("replacing {} with {}", text, link.new_text); *text = CowStr::Borrowed(&link.new_text); } } @@ -1320,7 +1320,7 @@ pub(crate) fn markdown_links( _, )) = ev.0 { - debug!("found link: {dest}"); + tracing::debug!("found link: {dest}"); let span = span_for_link(&dest, ev.1); filter_map(MarkdownLink { kind, link: dest.into_string(), range: span }) .map(|link| links.borrow_mut().push(link)); diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index 5733d1f9c79d6..1c3da6a4f04c3 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -742,7 +742,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { self.dst.push(&*item_name.as_str()); self.current.push(item_name); - info!("Recursing into {}", self.dst.display()); + tracing::info!("Recursing into {}", self.dst.display()); let buf = self.render_item(item, true); // buf will be empty if the module is stripped and there is no redirect for it @@ -765,7 +765,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { } fn mod_item_out(&mut self) -> Result<(), Error> { - info!("Recursed; leaving {}", self.dst.display()); + tracing::info!("Recursed; leaving {}", self.dst.display()); // Go back to where we were at self.dst.pop(); diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index eeec6f8fee778..15b6ae1888435 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -418,7 +418,7 @@ fn document( heading_offset: HeadingOffset, ) { if let Some(ref name) = item.name { - info!("Documenting {}", name); + tracing::info!("Documenting {}", name); } document_item_info(w, cx, item, parent); if parent.is_none() { @@ -509,7 +509,7 @@ fn document_full_inner( heading_offset: HeadingOffset, ) { if let Some(s) = item.collapsed_doc_value() { - debug!("Doc block: =====\n{}\n=====", s); + tracing::debug!("Doc block: =====\n{}\n=====", s); if is_collapsible { w.write_str( "
\ @@ -560,7 +560,7 @@ fn portability(item: &clean::Item, parent: Option<&clean::Item>) -> Option cfg.as_deref().cloned(), }; - debug!( + tracing::debug!( "Portability {:?} {:?} (parent: {:?}) - {:?} = {:?}", item.name, item.cfg, @@ -1123,7 +1123,7 @@ fn render_assoc_items_inner( what: AssocItemRender<'_>, derefs: &mut FxHashSet, ) { - info!("Documenting associated items of {:?}", containing_item.name); + tracing::info!("Documenting associated items of {:?}", containing_item.name); let shared = Rc::clone(&cx.shared); let cache = &shared.cache; let Some(v) = cache.impls.get(&it) else { return }; @@ -1226,7 +1226,11 @@ fn render_deref_methods( _ => None, }) .expect("Expected associated type binding"); - debug!("Render deref methods for {:#?}, target {:#?}", impl_.inner_impl().for_, target); + tracing::debug!( + "Render deref methods for {:#?}, target {:#?}", + impl_.inner_impl().for_, + target + ); let what = AssocItemRender::DerefFor { trait_: deref_type, type_: real_target, deref_mut_: deref_mut }; if let Some(did) = target.def_id(cache) { @@ -2142,7 +2146,7 @@ fn sidebar_deref_methods( ) { let c = cx.cache(); - debug!("found Deref: {:?}", impl_); + tracing::debug!("found Deref: {:?}", impl_); if let Some((target, real_target)) = impl_.inner_impl().items.iter().find_map(|item| match *item.kind { clean::AssocTypeItem(box ref t, _) => Some(match *t { @@ -2152,7 +2156,7 @@ fn sidebar_deref_methods( _ => None, }) { - debug!("found target, real_target: {:?} {:?}", target, real_target); + tracing::debug!("found target, real_target: {:?} {:?}", target, real_target); if let Some(did) = target.def_id(c) { if let Some(type_did) = impl_.inner_impl().for_.def_id(c) { // `impl Deref for S` @@ -2170,7 +2174,7 @@ fn sidebar_deref_methods( }) .and_then(|did| c.impls.get(&did)); if let Some(impls) = inner_impl { - debug!("found inner_impl: {:?}", impls); + tracing::debug!("found inner_impl: {:?}", impls); let mut ret = impls .iter() .filter(|i| i.inner_impl().trait_.is_none()) diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 6327817364a55..23e8e7b1a57a0 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -292,7 +292,7 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items: ) }); - debug!("{:?}", indices); + tracing::debug!("{:?}", indices); let mut last_section = None; for &idx in &indices { @@ -487,7 +487,13 @@ fn extra_info_tags(item: &clean::Item, parent: &clean::Item, tcx: TyCtxt<'_>) -> (cfg, _) => cfg.as_deref().cloned(), }; - debug!("Portability name={:?} {:?} - {:?} = {:?}", item.name, item.cfg, parent.cfg, cfg); + tracing::debug!( + "Portability name={:?} {:?} - {:?} = {:?}", + item.name, + item.cfg, + parent.cfg, + cfg + ); if let Some(ref cfg) = cfg { tags += &tag_html("portability", &cfg.render_long_plain(), &cfg.render_short_html()); } @@ -709,7 +715,7 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean: fn trait_item(w: &mut Buffer, cx: &mut Context<'_>, m: &clean::Item, t: &clean::Item) { let name = m.name.unwrap(); - info!("Documenting {} on {:?}", name, t.name); + tracing::info!("Documenting {} on {:?}", name, t.name); let item_type = m.type_(); let id = cx.derive_id(format!("{}.{}", item_type, name)); let mut content = Buffer::empty_from(w); diff --git a/src/librustdoc/html/render/search_index.rs b/src/librustdoc/html/render/search_index.rs index 8eb9c07f8a796..779527085dc5b 100644 --- a/src/librustdoc/html/render/search_index.rs +++ b/src/librustdoc/html/render/search_index.rs @@ -347,7 +347,7 @@ fn get_index_type_id(clean_type: &clean::Type) -> Option { /// /// Important note: It goes through generics recursively. So if you have /// `T: Option>`, it'll go into `Option` and then into `Result`. -#[instrument(level = "trace", skip(tcx, res, cache))] +#[tracing::instrument(level = "trace", skip(tcx, res, cache))] fn add_generics_and_bounds_as_types<'tcx, 'a>( self_: Option<&'a Type>, generics: &Generics, diff --git a/src/librustdoc/html/sources.rs b/src/librustdoc/html/sources.rs index 7ab65bff3469f..f52af9e3cb31f 100644 --- a/src/librustdoc/html/sources.rs +++ b/src/librustdoc/html/sources.rs @@ -19,7 +19,7 @@ use std::path::{Component, Path, PathBuf}; use std::rc::Rc; pub(crate) fn render(cx: &mut Context<'_>, krate: &clean::Crate) -> Result<(), Error> { - info!("emitting source files"); + tracing::info!("emitting source files"); let dst = cx.dst.join("src").join(krate.name(cx.tcx()).as_str()); cx.shared.ensure_dir(&dst)?; diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index d13efe6c113be..87a700540bf0c 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -101,7 +101,7 @@ impl<'tcx> JsonRenderer<'tcx> { } fn get_trait_items(&mut self) -> Vec<(types::Id, types::Item)> { - debug!("Adding foreign trait items"); + tracing::debug!("Adding foreign trait items"); Rc::clone(&self.cache) .traits .iter() @@ -109,7 +109,7 @@ impl<'tcx> JsonRenderer<'tcx> { // only need to synthesize items for external traits if !id.is_local() { for item in &trait_item.items { - trace!("Adding subitem to {id:?}: {:?}", item.item_id); + tracing::trace!("Adding subitem to {id:?}: {:?}", item.item_id); self.item(item.clone()).unwrap(); } let item_id = from_item_id(id.into(), self.tcx); @@ -161,7 +161,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { cache: Cache, tcx: TyCtxt<'tcx>, ) -> Result<(Self, clean::Crate), Error> { - debug!("Initializing json renderer"); + tracing::debug!("Initializing json renderer"); let (krate, imported_items) = import_finder::get_imports(krate); @@ -187,7 +187,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { fn item(&mut self, item: clean::Item) -> Result<(), Error> { let item_type = item.type_(); let item_name = item.name; - trace!("rendering {} {:?}", item_type, item_name); + tracing::trace!("rendering {} {:?}", item_type, item_name); // Flatten items that recursively store other items. We include orphaned items from // stripped modules and etc that are otherwise reachable. @@ -259,7 +259,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { } } - trace!("done rendering {} {:?}", item_type, item_name); + tracing::trace!("done rendering {} {:?}", item_type, item_name); Ok(()) } @@ -268,9 +268,9 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { } fn after_krate(&mut self) -> Result<(), Error> { - debug!("Done with crate"); + tracing::debug!("Done with crate"); - debug!("Adding Primitve impls"); + tracing::debug!("Adding Primitve impls"); for primitive in Rc::clone(&self.cache).primitive_locations.values() { self.get_impls(*primitive); } @@ -283,7 +283,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { let mut index = (*self.index).clone().into_inner(); index.extend(foreign_trait_items); - debug!("Constructing Output"); + tracing::debug!("Constructing Output"); // This needs to be the default HashMap for compatibility with the public interface for // rustdoc-json-types #[allow(rustc::default_hash_types)] diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 4cf9435d9c8ee..89cdb32c31845 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -20,8 +20,8 @@ #![allow(clippy::collapsible_if, clippy::collapsible_else_if)] #![allow(rustc::potential_query_instability)] -#[macro_use] -extern crate tracing; +// #[macro_use] +// extern crate tracing; // N.B. these need `extern crate` even in 2018 edition // because they're loaded implicitly from the sysroot. @@ -764,7 +764,7 @@ fn main_args(at_args: &[String]) -> MainResult { let run_check = options.run_check; // First, parse the crate and extract all relevant information. - info!("starting to run rustc"); + tracing::info!("starting to run rustc"); // Interpret the input file as a rust source file, passing it through the // compiler all the way through the analysis passes. The rustdoc output is @@ -833,7 +833,7 @@ fn main_args(at_args: &[String]) -> MainResult { output_format, ) }); - info!("finished with rustc"); + tracing::info!("finished with rustc"); if let Some(options) = scrape_examples_options { return scrape_examples::run(krate, render_opts, cache, tcx, options); @@ -850,7 +850,7 @@ fn main_args(at_args: &[String]) -> MainResult { return Ok(()); } - info!("going to format"); + tracing::info!("going to format"); match output_format { config::OutputFormat::Html => sess.time("render_html", || { run_renderer::>(krate, render_opts, cache, tcx) diff --git a/src/librustdoc/passes/bare_urls.rs b/src/librustdoc/passes/bare_urls.rs index 7ff3ccef945c2..4224df91df8b4 100644 --- a/src/librustdoc/passes/bare_urls.rs +++ b/src/librustdoc/passes/bare_urls.rs @@ -39,7 +39,7 @@ impl<'a, 'tcx> BareUrlsLinter<'a, 'tcx> { range: Range, f: &impl Fn(&DocContext<'_>, &str, &str, Range), ) { - trace!("looking for raw urls in {}", text); + tracing::trace!("looking for raw urls in {}", text); // For now, we only check "full" URLs (meaning, starting with "http://" or "https://"). for match_ in URL_REGEX.find_iter(text) { let url = match_.as_str(); diff --git a/src/librustdoc/passes/calculate_doc_coverage.rs b/src/librustdoc/passes/calculate_doc_coverage.rs index 48835abf9525b..169a42f1efccf 100644 --- a/src/librustdoc/passes/calculate_doc_coverage.rs +++ b/src/librustdoc/passes/calculate_doc_coverage.rs @@ -262,7 +262,7 @@ impl<'a, 'b> DocVisitor for CoverageCalculator<'a, 'b> { if let Some(span) = i.span(self.ctx.tcx) { let filename = span.filename(self.ctx.sess()); - debug!("counting {:?} {:?} in {:?}", i.type_(), i.name, filename); + tracing::debug!("counting {:?} {:?} in {:?}", i.type_(), i.name, filename); self.items.entry(filename).or_default().count_item( has_docs, has_doc_example, diff --git a/src/librustdoc/passes/check_doc_test_visibility.rs b/src/librustdoc/passes/check_doc_test_visibility.rs index 15982b40944e7..6314bad0a263c 100644 --- a/src/librustdoc/passes/check_doc_test_visibility.rs +++ b/src/librustdoc/passes/check_doc_test_visibility.rs @@ -119,7 +119,7 @@ pub(crate) fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item if tests.found_tests == 0 && cx.tcx.features().rustdoc_missing_doc_code_examples { if should_have_doc_example(cx, item) { - debug!("reporting error for {:?} (hir_id={:?})", item, hir_id); + tracing::debug!("reporting error for {:?} (hir_id={:?})", item, hir_id); let sp = item.attr_span(cx.tcx); cx.tcx.struct_span_lint_hir( crate::lint::MISSING_DOC_CODE_EXAMPLES, diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 3513c13d522f1..2166b928e7be0 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -316,7 +316,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { unresolved: path_str.into(), }; - debug!("looking for enum variant {}", path_str); + tracing::debug!("looking for enum variant {}", path_str); let mut split = path_str.rsplitn(3, "::"); let variant_field_name = split .next() @@ -438,7 +438,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { }) .and_then(|res| res.try_into().ok()) .or_else(|| resolve_primitive(path_str, ns)); - debug!("{} resolved to {:?} in namespace {:?}", path_str, result, ns); + tracing::debug!("{} resolved to {:?} in namespace {:?}", path_str, result, ns); result } @@ -480,7 +480,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { // If there's no `::`, it's not an associated item. // So we can be sure that `rustc_resolve` was accurate when it said it wasn't resolved. .ok_or_else(|| { - debug!("found no `::`, assuming {} was correctly not in scope", item_name); + tracing::debug!("found no `::`, assuming {} was correctly not in scope", item_name); UnresolvedPath { item_id, module_id, @@ -616,7 +616,11 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { def_kind @ (DefKind::Struct | DefKind::Union | DefKind::Enum | DefKind::ForeignTy), did, ) => { - debug!("looking for associated item named {} for item {:?}", item_name, did); + tracing::debug!( + "looking for associated item named {} for item {:?}", + item_name, + did + ); // Checks if item_name is a variant of the `SomeItem` enum if ns == TypeNS && def_kind == DefKind::Enum { match tcx.type_of(did).kind() { @@ -661,7 +665,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { ) }); - debug!("got associated item {:?}", assoc_item); + tracing::debug!("got associated item {:?}", assoc_item); if let Some(item) = assoc_item { return Some((root_res, item.def_id)); @@ -670,7 +674,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { if ns != Namespace::ValueNS { return None; } - debug!("looking for fields named {} for {:?}", item_name, did); + tracing::debug!("looking for fields named {} for {:?}", item_name, did); // FIXME: this doesn't really belong in `associated_item` (maybe `variant_field` is better?) // NOTE: it's different from variant_field because it only resolves struct fields, // not variant fields (2 path segments, not 3). @@ -729,7 +733,7 @@ fn resolve_associated_trait_item<'a>( // Next consider explicit impls: `impl MyTrait for MyType` // Give precedence to inherent impls. let traits = trait_impls_for(cx, ty, module); - debug!("considering traits {:?}", traits); + tracing::debug!("considering traits {:?}", traits); let mut candidates = traits.iter().filter_map(|&(impl_, trait_)| { cx.tcx .associated_items(trait_) @@ -740,7 +744,7 @@ fn resolve_associated_trait_item<'a>( }) }); // FIXME(#74563): warn about ambiguity - debug!("the candidates were {:?}", candidates.clone().collect::>()); + tracing::debug!("the candidates were {:?}", candidates.clone().collect::>()); candidates.next().copied() } @@ -753,16 +757,16 @@ fn resolve_associated_trait_item<'a>( /// /// This is just a wrapper around [`TyCtxt::impl_item_implementor_ids()`] and /// [`TyCtxt::associated_item()`] (with some helpful logging added). -#[instrument(level = "debug", skip(tcx), ret)] +#[tracing::instrument(level = "debug", skip(tcx), ret)] fn trait_assoc_to_impl_assoc_item<'tcx>( tcx: TyCtxt<'tcx>, impl_id: DefId, trait_assoc_id: DefId, ) -> Option<&'tcx ty::AssocItem> { let trait_to_impl_assoc_map = tcx.impl_item_implementor_ids(impl_id); - debug!(?trait_to_impl_assoc_map); + tracing::debug!(?trait_to_impl_assoc_map); let impl_assoc_id = *trait_to_impl_assoc_map.get(&trait_assoc_id)?; - debug!(?impl_assoc_id); + tracing::debug!(?impl_assoc_id); Some(tcx.associated_item(impl_assoc_id)) } @@ -771,7 +775,7 @@ fn trait_assoc_to_impl_assoc_item<'tcx>( /// /// NOTE: this cannot be a query because more traits could be available when more crates are compiled! /// So it is not stable to serialize cross-crate. -#[instrument(level = "debug", skip(cx))] +#[tracing::instrument(level = "debug", skip(cx))] fn trait_impls_for<'a>( cx: &mut DocContext<'a>, ty: Ty<'a>, @@ -780,14 +784,14 @@ fn trait_impls_for<'a>( let tcx = cx.tcx; let iter = cx.resolver_caches.traits_in_scope[&module].iter().flat_map(|trait_candidate| { let trait_ = trait_candidate.def_id; - trace!("considering explicit impl for trait {:?}", trait_); + tracing::trace!("considering explicit impl for trait {:?}", trait_); // Look at each trait implementation to see if it's an impl for `did` tcx.find_map_relevant_impl(trait_, ty, |impl_| { let trait_ref = tcx.impl_trait_ref(impl_).expect("this is not an inherent impl"); // Check if these are the same type. let impl_type = trait_ref.self_ty(); - trace!( + tracing::trace!( "comparing type {} with kind {:?} against type {:?}", impl_type, impl_type.kind(), @@ -801,7 +805,11 @@ fn trait_impls_for<'a>( let saw_impl = impl_type == ty || match (impl_type.kind(), ty.kind()) { (ty::Adt(impl_def, _), ty::Adt(ty_def, _)) => { - debug!("impl def_id: {:?}, ty def_id: {:?}", impl_def.did(), ty_def.did()); + tracing::debug!( + "impl def_id: {:?}, ty def_id: {:?}", + impl_def.did(), + ty_def.did() + ); impl_def.did() == ty_def.did() } _ => false, @@ -832,7 +840,12 @@ impl<'a, 'tcx> DocVisitor for LinkCollector<'a, 'tcx> { let parent_node = item.item_id.as_def_id().and_then(|did| find_nearest_parent_module(self.cx.tcx, did)); if parent_node.is_some() { - trace!("got parent node for {:?} {:?}, id {:?}", item.type_(), item.name, item.item_id); + tracing::trace!( + "got parent node for {:?} {:?}, id {:?}", + item.type_(), + item.name, + item.item_id + ); } let inner_docs = item.inner_docs(self.cx.tcx); @@ -849,7 +862,7 @@ impl<'a, 'tcx> DocVisitor for LinkCollector<'a, 'tcx> { if !may_have_doc_links(&doc) { continue; } - debug!("combined_docs={}", doc); + tracing::debug!("combined_docs={}", doc); // NOTE: if there are links that start in one crate and end in another, this will not resolve them. // This is a degenerate case and it's not supported by rustdoc. let parent_node = parent_module.or(parent_node); @@ -978,7 +991,7 @@ fn preprocess_link( match strip_generics_from_path(path_str) { Ok(path) => path, Err(err) => { - debug!("link has malformed generics: {}", path_str); + tracing::debug!("link has malformed generics: {}", path_str); return Some(Err(PreprocessingError::MalformedGenerics(err, path_str.to_owned()))); } } @@ -1020,7 +1033,7 @@ impl LinkCollector<'_, '_> { link: &PreprocessedMarkdownLink, ) -> Option { let PreprocessedMarkdownLink(pp_link, ori_link) = link; - trace!("considering link '{}'", ori_link.link); + tracing::trace!("considering link '{}'", ori_link.link); let diag_info = DiagnosticInfo { item, @@ -1171,10 +1184,10 @@ impl LinkCollector<'_, '_> { item: &Item, diag_info: &DiagnosticInfo<'_>, ) -> Option<()> { - debug!("intra-doc link to {} resolved to {:?}", path_str, (kind, id)); + tracing::debug!("intra-doc link to {} resolved to {:?}", path_str, (kind, id)); // Disallow e.g. linking to enums with `struct@` - debug!("saw kind {:?} with disambiguator {:?}", kind, disambiguator); + tracing::debug!("saw kind {:?} with disambiguator {:?}", kind, disambiguator); match (kind, disambiguator) { | (DefKind::Const | DefKind::ConstParam | DefKind::AssocConst | DefKind::AnonConst, Some(Disambiguator::Kind(DefKind::Const))) // NOTE: this allows 'method' to mean both normal functions and associated functions @@ -1603,7 +1616,7 @@ fn report_diagnostic( let Some(hir_id) = DocContext::as_local_hir_id(tcx, item.item_id) else { // If non-local, no need to check anything. - info!("ignoring warning from parent crate: {}", msg); + tracing::info!("ignoring warning from parent crate: {}", msg); return; }; @@ -1719,7 +1732,7 @@ fn resolution_failure( name = start; for ns in [TypeNS, ValueNS, MacroNS] { if let Ok(res) = collector.resolve(start, ns, item_id, module_id) { - debug!("found partial_res={:?}", res); + tracing::debug!("found partial_res={:?}", res); *partial_res = Some(full_res(collector.cx.tcx, res)); *unresolved = end.into(); break 'outer; @@ -2065,7 +2078,7 @@ fn resolve_primitive(path_str: &str, ns: Namespace) -> Option { "never" | "!" => Never, _ => return None, }; - debug!("resolved primitives {:?}", prim); + tracing::debug!("resolved primitives {:?}", prim); Some(Res::Primitive(prim)) } @@ -2109,7 +2122,7 @@ fn strip_generics_from_path(path_str: &str) -> Result } _ => segment.push(chr), } - trace!("raw segment: {:?}", segment); + tracing::trace!("raw segment: {:?}", segment); } if !segment.is_empty() { @@ -2119,7 +2132,7 @@ fn strip_generics_from_path(path_str: &str) -> Result } } - debug!("path_str: {:?}\nstripped segments: {:?}", path_str, &stripped_segments); + tracing::debug!("path_str: {:?}\nstripped segments: {:?}", path_str, &stripped_segments); let stripped_path = stripped_segments.join("::"); diff --git a/src/librustdoc/passes/collect_trait_impls.rs b/src/librustdoc/passes/collect_trait_impls.rs index 6b699c7901434..f05133d1fdc42 100644 --- a/src/librustdoc/passes/collect_trait_impls.rs +++ b/src/librustdoc/passes/collect_trait_impls.rs @@ -129,7 +129,7 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) -> type_did: DefId, ) { if let Some(target) = map.get(&type_did) { - debug!("add_deref_target: type {:?}, target {:?}", type_did, target); + tracing::debug!("add_deref_target: type {:?}, target {:?}", type_did, target); if let Some(target_prim) = target.primitive_type() { cleaner.prims.insert(target_prim); } else if let Some(target_did) = target.def_id(&cx.cache) { diff --git a/src/librustdoc/passes/strip_hidden.rs b/src/librustdoc/passes/strip_hidden.rs index 9914edf3036e4..1a1e4098209f1 100644 --- a/src/librustdoc/passes/strip_hidden.rs +++ b/src/librustdoc/passes/strip_hidden.rs @@ -43,7 +43,7 @@ struct Stripper<'a> { impl<'a> DocFolder for Stripper<'a> { fn fold_item(&mut self, i: Item) -> Option { if i.attrs.lists(sym::doc).has_word(sym::hidden) { - debug!("strip_hidden: stripping {:?} {:?}", i.type_(), i.name); + tracing::debug!("strip_hidden: stripping {:?} {:?}", i.type_(), i.name); // Use a dedicated hidden item for fields, variants, and modules. // We need to keep private fields and variants, so that the docs // can show a placeholder "// some variants omitted". We need to keep diff --git a/src/librustdoc/passes/stripper.rs b/src/librustdoc/passes/stripper.rs index a9d768f0149d6..d44b0c2c089d4 100644 --- a/src/librustdoc/passes/stripper.rs +++ b/src/librustdoc/passes/stripper.rs @@ -37,7 +37,7 @@ impl<'a> DocFolder for Stripper<'a> { // We need to recurse into stripped modules to strip things // like impl methods but when doing so we must not add any // items to the `retained` set. - debug!("Stripper: recursing into stripped {:?} {:?}", i.type_(), i.name); + tracing::debug!("Stripper: recursing into stripped {:?} {:?}", i.type_(), i.name); let old = mem::replace(&mut self.update_retained, false); let ret = self.fold_item_recur(i); self.update_retained = old; @@ -66,7 +66,7 @@ impl<'a> DocFolder for Stripper<'a> { if item_id.is_local() && !is_item_reachable(self.is_json_output, self.access_levels, item_id) { - debug!("Stripper: stripping {:?} {:?}", i.type_(), i.name); + tracing::debug!("Stripper: stripping {:?} {:?}", i.type_(), i.name); return None; } } @@ -79,7 +79,7 @@ impl<'a> DocFolder for Stripper<'a> { clean::ModuleItem(..) => { if i.item_id.is_local() && !i.visibility.is_public() { - debug!("Stripper: stripping module {:?}", i.name); + tracing::debug!("Stripper: stripping module {:?}", i.name); let old = mem::replace(&mut self.update_retained, false); let ret = strip_item(self.fold_item_recur(i)); self.update_retained = old; @@ -181,13 +181,13 @@ impl<'a> DocFolder for ImplStripper<'a> { if let Some(did) = imp.for_.def_id(self.cache) { if did.is_local() && !imp.for_.is_assoc_ty() && !self.retained.contains(&did.into()) { - debug!("ImplStripper: impl item for stripped type; removing"); + tracing::debug!("ImplStripper: impl item for stripped type; removing"); return None; } } if let Some(did) = imp.trait_.as_ref().map(|t| t.def_id()) { if did.is_local() && !self.retained.contains(&did.into()) { - debug!("ImplStripper: impl item for stripped trait; removing"); + tracing::debug!("ImplStripper: impl item for stripped trait; removing"); return None; } } @@ -195,7 +195,7 @@ impl<'a> DocFolder for ImplStripper<'a> { for typaram in generics { if let Some(did) = typaram.def_id(self.cache) { if did.is_local() && !self.retained.contains(&did.into()) { - debug!( + tracing::debug!( "ImplStripper: stripped item in trait's generics; removing impl" ); return None; diff --git a/src/librustdoc/scrape_examples.rs b/src/librustdoc/scrape_examples.rs index dfa6ba38b883b..1f5ac8eb2df58 100644 --- a/src/librustdoc/scrape_examples.rs +++ b/src/librustdoc/scrape_examples.rs @@ -155,14 +155,14 @@ where if let Some(ty) = types.node_type_opt(f.hir_id) { (ty, ex.span, f.span) } else { - trace!("node_type_opt({}) = None", f.hir_id); + tracing::trace!("node_type_opt({}) = None", f.hir_id); return; } } hir::ExprKind::MethodCall(path, _, _, call_span) => { let types = tcx.typeck(ex.hir_id.owner.def_id); let Some(def_id) = types.type_dependent_def_id(ex.hir_id) else { - trace!("type_dependent_def_id({}) = None", ex.hir_id); + tracing::trace!("type_dependent_def_id({}) = None", ex.hir_id); return; }; @@ -177,7 +177,7 @@ where // If this span comes from a macro expansion, then the source code may not actually show // a use of the given item, so it would be a poor example. Hence, we skip all uses in macros. if call_span.from_expansion() { - trace!("Rejecting expr from macro: {call_span:?}"); + tracing::trace!("Rejecting expr from macro: {call_span:?}"); return; } @@ -186,14 +186,16 @@ where let enclosing_item_span = tcx.hir().span_with_body(tcx.hir().get_parent_item(ex.hir_id).into()); if enclosing_item_span.from_expansion() { - trace!("Rejecting expr ({call_span:?}) from macro item: {enclosing_item_span:?}"); + tracing::trace!( + "Rejecting expr ({call_span:?}) from macro item: {enclosing_item_span:?}" + ); return; } // If the enclosing item doesn't actually enclose the call, this means we probably have a weird // macro issue even though the spans aren't tagged as being from an expansion. if !enclosing_item_span.contains(call_span) { - warn!( + tracing::warn!( "Attempted to scrape call at [{call_span:?}] whose enclosing item [{enclosing_item_span:?}] doesn't contain the span of the call." ); return; @@ -201,7 +203,7 @@ where // Similarly for the call w/ the function ident. if !call_span.contains(ident_span) { - warn!( + tracing::warn!( "Attempted to scrape call at [{call_span:?}] whose identifier [{ident_span:?}] was not contained in the span of the call." ); return; @@ -210,7 +212,7 @@ where // Save call site if the function resolves to a concrete definition if let ty::FnDef(def_id, _) = ty.kind() { if self.target_crates.iter().all(|krate| *krate != def_id.krate) { - trace!("Rejecting expr from crate not being documented: {call_span:?}"); + tracing::trace!("Rejecting expr from crate not being documented: {call_span:?}"); return; } @@ -225,7 +227,10 @@ where let abs_path = match fs::canonicalize(file_path.clone()) { Ok(abs_path) => abs_path, Err(_) => { - trace!("Could not canonicalize file path: {}", file_path.display()); + tracing::trace!( + "Could not canonicalize file path: {}", + file_path.display() + ); return; } }; @@ -235,7 +240,7 @@ where let url = match cx.href_from_span(clean_span, false) { Some(url) => url, None => { - trace!( + tracing::trace!( "Rejecting expr ({call_span:?}) whose clean span ({clean_span:?}) cannot be turned into a link" ); return; @@ -251,14 +256,16 @@ where let fn_key = tcx.def_path_hash(*def_id); let fn_entries = self.calls.entry(fn_key).or_default(); - trace!("Including expr: {:?}", call_span); + tracing::trace!("Including expr: {:?}", call_span); let enclosing_item_span = source_map.span_extend_to_prev_char(enclosing_item_span, '\n', false); let location = match CallLocation::new(call_span, ident_span, enclosing_item_span, &file) { Some(location) => location, None => { - trace!("Could not get serializable call location for {call_span:?}"); + tracing::trace!( + "Could not get serializable call location for {call_span:?}" + ); return; } }; @@ -295,8 +302,8 @@ pub(crate) fn run( .map(|(crate_num, _)| **crate_num) .collect::>(); - debug!("All crates in TyCtxt: {all_crates:?}"); - debug!("Scrape examples target_crates: {target_crates:?}"); + tracing::debug!("All crates in TyCtxt: {all_crates:?}"); + tracing::debug!("Scrape examples target_crates: {target_crates:?}"); // Run call-finder on all items let mut calls = FxHashMap::default(); diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index b8522ea5d8fdc..c834e1b51f506 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -200,7 +200,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { om: &mut Module<'tcx>, please_inline: bool, ) -> bool { - debug!("maybe_inline_local res: {:?}", res); + tracing::debug!("maybe_inline_local res: {:?}", res); if self.cx.output_format.is_json() { return false; @@ -292,7 +292,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { renamed: Option, om: &mut Module<'tcx>, ) { - debug!("visiting item {:?}", item); + tracing::debug!("visiting item {:?}", item); let name = renamed.unwrap_or(item.ident.name); let def_id = item.def_id.to_def_id(); From 9a473cca9cfa3e2a674d423dda28454e806b7277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Tue, 25 Oct 2022 18:58:11 +0200 Subject: [PATCH 2/2] Use LTO for `librustdoc` --- compiler/rustc_codegen_llvm/src/back/lto.rs | 5 ++++- src/bootstrap/tool.rs | 7 ++++++- src/librustdoc/clean/blanket_impl.rs | 7 ++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/back/lto.rs b/compiler/rustc_codegen_llvm/src/back/lto.rs index a49cc7f8d662d..2ea5f6a26bd66 100644 --- a/compiler/rustc_codegen_llvm/src/back/lto.rs +++ b/compiler/rustc_codegen_llvm/src/back/lto.rs @@ -132,7 +132,10 @@ fn prepare_lto( let module = SerializedModule::FromRlib(data.to_vec()); upstream_modules.push((module, CString::new(name).unwrap())); } - Err(msg) => return Err(diag_handler.fatal(&msg)), + Err(msg) => { + eprintln!("Couldn't add bitcode from {name}"); + return Err(diag_handler.fatal(&msg)); + } } } } diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index eec74b2675a1e..e0da68692be60 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -540,7 +540,7 @@ impl Step for Rustdoc { features.push("jemalloc".to_string()); } - let cargo = prepare_tool_cargo( + let mut cargo = prepare_tool_cargo( builder, build_compiler, Mode::ToolRustc, @@ -551,6 +551,11 @@ impl Step for Rustdoc { features.as_slice(), ); + if build_compiler.stage == 1 { + cargo.rustflag("-Cembed-bitcode=yes"); + cargo.rustflag("-Clto=thin"); + } + builder.info(&format!( "Building rustdoc for stage{} ({})", target_compiler.stage, target_compiler.host diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index 4efa4d7023445..df898ea8fa205 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -55,7 +55,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> { // FIXME(eddyb) ignoring `obligations` might cause false positives. drop(obligations); - trace!( + tracing::trace!( "invoking predicate_may_hold: param_env={:?}, impl_trait_ref={:?}, impl_ty={:?}", param_env, impl_trait_ref, @@ -87,9 +87,10 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> { _ => continue 'blanket_impls, } } - debug!( + tracing::debug!( "get_blanket_impls: found applicable impl for trait_ref={:?}, ty={:?}", - trait_ref, ty + trait_ref, + ty ); cx.generated_synthetics.insert((ty.0, trait_def_id));