-use rustc_ast::{self as ast, token};
+use rustc_ast as ast;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sync::Lrc;
use rustc_errors::{ColorConfig, ErrorReported, FatalError};
crate struct TestOptions {
/// Whether to disable the default `extern crate my_crate;` when creating doctests.
crate no_crate_inject: bool,
- /// Whether to emit compilation warnings when compiling doctests. Setting this will suppress
- /// the default `#![allow(unused)]`.
- crate display_doctest_warnings: bool,
/// Additional crate-level attributes to add to doctests.
crate attrs: Vec<String>,
}
}
});
+ debug!(?lint_opts);
+
let crate_types =
if options.proc_macro_crate { vec![CrateType::ProcMacro] } else { vec![CrateType::Rlib] };
maybe_sysroot: options.maybe_sysroot.clone(),
search_paths: options.libs.clone(),
crate_types,
- lint_opts: if !options.display_doctest_warnings { lint_opts } else { vec![] },
+ lint_opts,
lint_cap: Some(options.lint_cap.unwrap_or(lint::Forbid)),
cg: options.codegen_options.clone(),
externs: options.externs.clone(),
};
let test_args = options.test_args.clone();
- let display_doctest_warnings = options.display_doctest_warnings;
let nocapture = options.nocapture;
let externs = options.externs.clone();
let json_unused_externs = options.json_unused_externs;
let collector = global_ctxt.enter(|tcx| {
let crate_attrs = tcx.hir().attrs(CRATE_HIR_ID);
- let mut opts = scrape_test_config(crate_attrs);
- opts.display_doctest_warnings |= options.display_doctest_warnings;
+ let opts = scrape_test_config(crate_attrs);
let enable_per_target_ignores = options.enable_per_target_ignores;
let mut collector = Collector::new(
tcx.crate_name(LOCAL_CRATE),
Err(ErrorReported) => return Err(ErrorReported),
};
- run_tests(test_args, nocapture, display_doctest_warnings, tests);
+ run_tests(test_args, nocapture, tests);
// Collect and warn about unused externs, but only if we've gotten
// reports for each doctest
Ok(())
}
-crate fn run_tests(
- mut test_args: Vec<String>,
- nocapture: bool,
- display_doctest_warnings: bool,
- tests: Vec<test::TestDescAndFn>,
-) {
+crate fn run_tests(mut test_args: Vec<String>, nocapture: bool, tests: Vec<test::TestDescAndFn>) {
test_args.insert(0, "rustdoctest".to_string());
if nocapture {
test_args.push("--nocapture".to_string());
}
- test::test_main(
- &test_args,
- tests,
- Some(test::Options::new().display_output(display_doctest_warnings)),
- );
+ test::test_main(&test_args, tests, None);
}
// Look for `#![doc(test(no_crate_inject))]`, used by crates in the std facade.
fn scrape_test_config(attrs: &[ast::Attribute]) -> TestOptions {
use rustc_ast_pretty::pprust;
- let mut opts =
- TestOptions { no_crate_inject: false, display_doctest_warnings: false, attrs: Vec::new() };
+ let mut opts = TestOptions { no_crate_inject: false, attrs: Vec::new() };
let test_attrs: Vec<_> = attrs
.iter()
let mut prog = String::new();
let mut supports_color = false;
- if opts.attrs.is_empty() && !opts.display_doctest_warnings {
+ if opts.attrs.is_empty() {
// If there aren't any attributes supplied by #![doc(test(attr(...)))], then allow some
// lints that are commonly triggered in doctests. The crate-level test attributes are
// commonly used to make tests fail in case they trigger warnings, so having this there in
use rustc_errors::emitter::{Emitter, EmitterWriter};
use rustc_errors::Handler;
use rustc_parse::maybe_new_parser_from_source_str;
+ use rustc_parse::parser::ForceCollect;
use rustc_session::parse::ParseSess;
use rustc_span::source_map::FilePathMapping;
}
};
- match parser.parse_mod(&token::Eof) {
- Ok((_attrs, items, _span)) => {
- for item in items {
+ loop {
+ match parser.parse_item(ForceCollect::No) {
+ Ok(Some(item)) => {
if !found_main {
if let ast::ItemKind::Fn(..) = item.kind {
if item.ident.name == sym::main {
break;
}
}
+ Ok(None) => break,
+ Err(mut e) => {
+ e.cancel();
+ break;
+ }
}
- Err(mut e) => {
- e.cancel();
- }
+
+ // The supplied slice is only used for diagnostics,
+ // which are swallowed here anyway.
+ parser.maybe_consume_incorrect_semicolon(&[]);
}
// Reset errors so that they won't be reported as compiler bugs when dropping the