Skip to content

Commit 02b4400

Browse files
bors[bot]matklad
andauthored
Merge #3575
3575: Restore cargo-fmt gating r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents b0ed808 + 680182d commit 02b4400

14 files changed

+103
-96
lines changed

crates/ra_hir/src/code_model.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,9 @@ impl Module {
227227
Some((name, def))
228228
}
229229
})
230-
.flat_map(|(name, def)|
231-
ScopeDef::all_items(def)
232-
.into_iter()
233-
.map(move |item| (name.clone(), item))
234-
)
230+
.flat_map(|(name, def)| {
231+
ScopeDef::all_items(def).into_iter().map(move |item| (name.clone(), item))
232+
})
235233
.collect()
236234
}
237235

@@ -1298,10 +1296,8 @@ impl ScopeDef {
12981296
let mut items = ArrayVec::new();
12991297

13001298
match (def.take_types(), def.take_values()) {
1301-
(Some(m1), None) =>
1302-
items.push(ScopeDef::ModuleDef(m1.into())),
1303-
(None, Some(m2)) =>
1304-
items.push(ScopeDef::ModuleDef(m2.into())),
1299+
(Some(m1), None) => items.push(ScopeDef::ModuleDef(m1.into())),
1300+
(None, Some(m2)) => items.push(ScopeDef::ModuleDef(m2.into())),
13051301
(Some(m1), Some(m2)) => {
13061302
// Some items, like unit structs and enum variants, are
13071303
// returned as both a type and a value. Here we want
@@ -1312,8 +1308,8 @@ impl ScopeDef {
13121308
} else {
13131309
items.push(ScopeDef::ModuleDef(m1.into()));
13141310
}
1315-
},
1316-
(None, None) => {},
1311+
}
1312+
(None, None) => {}
13171313
};
13181314

13191315
if let Some(macro_def_id) = def.take_macros() {

crates/ra_hir/src/semantics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ impl<'a, DB: HirDatabase> SemanticsScope<'a, DB> {
349349
for item in items {
350350
f(name.clone(), item);
351351
}
352-
return
353-
},
352+
return;
353+
}
354354
resolver::ScopeDef::ImplSelfType(it) => ScopeDef::ImplSelfType(it.into()),
355355
resolver::ScopeDef::AdtSelfType(it) => ScopeDef::AdtSelfType(it.into()),
356356
resolver::ScopeDef::GenericParam(id) => ScopeDef::GenericParam(TypeParam { id }),

crates/ra_ide/src/completion/complete_path.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1005,5 +1005,4 @@ mod tests {
10051005
"###
10061006
);
10071007
}
1008-
10091008
}

crates/ra_parser/src/grammar/params.rs

+2-20
Original file line numberDiff line numberDiff line change
@@ -82,26 +82,8 @@ const VALUE_PARAMETER_FIRST: TokenSet = patterns::PATTERN_FIRST.union(types::TYP
8282
fn value_parameter(p: &mut Parser, flavor: Flavor) {
8383
let m = p.start();
8484
match flavor {
85-
// test trait_fn_placeholder_parameter
86-
// trait Foo {
87-
// fn bar(_: u64, mut x: i32);
88-
// }
89-
90-
// test trait_fn_patterns
91-
// trait T {
92-
// fn f1((a, b): (usize, usize)) {}
93-
// fn f2(S { a, b }: S) {}
94-
// fn f3(NewType(a): NewType) {}
95-
// fn f4(&&a: &&usize) {}
96-
// }
97-
98-
// test fn_patterns
99-
// impl U {
100-
// fn f1((a, b): (usize, usize)) {}
101-
// fn f2(S { a, b }: S) {}
102-
// fn f3(NewType(a): NewType) {}
103-
// fn f4(&&a: &&usize) {}
104-
// }
85+
// test fn_def_param
86+
// fn foo((x, y): (i32, i32)) {}
10587
Flavor::FnDef => {
10688
patterns::pattern(p);
10789
types::ascription(p);

crates/ra_syntax/test_data/parser/inline/ok/0116_trait_fn_placeholder_parameter.rs

-3
This file was deleted.

crates/ra_syntax/test_data/parser/inline/ok/0116_trait_fn_placeholder_parameter.txt

-47
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fn foo((x, y): (i32, i32)) {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
SOURCE_FILE@[0; 30)
2+
FN_DEF@[0; 29)
3+
FN_KW@[0; 2) "fn"
4+
WHITESPACE@[2; 3) " "
5+
NAME@[3; 6)
6+
IDENT@[3; 6) "foo"
7+
PARAM_LIST@[6; 26)
8+
L_PAREN@[6; 7) "("
9+
PARAM@[7; 25)
10+
TUPLE_PAT@[7; 13)
11+
L_PAREN@[7; 8) "("
12+
BIND_PAT@[8; 9)
13+
NAME@[8; 9)
14+
IDENT@[8; 9) "x"
15+
COMMA@[9; 10) ","
16+
WHITESPACE@[10; 11) " "
17+
BIND_PAT@[11; 12)
18+
NAME@[11; 12)
19+
IDENT@[11; 12) "y"
20+
R_PAREN@[12; 13) ")"
21+
COLON@[13; 14) ":"
22+
WHITESPACE@[14; 15) " "
23+
TUPLE_TYPE@[15; 25)
24+
L_PAREN@[15; 16) "("
25+
PATH_TYPE@[16; 19)
26+
PATH@[16; 19)
27+
PATH_SEGMENT@[16; 19)
28+
NAME_REF@[16; 19)
29+
IDENT@[16; 19) "i32"
30+
COMMA@[19; 20) ","
31+
WHITESPACE@[20; 21) " "
32+
PATH_TYPE@[21; 24)
33+
PATH@[21; 24)
34+
PATH_SEGMENT@[21; 24)
35+
NAME_REF@[21; 24)
36+
IDENT@[21; 24) "i32"
37+
R_PAREN@[24; 25) ")"
38+
R_PAREN@[25; 26) ")"
39+
WHITESPACE@[26; 27) " "
40+
BLOCK_EXPR@[27; 29)
41+
BLOCK@[27; 29)
42+
L_CURLY@[27; 28) "{"
43+
R_CURLY@[28; 29) "}"
44+
WHITESPACE@[29; 30) "\n"

crates/ra_syntax/test_data/parser/inline/ok/0153_trait_fn_patterns.rs renamed to crates/ra_syntax/test_data/parser/ok/0063_trait_fn_patterns.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ trait T {
33
fn f2(S { a, b }: S) {}
44
fn f3(NewType(a): NewType) {}
55
fn f4(&&a: &&usize) {}
6+
fn bar(_: u64, mut x: i32);
67
}

crates/ra_syntax/test_data/parser/inline/ok/0153_trait_fn_patterns.txt renamed to crates/ra_syntax/test_data/parser/ok/0063_trait_fn_patterns.txt

+41-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
SOURCE_FILE@[0; 138)
2-
TRAIT_DEF@[0; 137)
1+
SOURCE_FILE@[0; 170)
2+
TRAIT_DEF@[0; 169)
33
TRAIT_KW@[0; 5) "trait"
44
WHITESPACE@[5; 6) " "
55
NAME@[6; 7)
66
IDENT@[6; 7) "T"
77
WHITESPACE@[7; 8) " "
8-
ITEM_LIST@[8; 137)
8+
ITEM_LIST@[8; 169)
99
L_CURLY@[8; 9) "{"
1010
WHITESPACE@[9; 14) "\n "
1111
FN_DEF@[14; 46)
@@ -156,6 +156,41 @@ SOURCE_FILE@[0; 138)
156156
BLOCK@[133; 135)
157157
L_CURLY@[133; 134) "{"
158158
R_CURLY@[134; 135) "}"
159-
WHITESPACE@[135; 136) "\n"
160-
R_CURLY@[136; 137) "}"
161-
WHITESPACE@[137; 138) "\n"
159+
WHITESPACE@[135; 140) "\n "
160+
FN_DEF@[140; 167)
161+
FN_KW@[140; 142) "fn"
162+
WHITESPACE@[142; 143) " "
163+
NAME@[143; 146)
164+
IDENT@[143; 146) "bar"
165+
PARAM_LIST@[146; 166)
166+
L_PAREN@[146; 147) "("
167+
PARAM@[147; 153)
168+
PLACEHOLDER_PAT@[147; 148)
169+
UNDERSCORE@[147; 148) "_"
170+
COLON@[148; 149) ":"
171+
WHITESPACE@[149; 150) " "
172+
PATH_TYPE@[150; 153)
173+
PATH@[150; 153)
174+
PATH_SEGMENT@[150; 153)
175+
NAME_REF@[150; 153)
176+
IDENT@[150; 153) "u64"
177+
COMMA@[153; 154) ","
178+
WHITESPACE@[154; 155) " "
179+
PARAM@[155; 165)
180+
BIND_PAT@[155; 160)
181+
MUT_KW@[155; 158) "mut"
182+
WHITESPACE@[158; 159) " "
183+
NAME@[159; 160)
184+
IDENT@[159; 160) "x"
185+
COLON@[160; 161) ":"
186+
WHITESPACE@[161; 162) " "
187+
PATH_TYPE@[162; 165)
188+
PATH@[162; 165)
189+
PATH_SEGMENT@[162; 165)
190+
NAME_REF@[162; 165)
191+
IDENT@[162; 165) "i32"
192+
R_PAREN@[165; 166) ")"
193+
SEMI@[166; 167) ";"
194+
WHITESPACE@[167; 168) "\n"
195+
R_CURLY@[168; 169) "}"
196+
WHITESPACE@[169; 170) "\n"

crates/test_utils/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,8 @@ pub fn skip_slow_tests() -> bool {
397397
should_skip
398398
}
399399

400+
const REWRITE: bool = false;
401+
400402
/// Asserts that `expected` and `actual` strings are equal. If they differ only
401403
/// in trailing or leading whitespace the test won't fail and
402404
/// the contents of `actual` will be written to the file located at `path`.
@@ -412,7 +414,6 @@ fn assert_equal_text(expected: &str, actual: &str, path: &Path) {
412414
fs::write(path, actual).unwrap();
413415
return;
414416
}
415-
const REWRITE: bool = false;
416417
if REWRITE {
417418
println!("rewriting {}", pretty_path.display());
418419
fs::write(path, actual).unwrap();

xtask/src/lib.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,11 @@ pub fn project_root() -> PathBuf {
3838
}
3939

4040
pub fn run_rustfmt(mode: Mode) -> Result<()> {
41+
let _dir = pushd(project_root());
4142
ensure_rustfmt()?;
4243

43-
if mode == Mode::Verify {
44-
run!("rustup run {} -- cargo fmt -- --check", TOOLCHAIN)?;
45-
} else {
46-
run!("rustup run {} -- cargo fmt", TOOLCHAIN)?;
47-
}
44+
let check = if mode == Mode::Verify { "--check" } else { "" };
45+
run!("rustup run {} -- cargo fmt -- {}", TOOLCHAIN, check)?;
4846
Ok(())
4947
}
5048

0 commit comments

Comments
 (0)