From a632de1ad99ba9edd740387dff980cd9f12f9cbd Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 31 Dec 2020 21:27:05 -0800 Subject: [PATCH] Update internal code generator to rustfmt 2.0.0-rc.2 The previously pinned rustfmt commit + toolchain have no longer been compiling as of servo/rust-smallvec#248. error[E0658]: unions with non-`Copy` fields are unstable --> /home/david/.cargo/registry/src/github.com-1ecc6299db9ec823/smallvec-1.6.0/src/lib.rs:353:1 | 353 | / union SmallVecData { 354 | | inline: core::mem::ManuallyDrop>, 355 | | heap: (*mut A::Item, usize), 356 | | } | |_^ | = note: see issue #55149 for more information = help: add `#![feature(untagged_unions)]` to the crate attributes to enable --- .github/workflows/ci.yml | 5 ++++- codegen/Cargo.toml | 6 +++--- codegen/rust-toolchain | 2 +- codegen/src/file.rs | 17 ++++++++++++----- tests/debug/gen.rs | 24 ++++++++++++++++++------ 5 files changed, 38 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b83f1df553..1984476cbd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -87,11 +87,14 @@ jobs: codegen: name: Codegen runs-on: ubuntu-latest + env: + CFG_RELEASE_CHANNEL: dev + CFG_RELEASE: 1.51.0 steps: - uses: actions/checkout@v2 - uses: dtolnay/rust-toolchain@master with: - toolchain: nightly-2020-05-15 + toolchain: nightly-2021-01-01 - run: cd codegen && cargo run - run: git diff --exit-code diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml index 39fa27fa0f..47928f6e0b 100644 --- a/codegen/Cargo.toml +++ b/codegen/Cargo.toml @@ -22,9 +22,9 @@ thiserror = "1.0" toml = "0.5" [dependencies.rustfmt] -package = "rustfmt_lib" -git = "https://github.com/rust-lang-nursery/rustfmt" -rev = "99edc8826ee6d7a5d529e8749cdf4ac999dfd954" +package = "rustfmt-nightly" +git = "https://github.com/rust-lang/rustfmt" +rev = "367a874d04abfb2269ff1ea1974f06640546b7c5" [workspace] # Prefer that `cargo clean` in syn's directory does not require a rebuild of diff --git a/codegen/rust-toolchain b/codegen/rust-toolchain index 8737a7eb56..a2b82fb1f4 100644 --- a/codegen/rust-toolchain +++ b/codegen/rust-toolchain @@ -1 +1 @@ -nightly-2020-05-15 +nightly-2021-01-01 diff --git a/codegen/src/file.rs b/codegen/src/file.rs index 5521d75984..0eeb0c74c1 100644 --- a/codegen/src/file.rs +++ b/codegen/src/file.rs @@ -14,14 +14,21 @@ pub fn write>(path: P, content: TokenStream) -> Result<()> { writeln!(formatted)?; let mut config = rustfmt::Config::default(); - config.set().emit_mode(rustfmt::EmitMode::Stdout); - config.set().verbose(rustfmt::Verbosity::Quiet); config.set().format_macro_matchers(true); config.set().normalize_doc_attributes(true); - let mut session = rustfmt::Session::new(config, Some(&mut formatted)); - session.format(rustfmt::Input::Text(content.to_string()))?; - drop(session); + let format_report = rustfmt::format( + rustfmt::Input::Text(content.to_string()), + &config, + rustfmt::OperationSetting { + recursive: false, + verbosity: rustfmt::emitter::Verbosity::Normal, + }, + )?; + + for (_filename, format_result) in format_report.format_result() { + write!(formatted, "{}", format_result.formatted_text())?; + } if path.as_ref().is_file() && fs::read(&path)? == formatted { return Ok(()); diff --git a/tests/debug/gen.rs b/tests/debug/gen.rs index 85a1a39079..1eae327bb1 100644 --- a/tests/debug/gen.rs +++ b/tests/debug/gen.rs @@ -3424,12 +3424,24 @@ impl Debug for Lite { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { let _val = &self.value; match _val { - syn::Lit::Str(_val) => write!(formatter, "{:?}", _val.value()), - syn::Lit::ByteStr(_val) => write!(formatter, "{:?}", _val.value()), - syn::Lit::Byte(_val) => write!(formatter, "{:?}", _val.value()), - syn::Lit::Char(_val) => write!(formatter, "{:?}", _val.value()), - syn::Lit::Int(_val) => write!(formatter, "{}", _val), - syn::Lit::Float(_val) => write!(formatter, "{}", _val), + syn::Lit::Str(_val) => { + write!(formatter, "{:?}", _val.value()) + } + syn::Lit::ByteStr(_val) => { + write!(formatter, "{:?}", _val.value()) + } + syn::Lit::Byte(_val) => { + write!(formatter, "{:?}", _val.value()) + } + syn::Lit::Char(_val) => { + write!(formatter, "{:?}", _val.value()) + } + syn::Lit::Int(_val) => { + write!(formatter, "{}", _val) + } + syn::Lit::Float(_val) => { + write!(formatter, "{}", _val) + } syn::Lit::Bool(_val) => { let mut formatter = formatter.debug_struct("Lit::Bool"); formatter.field("value", Lite(&_val.value));