Skip to content

Commit

Permalink
rustdoc: Respect diagnostic debugging options
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Jan 3, 2020
1 parent 4feecee commit 1370bbc
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 56 deletions.
13 changes: 12 additions & 1 deletion src/librustc_session/config.rs
Expand Up @@ -20,7 +20,7 @@ use rustc_span::source_map::{FileName, FilePathMapping};
use rustc_span::symbol::{sym, Symbol}; use rustc_span::symbol::{sym, Symbol};


use rustc_errors::emitter::HumanReadableErrorType; use rustc_errors::emitter::HumanReadableErrorType;
use rustc_errors::{ColorConfig, FatalError, Handler}; use rustc_errors::{ColorConfig, FatalError, Handler, HandlerFlags};


use getopts; use getopts;


Expand Down Expand Up @@ -597,6 +597,17 @@ impl DebuggingOptions {
pub fn ui_testing(&self) -> bool { pub fn ui_testing(&self) -> bool {
self.ui_testing.unwrap_or(false) self.ui_testing.unwrap_or(false)
} }

pub fn diagnostic_handler_flags(&self, can_emit_warnings: bool) -> HandlerFlags {
HandlerFlags {
can_emit_warnings,
treat_err_as_bug: self.treat_err_as_bug,
dont_buffer_diagnostics: self.dont_buffer_diagnostics,
report_delayed_bugs: self.report_delayed_bugs,
external_macro_backtrace: self.external_macro_backtrace,
deduplicate_diagnostics: self.deduplicate_diagnostics.unwrap_or(true),
}
}
} }


// The type of entry function, so users can have their own entry functions // The type of entry function, so users can have their own entry functions
Expand Down
15 changes: 1 addition & 14 deletions src/librustc_session/session.rs
Expand Up @@ -941,13 +941,7 @@ pub fn build_session_with_source_map(
.last() .last()
.unwrap_or(false); .unwrap_or(false);
let cap_lints_allow = sopts.lint_cap.map_or(false, |cap| cap == lint::Allow); let cap_lints_allow = sopts.lint_cap.map_or(false, |cap| cap == lint::Allow);

let can_emit_warnings = !(warnings_allow || cap_lints_allow); let can_emit_warnings = !(warnings_allow || cap_lints_allow);
let treat_err_as_bug = sopts.debugging_opts.treat_err_as_bug;
let dont_buffer_diagnostics = sopts.debugging_opts.dont_buffer_diagnostics;
let report_delayed_bugs = sopts.debugging_opts.report_delayed_bugs;
let external_macro_backtrace = sopts.debugging_opts.external_macro_backtrace;
let deduplicate_diagnostics = sopts.debugging_opts.deduplicate_diagnostics.unwrap_or(true);


let write_dest = match diagnostics_output { let write_dest = match diagnostics_output {
DiagnosticOutput::Default => None, DiagnosticOutput::Default => None,
Expand All @@ -957,14 +951,7 @@ pub fn build_session_with_source_map(


let diagnostic_handler = rustc_errors::Handler::with_emitter_and_flags( let diagnostic_handler = rustc_errors::Handler::with_emitter_and_flags(
emitter, emitter,
rustc_errors::HandlerFlags { sopts.debugging_opts.diagnostic_handler_flags(can_emit_warnings),
can_emit_warnings,
treat_err_as_bug,
report_delayed_bugs,
dont_buffer_diagnostics,
external_macro_backtrace,
deduplicate_diagnostics,
},
); );


build_session_(sopts, local_crate_source_file, diagnostic_handler, source_map, lint_caps) build_session_(sopts, local_crate_source_file, diagnostic_handler, source_map, lint_caps)
Expand Down
7 changes: 1 addition & 6 deletions src/librustdoc/config.rs
Expand Up @@ -269,12 +269,7 @@ impl Options {
let codegen_options = build_codegen_options(matches, error_format); let codegen_options = build_codegen_options(matches, error_format);
let debugging_options = build_debugging_options(matches, error_format); let debugging_options = build_debugging_options(matches, error_format);


let diag = new_handler( let diag = new_handler(error_format, None, &debugging_options);
error_format,
None,
debugging_options.treat_err_as_bug,
debugging_options.ui_testing(),
);


// check for deprecated options // check for deprecated options
check_deprecated_options(&matches, &diag); check_deprecated_options(&matches, &diag);
Expand Down
29 changes: 8 additions & 21 deletions src/librustdoc/core.rs
Expand Up @@ -35,7 +35,7 @@ use crate::html::render::RenderInfo;


use crate::passes; use crate::passes;


pub use rustc::session::config::{CodegenOptions, Input, Options}; pub use rustc::session::config::{CodegenOptions, DebuggingOptions, Input, Options};
pub use rustc::session::search_paths::SearchPath; pub use rustc::session::search_paths::SearchPath;


pub type ExternalPaths = FxHashMap<DefId, (Vec<String>, clean::TypeKind)>; pub type ExternalPaths = FxHashMap<DefId, (Vec<String>, clean::TypeKind)>;
Expand Down Expand Up @@ -170,12 +170,8 @@ impl<'tcx> DocContext<'tcx> {
pub fn new_handler( pub fn new_handler(
error_format: ErrorOutputType, error_format: ErrorOutputType,
source_map: Option<Lrc<source_map::SourceMap>>, source_map: Option<Lrc<source_map::SourceMap>>,
treat_err_as_bug: Option<usize>, debugging_opts: &DebuggingOptions,
ui_testing: bool,
) -> errors::Handler { ) -> errors::Handler {
// rustdoc doesn't override (or allow to override) anything from this that is relevant here, so
// stick to the defaults
let sessopts = Options::default();
let emitter: Box<dyn Emitter + sync::Send> = match error_format { let emitter: Box<dyn Emitter + sync::Send> = match error_format {
ErrorOutputType::HumanReadable(kind) => { ErrorOutputType::HumanReadable(kind) => {
let (short, color_config) = kind.unzip(); let (short, color_config) = kind.unzip();
Expand All @@ -184,34 +180,25 @@ pub fn new_handler(
color_config, color_config,
source_map.map(|cm| cm as _), source_map.map(|cm| cm as _),
short, short,
sessopts.debugging_opts.teach, debugging_opts.teach,
sessopts.debugging_opts.terminal_width, debugging_opts.terminal_width,
false, false,
) )
.ui_testing(ui_testing), .ui_testing(debugging_opts.ui_testing),
) )
} }
ErrorOutputType::Json { pretty, json_rendered } => { ErrorOutputType::Json { pretty, json_rendered } => {
let source_map = source_map.unwrap_or_else(|| { let source_map = source_map.unwrap_or_else(|| {
Lrc::new(source_map::SourceMap::new(sessopts.file_path_mapping())) Lrc::new(source_map::SourceMap::new(source_map::FilePathMapping::empty()))
}); });
Box::new( Box::new(
JsonEmitter::stderr(None, source_map, pretty, json_rendered, false) JsonEmitter::stderr(None, source_map, pretty, json_rendered, false)
.ui_testing(ui_testing), .ui_testing(debugging_opts.ui_testing),
) )
} }
}; };


errors::Handler::with_emitter_and_flags( errors::Handler::with_emitter_and_flags(emitter, debugging_opts.diagnostic_handler_flags(true))
emitter,
errors::HandlerFlags {
can_emit_warnings: true,
treat_err_as_bug,
report_delayed_bugs: false,
external_macro_backtrace: false,
..Default::default()
},
)
} }


pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOptions) { pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOptions) {
Expand Down
18 changes: 4 additions & 14 deletions src/librustdoc/lib.rs
Expand Up @@ -445,12 +445,7 @@ fn main_args(args: &[String]) -> i32 {
} }


fn main_options(options: config::Options) -> i32 { fn main_options(options: config::Options) -> i32 {
let diag = core::new_handler( let diag = core::new_handler(options.error_format, None, &options.debugging_options);
options.error_format,
None,
options.debugging_options.treat_err_as_bug,
options.debugging_options.ui_testing(),
);


match (options.should_test, options.markdown_input()) { match (options.should_test, options.markdown_input()) {
(true, true) => return markdown::test(options, &diag), (true, true) => return markdown::test(options, &diag),
Expand All @@ -463,12 +458,7 @@ fn main_options(options: config::Options) -> i32 {


// need to move these items separately because we lose them by the time the closure is called, // need to move these items separately because we lose them by the time the closure is called,
// but we can't crates the Handler ahead of time because it's not Send // but we can't crates the Handler ahead of time because it's not Send
let diag_opts = ( let diag_opts = (options.error_format, options.edition, options.debugging_options.clone());
options.error_format,
options.debugging_options.treat_err_as_bug,
options.debugging_options.ui_testing(),
options.edition,
);
let show_coverage = options.show_coverage; let show_coverage = options.show_coverage;
rust_input(options, move |out| { rust_input(options, move |out| {
if show_coverage { if show_coverage {
Expand All @@ -479,8 +469,8 @@ fn main_options(options: config::Options) -> i32 {


let Output { krate, renderinfo, renderopts } = out; let Output { krate, renderinfo, renderopts } = out;
info!("going to format"); info!("going to format");
let (error_format, treat_err_as_bug, ui_testing, edition) = diag_opts; let (error_format, edition, debugging_options) = diag_opts;
let diag = core::new_handler(error_format, None, treat_err_as_bug, ui_testing); let diag = core::new_handler(error_format, None, &debugging_options);
match html::render::run(krate, renderopts, renderinfo, &diag, edition) { match html::render::run(krate, renderopts, renderinfo, &diag, edition) {
Ok(_) => rustc_driver::EXIT_SUCCESS, Ok(_) => rustc_driver::EXIT_SUCCESS,
Err(e) => { Err(e) => {
Expand Down

0 comments on commit 1370bbc

Please sign in to comment.