Skip to content

Commit

Permalink
Update internal code generator to rustfmt 2.0.0-rc.2
Browse files Browse the repository at this point in the history
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<A: Array> {
    354 | |     inline: core::mem::ManuallyDrop<MaybeUninit<A>>,
    355 | |     heap: (*mut A::Item, usize),
    356 | | }
        | |_^
        |
        = note: see issue #55149 <rust-lang/rust#55149> for more information
        = help: add `#![feature(untagged_unions)]` to the crate attributes to enable
  • Loading branch information
dtolnay committed Jan 1, 2021
1 parent 71f401c commit a632de1
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 16 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions codegen/Cargo.toml
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion codegen/rust-toolchain
@@ -1 +1 @@
nightly-2020-05-15
nightly-2021-01-01
17 changes: 12 additions & 5 deletions codegen/src/file.rs
Expand Up @@ -14,14 +14,21 @@ pub fn write<P: AsRef<Path>>(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(());
Expand Down
24 changes: 18 additions & 6 deletions tests/debug/gen.rs
Expand Up @@ -3424,12 +3424,24 @@ impl Debug for Lite<syn::Lit> {
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));
Expand Down

0 comments on commit a632de1

Please sign in to comment.