Skip to content

Commit d9bf37a

Browse files
use --edition for doctests, rather than just the crate
1 parent a0e48dd commit d9bf37a

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

src/librustdoc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ pub fn main_args(args: &[String]) -> isize {
446446
match (should_test, markdown_input) {
447447
(true, true) => {
448448
return markdown::test(input, cfgs, libs, externs, test_args, maybe_sysroot,
449-
display_warnings, linker)
449+
display_warnings, linker, edition)
450450
}
451451
(true, false) => {
452452
return test::run(Path::new(input), cfgs, libs, externs, test_args, crate_name,

src/librustdoc/markdown.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use testing;
1818
use rustc::session::search_paths::SearchPaths;
1919
use rustc::session::config::Externs;
2020
use syntax::codemap::DUMMY_SP;
21+
use syntax::edition::Edition;
2122

2223
use externalfiles::{ExternalHtml, LoadStringError, load_string};
2324

@@ -139,7 +140,7 @@ pub fn render(input: &Path, mut output: PathBuf, matches: &getopts::Matches,
139140
/// Run any tests/code examples in the markdown file `input`.
140141
pub fn test(input: &str, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
141142
mut test_args: Vec<String>, maybe_sysroot: Option<PathBuf>,
142-
display_warnings: bool, linker: Option<PathBuf>) -> isize {
143+
display_warnings: bool, linker: Option<PathBuf>, edition: Edition) -> isize {
143144
let input_str = match load_string(input) {
144145
Ok(s) => s,
145146
Err(LoadStringError::ReadFail) => return 1,
@@ -151,7 +152,7 @@ pub fn test(input: &str, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
151152
let mut collector = Collector::new(input.to_owned(), cfgs, libs, externs,
152153
true, opts, maybe_sysroot, None,
153154
Some(PathBuf::from(input)),
154-
linker);
155+
linker, edition);
155156
find_testable_code(&input_str, &mut collector, DUMMY_SP, None);
156157
test_args.insert(0, "rustdoctest".to_string());
157158
testing::test_main(&test_args, collector.tests,

src/librustdoc/test.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ pub fn run(input_path: &Path,
123123
maybe_sysroot,
124124
Some(codemap),
125125
None,
126-
linker);
126+
linker,
127+
edition);
127128

128129
{
129130
let map = hir::map::map_crate(&sess, &cstore, &mut hir_forest, &defs);
@@ -183,8 +184,7 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize,
183184
externs: Externs,
184185
should_panic: bool, no_run: bool, as_test_harness: bool,
185186
compile_fail: bool, mut error_codes: Vec<String>, opts: &TestOptions,
186-
maybe_sysroot: Option<PathBuf>,
187-
linker: Option<PathBuf>) {
187+
maybe_sysroot: Option<PathBuf>, linker: Option<PathBuf>, edition: Edition) {
188188
// the test harness wants its own `main` & top level functions, so
189189
// never wrap the test in `fn main() { ... }`
190190
let (test, line_offset) = make_test(test, Some(cratename), as_test_harness, opts);
@@ -210,6 +210,10 @@ fn run_test(test: &str, cratename: &str, filename: &FileName, line: usize,
210210
},
211211
test: as_test_harness,
212212
unstable_features: UnstableFeatures::from_environment(),
213+
debugging_opts: config::DebuggingOptions {
214+
edition,
215+
..config::basic_debugging_options()
216+
},
213217
..config::basic_options().clone()
214218
};
215219

@@ -473,13 +477,14 @@ pub struct Collector {
473477
codemap: Option<Lrc<CodeMap>>,
474478
filename: Option<PathBuf>,
475479
linker: Option<PathBuf>,
480+
edition: Edition,
476481
}
477482

478483
impl Collector {
479484
pub fn new(cratename: String, cfgs: Vec<String>, libs: SearchPaths, externs: Externs,
480485
use_headers: bool, opts: TestOptions, maybe_sysroot: Option<PathBuf>,
481486
codemap: Option<Lrc<CodeMap>>, filename: Option<PathBuf>,
482-
linker: Option<PathBuf>) -> Collector {
487+
linker: Option<PathBuf>, edition: Edition) -> Collector {
483488
Collector {
484489
tests: Vec::new(),
485490
names: Vec::new(),
@@ -494,6 +499,7 @@ impl Collector {
494499
codemap,
495500
filename,
496501
linker,
502+
edition,
497503
}
498504
}
499505

@@ -513,6 +519,7 @@ impl Collector {
513519
let opts = self.opts.clone();
514520
let maybe_sysroot = self.maybe_sysroot.clone();
515521
let linker = self.linker.clone();
522+
let edition = self.edition;
516523
debug!("Creating test {}: {}", name, test);
517524
self.tests.push(testing::TestDescAndFn {
518525
desc: testing::TestDesc {
@@ -543,7 +550,8 @@ impl Collector {
543550
error_codes,
544551
&opts,
545552
maybe_sysroot,
546-
linker)
553+
linker,
554+
edition)
547555
}))
548556
} {
549557
Ok(()) => (),

0 commit comments

Comments
 (0)