Repository: rust-lang/rust
File: src/librustdoc/lib.rs (Rust)

Code before:
            for owner_id in tcx.hir_crate_items(()).delayed_lint_items() {
                if let Some(delayed_lints) = tcx.opt_ast_lowering_delayed_lints(owner_id) {
                    for lint in &delayed_lints.lints {
                        match lint {
                            DelayedLint::AttributeParsing(attribute_lint) => {
                                tcx.node_span_lint(
                                    attribute_lint.lint_id.lint,
                                    attribute_lint.id,
                                    attribute_lint.span,
                                    |diag| {
                                        rustc_lint::decorate_attribute_lint(
                                            tcx.sess,
                                            Some(tcx),
                                            &attribute_lint.kind,
                                            diag,
                                        );
                                    },
                                );
                            }
                        }
                    }
                }
            }

            if render_opts.dep_info().is_some() {
                if let Err(e) = fs::create_dir_all(&render_opts.output) {
                    sess.dcx()
                        .fatal(format!("{output}: {e}", output = render_opts.output.display()));
                }
                rustc_interface::passes::write_dep_info(tcx);
            }

            if let Some(metrics_dir) = &sess.opts.unstable_opts.metrics_dir {
                dump_feature_usage_metrics(tcx, metrics_dir);
            }

            if run_check {
                // Since we're in "check" mode, no need to generate anything beyond this point.
                return;
            }

            info!("going to format");
            match output_format {
                config::OutputFormat::Html => sess.time("render_html", || {
                    run_renderer(
                        krate,
                        render_opts,
                        cache,
                        tcx,
                        |krate, render_opts, cache, tcx| {
                            html::render::Context::init(

Review comment (bug):
For some unknown reason, rustc doesn't actually try to create the outdir for depinfo files, not sure if that's intentional. E.g., `--out-dir=nonexistent --emit=dep-info` fails. This might warrant a quick investigation. Unless it's a bug in rustc, we should probably be consistent with rustc and not attempt to create the outdir? I'm split.

I don't know why but `write_dep_info` specifically contains a check to prevent `create_dir_all` from being called if `DepInfo` is the only requested emission type. *However* that runs after `write_out_deps` which by that point would've already bailed out with an error if the directory didn't exist...

https://github.com/rust-lang/rust/blob/67aec36df76a7b67b71a8ee47684467e16f1847e/compiler/rustc_interface/src/passes.rs#L844-L855

Code after:
                if let Some(delayed_lints) = tcx.opt_ast_lowering_delayed_lints(owner_id) {
                    for lint in &delayed_lints.lints {
                        match lint {
                            DelayedLint::AttributeParsing(attribute_lint) => {
                                tcx.node_span_lint(
                                    attribute_lint.lint_id.lint,
                                    attribute_lint.id,
                                    attribute_lint.span,
                                    |diag| {
                                        rustc_lint::decorate_attribute_lint(
                                            tcx.sess,
                                            Some(tcx),
                                            &attribute_lint.kind,
                                            diag,
                                        );
                                    },
                                );
                            }
                        }
                    }
                }
            }

            if render_opts.dep_info().is_some() {
                rustc_interface::passes::write_dep_info(tcx);
            }

            if let Some(metrics_dir) = &sess.opts.unstable_opts.metrics_dir {
                dump_feature_usage_metrics(tcx, metrics_dir);
            }

            if run_check {
                // Since we're in "check" mode, no need to generate anything beyond this point.
                return;
            }

            info!("going to format");
            match output_format {
                config::OutputFormat::Html => sess.time("render_html", || {
                    run_renderer(
                        krate,
                        render_opts,
                        cache,
                        tcx,
                        |krate, render_opts, cache, tcx| {
                            html::render::Context::init(
                                krate,
                                render_opts,
                                cache,
                                tcx,
                                expanded_macros,