Skip to content

Commit

Permalink
Rollup merge of rust-lang#53226 - QuietMisdreavus:editions-for-all, r…
Browse files Browse the repository at this point in the history
…=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
  • Loading branch information
kennytm authored Aug 14, 2018
2 parents 700c5e8 + 0511b01 commit eeab08e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use syntax::ext::base::ExtCtxt;
use syntax::fold::Folder;
use syntax::parse::{self, PResult};
use syntax::util::node_count::NodeCounter;
use syntax_pos::FileName;
use syntax_pos::{FileName, hygiene};
use syntax_ext;

use derive_registrar;
Expand Down Expand Up @@ -670,6 +670,7 @@ pub fn phase_1_parse_input<'a>(
) -> PResult<'a, ast::Crate> {
sess.diagnostic()
.set_continue_after_error(control.continue_parse_after_error);
hygiene::set_default_edition(sess.edition());

if sess.profile_queries() {
profile::begin(sess);
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ use syntax::ast;
use syntax::codemap::{CodeMap, FileLoader, RealFileLoader};
use syntax::feature_gate::{GatedCfg, UnstableFeatures};
use syntax::parse::{self, PResult};
use syntax_pos::{hygiene, DUMMY_SP, MultiSpan, FileName};
use syntax_pos::{DUMMY_SP, MultiSpan, FileName};

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

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

driver::spawn_thread_pool(sopts, |sopts| {
run_compiler_with_pool(matches, sopts, cfg, callbacks, file_loader, emitter_dest)
Expand Down
3 changes: 1 addition & 2 deletions src/librustdoc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use syntax::codemap::CodeMap;
use syntax::edition::Edition;
use syntax::feature_gate::UnstableFeatures;
use syntax::with_globals;
use syntax_pos::{BytePos, DUMMY_SP, Pos, Span, FileName, hygiene};
use syntax_pos::{BytePos, DUMMY_SP, Pos, Span, FileName};
use errors;
use errors::emitter::ColorConfig;

Expand Down Expand Up @@ -562,7 +562,6 @@ impl Collector {
rustc_driver::in_named_rustc_thread(name, move || with_globals(move || {
io::set_panic(panic);
io::set_print(print);
hygiene::set_default_edition(edition);
run_test(&test,
&cratename,
&filename,
Expand Down
24 changes: 24 additions & 0 deletions src/test/rustdoc/async-fn.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// edition:2018
// compile-flags:-Z unstable-options

// FIXME: once `--edition` is stable in rustdoc, remove that `compile-flags` directive

#![feature(rust_2018_preview, async_await, futures_api)]

// @has async_fn/struct.S.html
// @has - '//code' 'pub async fn f()'
pub struct S;

impl S {
pub async fn f() {}
}

0 comments on commit eeab08e

Please sign in to comment.