diff options
Diffstat (limited to 'src/librustdoc')
| -rw-r--r-- | src/librustdoc/config.rs | 16 | ||||
| -rw-r--r-- | src/librustdoc/core.rs | 4 | ||||
| -rw-r--r-- | src/librustdoc/doctest.rs | 7 | ||||
| -rw-r--r-- | src/librustdoc/doctest/make.rs | 2 | ||||
| -rw-r--r-- | src/librustdoc/externalfiles.rs | 7 | ||||
| -rw-r--r-- | src/librustdoc/lib.rs | 13 | ||||
| -rw-r--r-- | src/librustdoc/scrape_examples.rs | 5 | ||||
| -rw-r--r-- | src/librustdoc/theme.rs | 4 |
8 files changed, 30 insertions, 28 deletions
diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 78d4129f642..45bd1616e83 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -8,6 +8,7 @@ use std::path::PathBuf; use std::str::FromStr; use rustc_data_structures::fx::FxHashMap; +use rustc_errors::DiagCtxtHandle; use rustc_session::config::{ self, parse_crate_types_from_list, parse_externs, parse_target_triple, CrateType, }; @@ -383,9 +384,10 @@ impl Options { }; let dcx = new_dcx(error_format, None, diagnostic_width, &unstable_opts); + let dcx = dcx.handle(); // check for deprecated options - check_deprecated_options(matches, &dcx); + check_deprecated_options(matches, dcx); if matches.opt_strs("passes") == ["list"] { println!("Available passes for running rustdoc:"); @@ -458,7 +460,7 @@ impl Options { println!("rustdoc: [check-theme] Starting tests! (Ignoring all other arguments)"); for theme_file in to_check.iter() { print!(" - Checking \"{theme_file}\"..."); - let (success, differences) = theme::test_theme_against(theme_file, &paths, &dcx); + let (success, differences) = theme::test_theme_against(theme_file, &paths, dcx); if !differences.is_empty() || !success { println!(" FAILED"); errors += 1; @@ -603,7 +605,7 @@ impl Options { .with_help("arguments to --theme must have a .css extension") .emit(); } - let (success, ret) = theme::test_theme_against(&theme_file, &paths, &dcx); + let (success, ret) = theme::test_theme_against(&theme_file, &paths, dcx); if !success { dcx.fatal(format!("error loading theme file: \"{theme_s}\"")); } else if !ret.is_empty() { @@ -630,7 +632,7 @@ impl Options { &matches.opt_strs("markdown-before-content"), &matches.opt_strs("markdown-after-content"), nightly_options::match_is_nightly_build(matches), - &dcx, + dcx, &mut id_map, edition, &None, @@ -741,9 +743,9 @@ impl Options { ); } - let scrape_examples_options = ScrapeExamplesOptions::new(matches, &dcx); + let scrape_examples_options = ScrapeExamplesOptions::new(matches, dcx); let with_examples = matches.opt_strs("with-examples"); - let call_locations = crate::scrape_examples::load_call_locations(with_examples, &dcx); + let call_locations = crate::scrape_examples::load_call_locations(with_examples, dcx); let unstable_features = rustc_feature::UnstableFeatures::from_environment(crate_name.as_deref()); @@ -847,7 +849,7 @@ fn parse_remap_path_prefix( } /// Prints deprecation warnings for deprecated options -fn check_deprecated_options(matches: &getopts::Matches, dcx: &rustc_errors::DiagCtxt) { +fn check_deprecated_options(matches: &getopts::Matches, dcx: DiagCtxtHandle<'_>) { let deprecated_flags = []; for &flag in deprecated_flags.iter() { diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index ce098a1bcfb..5d8e61f9fa0 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -3,7 +3,7 @@ use rustc_data_structures::sync::Lrc; use rustc_data_structures::unord::UnordSet; use rustc_errors::emitter::{stderr_destination, DynEmitter, HumanEmitter}; use rustc_errors::json::JsonEmitter; -use rustc_errors::{codes::*, ErrorGuaranteed, TerminalUrl}; +use rustc_errors::{codes::*, DiagCtxtHandle, ErrorGuaranteed, TerminalUrl}; use rustc_feature::UnstableFeatures; use rustc_hir::def::Res; use rustc_hir::def_id::{DefId, DefIdMap, DefIdSet, LocalDefId}; @@ -379,7 +379,7 @@ pub(crate) fn run_global_ctxt( ); } - fn report_deprecated_attr(name: &str, dcx: &rustc_errors::DiagCtxt, sp: Span) { + fn report_deprecated_attr(name: &str, dcx: DiagCtxtHandle<'_>, sp: Span) { let mut msg = dcx.struct_span_warn(sp, format!("the `#![doc({name})]` attribute is deprecated")); msg.note( diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 81a7463deca..40cc4a9d441 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -7,7 +7,7 @@ pub(crate) use markdown::test as test_markdown; use rustc_ast as ast; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_errors::{ColorConfig, ErrorGuaranteed, FatalError}; +use rustc_errors::{ColorConfig, DiagCtxtHandle, ErrorGuaranteed, FatalError}; use rustc_hir::def_id::LOCAL_CRATE; use rustc_hir::CRATE_HIR_ID; use rustc_interface::interface; @@ -90,10 +90,7 @@ fn get_doctest_dir() -> io::Result<TempDir> { TempFileBuilder::new().prefix("rustdoctest").tempdir() } -pub(crate) fn run( - dcx: &rustc_errors::DiagCtxt, - options: RustdocOptions, -) -> Result<(), ErrorGuaranteed> { +pub(crate) fn run(dcx: DiagCtxtHandle<'_>, options: RustdocOptions) -> Result<(), ErrorGuaranteed> { let invalid_codeblock_attributes_name = crate::lint::INVALID_CODEBLOCK_ATTRIBUTES.name; // See core::create_config for what's going on here. diff --git a/src/librustdoc/doctest/make.rs b/src/librustdoc/doctest/make.rs index 599611407ed..74833c11362 100644 --- a/src/librustdoc/doctest/make.rs +++ b/src/librustdoc/doctest/make.rs @@ -229,7 +229,7 @@ fn check_for_main_and_extern_crate( // dcx. Any errors in the tests will be reported when the test file is compiled, // Note that we still need to cancel the errors above otherwise `Diag` will panic on // drop. - psess.dcx.reset_err_count(); + psess.dcx().reset_err_count(); (found_main, found_extern_crate, found_macro) }) diff --git a/src/librustdoc/externalfiles.rs b/src/librustdoc/externalfiles.rs index 03ee042aa8d..62cdc0bd5a6 100644 --- a/src/librustdoc/externalfiles.rs +++ b/src/librustdoc/externalfiles.rs @@ -1,4 +1,5 @@ use crate::html::markdown::{ErrorCodes, HeadingOffset, IdMap, Markdown, Playground}; +use rustc_errors::DiagCtxtHandle; use rustc_span::edition::Edition; use std::fs; use std::path::Path; @@ -27,7 +28,7 @@ impl ExternalHtml { md_before_content: &[String], md_after_content: &[String], nightly_build: bool, - dcx: &rustc_errors::DiagCtxt, + dcx: DiagCtxtHandle<'_>, id_map: &mut IdMap, edition: Edition, playground: &Option<Playground>, @@ -75,7 +76,7 @@ pub(crate) enum LoadStringError { pub(crate) fn load_string<P: AsRef<Path>>( file_path: P, - dcx: &rustc_errors::DiagCtxt, + dcx: DiagCtxtHandle<'_>, ) -> Result<String, LoadStringError> { let file_path = file_path.as_ref(); let contents = match fs::read(file_path) { @@ -98,7 +99,7 @@ pub(crate) fn load_string<P: AsRef<Path>>( } } -fn load_external_files(names: &[String], dcx: &rustc_errors::DiagCtxt) -> Option<String> { +fn load_external_files(names: &[String], dcx: DiagCtxtHandle<'_>) -> Option<String> { let mut out = String::new(); for name in names { let Ok(s) = load_string(name, dcx) else { return None }; diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index d6e715d48ea..fb4cd218b84 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -77,7 +77,7 @@ use std::io::{self, IsTerminal}; use std::process; use std::sync::{atomic::AtomicBool, Arc}; -use rustc_errors::{ErrorGuaranteed, FatalError}; +use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed, FatalError}; use rustc_interface::interface; use rustc_middle::ty::TyCtxt; use rustc_session::config::{make_crate_type_option, ErrorOutputType, RustcOptGroup}; @@ -670,7 +670,7 @@ fn usage(argv0: &str) { /// A result type used by several functions under `main()`. type MainResult = Result<(), ErrorGuaranteed>; -pub(crate) fn wrap_return(dcx: &rustc_errors::DiagCtxt, res: Result<(), String>) -> MainResult { +pub(crate) fn wrap_return(dcx: DiagCtxtHandle<'_>, res: Result<(), String>) -> MainResult { match res { Ok(()) => dcx.has_errors().map_or(Ok(()), Err), Err(err) => Err(dcx.err(err)), @@ -732,12 +732,13 @@ fn main_args( None => return Ok(()), }; - let diag = + let dcx = core::new_dcx(options.error_format, None, options.diagnostic_width, &options.unstable_opts); + let dcx = dcx.handle(); match (options.should_test, options.markdown_input()) { - (true, Some(_)) => return wrap_return(&diag, doctest::test_markdown(options)), - (true, None) => return doctest::run(&diag, options), + (true, Some(_)) => return wrap_return(dcx, doctest::test_markdown(options)), + (true, None) => return doctest::run(dcx, options), (false, Some(input)) => { let input = input.to_owned(); let edition = options.edition; @@ -747,7 +748,7 @@ fn main_args( // requires session globals and a thread pool, so we use // `run_compiler`. return wrap_return( - &diag, + dcx, interface::run_compiler(config, |_compiler| { markdown::render(&input, render_options, edition) }), diff --git a/src/librustdoc/scrape_examples.rs b/src/librustdoc/scrape_examples.rs index e9b380fdeac..5a595e03953 100644 --- a/src/librustdoc/scrape_examples.rs +++ b/src/librustdoc/scrape_examples.rs @@ -7,6 +7,7 @@ use crate::formats::renderer::FormatRenderer; use crate::html::render::Context; use rustc_data_structures::fx::FxHashMap; +use rustc_errors::DiagCtxtHandle; use rustc_hir::{ self as hir, intravisit::{self, Visitor}, @@ -38,7 +39,7 @@ pub(crate) struct ScrapeExamplesOptions { } impl ScrapeExamplesOptions { - pub(crate) fn new(matches: &getopts::Matches, dcx: &rustc_errors::DiagCtxt) -> Option<Self> { + pub(crate) fn new(matches: &getopts::Matches, dcx: DiagCtxtHandle<'_>) -> Option<Self> { let output_path = matches.opt_str("scrape-examples-output-path"); let target_crates = matches.opt_strs("scrape-examples-target-crate"); let scrape_tests = matches.opt_present("scrape-tests"); @@ -336,7 +337,7 @@ pub(crate) fn run( // options. pub(crate) fn load_call_locations( with_examples: Vec<String>, - dcx: &rustc_errors::DiagCtxt, + dcx: DiagCtxtHandle<'_>, ) -> AllCallLocations { let mut all_calls: AllCallLocations = FxHashMap::default(); for path in with_examples { diff --git a/src/librustdoc/theme.rs b/src/librustdoc/theme.rs index 31d32e23f8e..2fa54a9cd81 100644 --- a/src/librustdoc/theme.rs +++ b/src/librustdoc/theme.rs @@ -5,7 +5,7 @@ use std::iter::Peekable; use std::path::Path; use std::str::Chars; -use rustc_errors::DiagCtxt; +use rustc_errors::DiagCtxtHandle; #[cfg(test)] mod tests; @@ -236,7 +236,7 @@ pub(crate) fn get_differences( pub(crate) fn test_theme_against<P: AsRef<Path>>( f: &P, origin: &FxHashMap<String, CssPath>, - dcx: &DiagCtxt, + dcx: DiagCtxtHandle<'_>, ) -> (bool, Vec<String>) { let against = match fs::read_to_string(f) .map_err(|e| e.to_string()) |
