Skip to content

Commit eeab08e

Browse files
authored
Rollup merge of rust-lang#53226 - QuietMisdreavus:editions-for-all, r=estebank
driver: set the syntax edition in phase 1 Fixes rust-lang#53203 It seems the way libsyntax handles the desired edition is to use a global, set via `syntax_pos::hygiene::set_default_edition`. Right now, this is set in the driver in `run_compiler`, which is the entry point for running the compiler all the way through to emitting files. Since rustdoc doesn't use this function, it wasn't properly setting this global. (When initially setting up editions in rustdoc, i'd assumed that setting `sessopts.edition` would have done this... `>_>`) This was "fixed" for doctests in rust-lang#52385, but rather than patching in a call to `set_default_edition` in all the places rustdoc sets up the compiler, i've instead moved the call in the driver to be farther in the process. This means that any use of `phase_1_parse_input` with the right session options will have the edition properly set without having to also remember to set libsyntax up separately. r? @rust-lang/compiler
2 parents 700c5e8 + 0511b01 commit eeab08e

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

src/librustc_driver/driver.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ use syntax::ext::base::ExtCtxt;
5757
use syntax::fold::Folder;
5858
use syntax::parse::{self, PResult};
5959
use syntax::util::node_count::NodeCounter;
60-
use syntax_pos::FileName;
60+
use syntax_pos::{FileName, hygiene};
6161
use syntax_ext;
6262

6363
use derive_registrar;
@@ -670,6 +670,7 @@ pub fn phase_1_parse_input<'a>(
670670
) -> PResult<'a, ast::Crate> {
671671
sess.diagnostic()
672672
.set_continue_after_error(control.continue_parse_after_error);
673+
hygiene::set_default_edition(sess.edition());
673674

674675
if sess.profile_queries() {
675676
profile::begin(sess);

src/librustc_driver/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ use syntax::ast;
110110
use syntax::codemap::{CodeMap, FileLoader, RealFileLoader};
111111
use syntax::feature_gate::{GatedCfg, UnstableFeatures};
112112
use syntax::parse::{self, PResult};
113-
use syntax_pos::{hygiene, DUMMY_SP, MultiSpan, FileName};
113+
use syntax_pos::{DUMMY_SP, MultiSpan, FileName};
114114

115115
#[cfg(test)]
116116
mod test;
@@ -478,7 +478,6 @@ pub fn run_compiler<'a>(args: &[String],
478478
};
479479

480480
let (sopts, cfg) = config::build_session_options_and_crate_config(&matches);
481-
hygiene::set_default_edition(sopts.edition);
482481

483482
driver::spawn_thread_pool(sopts, |sopts| {
484483
run_compiler_with_pool(matches, sopts, cfg, callbacks, file_loader, emitter_dest)

src/librustdoc/test.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use syntax::codemap::CodeMap;
3737
use syntax::edition::Edition;
3838
use syntax::feature_gate::UnstableFeatures;
3939
use syntax::with_globals;
40-
use syntax_pos::{BytePos, DUMMY_SP, Pos, Span, FileName, hygiene};
40+
use syntax_pos::{BytePos, DUMMY_SP, Pos, Span, FileName};
4141
use errors;
4242
use errors::emitter::ColorConfig;
4343

@@ -562,7 +562,6 @@ impl Collector {
562562
rustc_driver::in_named_rustc_thread(name, move || with_globals(move || {
563563
io::set_panic(panic);
564564
io::set_print(print);
565-
hygiene::set_default_edition(edition);
566565
run_test(&test,
567566
&cratename,
568567
&filename,

src/test/rustdoc/async-fn.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2018 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+
// edition:2018
12+
// compile-flags:-Z unstable-options
13+
14+
// FIXME: once `--edition` is stable in rustdoc, remove that `compile-flags` directive
15+
16+
#![feature(rust_2018_preview, async_await, futures_api)]
17+
18+
// @has async_fn/struct.S.html
19+
// @has - '//code' 'pub async fn f()'
20+
pub struct S;
21+
22+
impl S {
23+
pub async fn f() {}
24+
}

0 commit comments

Comments
 (0)