Skip to content

Commit 8627f52

Browse files
committed
uses should come first
1 parent 40eb6ce commit 8627f52

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

xtask/src/commands/export.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub(crate) fn run(opt: OptExport, shell: &mut Shell) -> anyhow::Result<()> {
4343
let syn::File { items, .. } =
4444
syn::parse_file(&code).with_context(|| format!("`{}` is broken", src_path.display()))?;
4545

46-
let mut acc = "".to_owned();
46+
let mut acc = vec!["".to_owned(), "".to_owned()];
4747

4848
for item in items {
4949
match item {
@@ -55,6 +55,7 @@ pub(crate) fn run(opt: OptExport, shell: &mut Shell) -> anyhow::Result<()> {
5555
semi: Some(_),
5656
..
5757
}) => {
58+
let acc = &mut acc[1];
5859
let path = src_path
5960
.with_file_name(ident.to_string())
6061
.with_extension("rs");
@@ -75,32 +76,33 @@ pub(crate) fn run(opt: OptExport, shell: &mut Shell) -> anyhow::Result<()> {
7576
});
7677

7778
for attr in attrs {
78-
acc += &attr.to_token_stream().to_string();
79-
acc += "\n";
79+
*acc += &attr.to_token_stream().to_string();
80+
*acc += "\n";
8081
}
81-
acc += &vis.to_token_stream().to_string();
82-
acc += " mod ";
83-
acc += &ident.to_string();
84-
acc += " {\n";
82+
*acc += &vis.to_token_stream().to_string();
83+
*acc += " mod ";
84+
*acc += &ident.to_string();
85+
*acc += " {\n";
8586
if is_safe_to_indent {
8687
for line in content.lines() {
87-
acc += " ";
88-
acc += line;
89-
acc += "\n";
88+
*acc += " ";
89+
*acc += line;
90+
*acc += "\n";
9091
}
9192
} else {
92-
acc += &content;
93+
*acc += &content;
9394
}
94-
acc += "}\n";
95+
*acc += "}\n";
9596
}
9697
item => {
97-
acc += &item.to_token_stream().to_string();
98-
acc += "\n";
98+
let acc = &mut acc[0];
99+
*acc += &item.to_token_stream().to_string();
100+
*acc += "\n";
99101
}
100102
}
101103
}
102104

103-
acc = rustfmt(&acc)?;
105+
let acc = rustfmt(&acc.join("\n"))?;
104106

105107
shell.status(
106108
"Expanded",

0 commit comments

Comments
 (0)