Commit fc975344 authored by Federico Mena Quintero's avatar Federico Mena Quintero

Merge branch 'alexcrichton/gnome-class-rustfmt'

parents 38043d55 8bcada8b
This diff is collapsed.
......@@ -37,7 +37,6 @@ gobject-sys = "0.7.0"
libc = "0.2"
proc-macro2 = {version = "0.4.8"}
quote = { version="0.6" }
rustfmt = "0.10.0"
syn = { version="0.15.3", features=["full", "extra-traits"] }
unicode-xid = "0.0.4"
xml-rs = "0.8.0"
......
......@@ -3,10 +3,10 @@ use crate::hir::generatorattrs::{Generator, GeneratorAttributes};
use difference::{Changeset, Difference};
use proc_macro2::{Span, TokenStream};
use quote::ToTokens;
use rustfmt;
use std::fs::{self, File};
use std::io::{Result as IoResult, Write};
use std::io::{Read, Result as IoResult, Write};
use std::iter::FromIterator;
use std::process::{Command, Stdio};
use std::rc::Rc;
use syn::LitStr;
......@@ -281,13 +281,26 @@ impl RustWriter {
/// Apply rustfmt on a TokenStream
fn format_stream(path: &LitStr, tokens: Vec<Rc<TokenStream>>) -> Result<Vec<u8>> {
let mut config: rustfmt::config::Config = Default::default();
let mut out: Vec<u8> = vec![];
config.set().write_mode(rustfmt::config::WriteMode::Plain);
config.set().error_on_line_overflow(false);
let stream: String = tokens.iter().map(|token| token.to_string()).collect();
rustfmt::format_input(rustfmt::Input::Text(stream), &config, Some(&mut out))
.map_err(|e| format_err!(path, "{}", e.0))?;
let mut child = Command::new("rustfmt")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::inherit())
.spawn()
.map_err(|e| format_err!(path, "{}", e))?;
child
.stdin
.take()
.unwrap()
.write_all(stream.as_bytes())
.map_err(|e| format_err!(path, "{}", e))?;
let mut out = Vec::new();
child
.stdout
.take()
.unwrap()
.read_to_end(&mut out)
.map_err(|e| format_err!(path, "{}", e))?;
Ok(out)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment