Skip to content

Commit fab6b06

Browse files
Add treat-err-as-bug flag in rustdoc
1 parent 6810f52 commit fab6b06

File tree

4 files changed

+55
-11
lines changed

4 files changed

+55
-11
lines changed

src/librustdoc/core.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,10 @@ impl DocAccessLevels for AccessLevels<DefId> {
260260
///
261261
/// If the given `error_format` is `ErrorOutputType::Json` and no `SourceMap` is given, a new one
262262
/// will be created for the handler.
263-
pub fn new_handler(error_format: ErrorOutputType, source_map: Option<Lrc<source_map::SourceMap>>)
264-
-> errors::Handler
265-
{
263+
pub fn new_handler(error_format: ErrorOutputType,
264+
source_map: Option<Lrc<source_map::SourceMap>>,
265+
treat_err_as_bug: bool,
266+
) -> errors::Handler {
266267
// rustdoc doesn't override (or allow to override) anything from this that is relevant here, so
267268
// stick to the defaults
268269
let sessopts = Options::default();
@@ -299,7 +300,7 @@ pub fn new_handler(error_format: ErrorOutputType, source_map: Option<Lrc<source_
299300
emitter,
300301
errors::HandlerFlags {
301302
can_emit_warnings: true,
302-
treat_err_as_bug: false,
303+
treat_err_as_bug,
303304
report_delayed_bugs: false,
304305
external_macro_backtrace: false,
305306
..Default::default()
@@ -323,9 +324,9 @@ pub fn run_core(search_paths: SearchPaths,
323324
lint_cap: Option<lint::Level>,
324325
describe_lints: bool,
325326
mut manual_passes: Vec<String>,
326-
mut default_passes: passes::DefaultPassOption)
327-
-> (clean::Crate, RenderInfo, Vec<String>)
328-
{
327+
mut default_passes: passes::DefaultPassOption,
328+
treat_err_as_bug: bool,
329+
) -> (clean::Crate, RenderInfo, Vec<String>) {
329330
// Parse, resolve, and typecheck the given crate.
330331

331332
let cpath = match input {
@@ -388,7 +389,9 @@ pub fn run_core(search_paths: SearchPaths,
388389
};
389390
driver::spawn_thread_pool(sessopts, move |sessopts| {
390391
let source_map = Lrc::new(source_map::SourceMap::new(sessopts.file_path_mapping()));
391-
let diagnostic_handler = new_handler(error_format, Some(source_map.clone()));
392+
let diagnostic_handler = new_handler(error_format,
393+
Some(source_map.clone()),
394+
treat_err_as_bug);
392395

393396
let mut sess = session::build_session_(
394397
sessopts, cpath, diagnostic_handler, source_map,

src/librustdoc/lib.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,11 @@ fn main_args(args: &[String]) -> isize {
404404
`short` (instead was `{}`)", arg));
405405
}
406406
};
407+
let treat_err_as_bug = matches.opt_strs("Z").iter().any(|x| {
408+
*x == "treat-err-as-bug"
409+
});
407410

408-
let diag = core::new_handler(error_format, None);
411+
let diag = core::new_handler(error_format, None, treat_err_as_bug);
409412

410413
// check for deprecated options
411414
check_deprecated_options(&matches, &diag);
@@ -560,7 +563,7 @@ fn main_args(args: &[String]) -> isize {
560563
let res = acquire_input(PathBuf::from(input), externs, edition, cg, &matches, error_format,
561564
move |out| {
562565
let Output { krate, passes, renderinfo } = out;
563-
let diag = core::new_handler(error_format, None);
566+
let diag = core::new_handler(error_format, None, treat_err_as_bug);
564567
info!("going to format");
565568
match output_format.as_ref().map(|s| &**s) {
566569
Some("html") | None => {
@@ -691,6 +694,9 @@ where R: 'static + Send,
691694
let force_unstable_if_unmarked = matches.opt_strs("Z").iter().any(|x| {
692695
*x == "force-unstable-if-unmarked"
693696
});
697+
let treat_err_as_bug = matches.opt_strs("Z").iter().any(|x| {
698+
*x == "treat-err-as-bug"
699+
});
694700

695701
let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);
696702

@@ -703,7 +709,8 @@ where R: 'static + Send,
703709
core::run_core(paths, cfgs, externs, Input::File(cratefile), triple, maybe_sysroot,
704710
display_warnings, crate_name.clone(),
705711
force_unstable_if_unmarked, edition, cg, error_format,
706-
lint_opts, lint_cap, describe_lints, manual_passes, default_passes);
712+
lint_opts, lint_cap, describe_lints, manual_passes, default_passes,
713+
treat_err_as_bug);
707714

708715
info!("finished with rustc");
709716

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: -Ztreat-err-as-bug --error-format=human
12+
13+
pub fn foo() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error: this file contains an un-closed delimiter
2+
--> $DIR/treat-err-as-bug.rs:13:16
3+
|
4+
13 | pub fn foo() {
5+
| - ^
6+
| |
7+
| un-closed delimiter
8+
9+
thread '<unnamed>' panicked at 'encountered error with `-Z treat_err_as_bug', librustc_errors/lib.rs:486:13
10+
note: Run with `RUST_BACKTRACE=1` for a backtrace.
11+
12+
error: internal compiler error: unexpected panic
13+
14+
note: the compiler unexpectedly panicked. this is a bug.
15+
16+
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
17+
18+
note: rustc 1.30.0-dev running on x86_64-apple-darwin
19+
20+
note: compiler flags: -Z ui-testing -Z unstable-options -Z treat-err-as-bug
21+

0 commit comments

Comments
 (0)