Skip to content

Commit 1d0134e

Browse files
committed
bless guard pattern testing + fmt
1 parent 8c5c29f commit 1d0134e

4 files changed

Lines changed: 32 additions & 43 deletions

File tree

compiler/rustc_mir_build/src/builder/matches/match_pair.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ impl<'tcx> MatchPairTree<'tcx> {
361361
}
362362

363363
PatKind::Guard { ref subpattern, condition } => {
364-
extra_data.guard_paterns.push(condition);
364+
extra_data.guard_patterns.push(condition);
365365
MatchPairTree::for_pattern(place_builder, subpattern, cx, match_pairs, extra_data);
366366
return;
367367
}

compiler/rustc_mir_build/src/builder/matches/mod.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -966,9 +966,9 @@ struct PatternExtraData<'tcx> {
966966

967967
/// Whether this corresponds to a never pattern.
968968
is_never: bool,
969-
969+
970970
/// [`ExprId`]s of subpattern conditions
971-
guard_paterns: Vec<ExprId>
971+
guard_patterns: Vec<ExprId>,
972972
}
973973

974974
impl<'tcx> PatternExtraData<'tcx> {
@@ -1013,7 +1013,7 @@ impl<'tcx> FlatPat<'tcx> {
10131013
bindings: Vec::new(),
10141014
ascriptions: Vec::new(),
10151015
is_never: pattern.is_never_pattern(),
1016-
guard_paterns: Vec::new()
1016+
guard_patterns: Vec::new(),
10171017
};
10181018
MatchPairTree::for_pattern(place, pattern, cx, &mut match_pairs, &mut extra_data);
10191019

@@ -1479,7 +1479,7 @@ impl<'tcx> MatchTreeSubBranch<'tcx> {
14791479
.cloned()
14801480
.chain(candidate.extra_data.ascriptions)
14811481
.collect(),
1482-
guard_patterns: candidate.extra_data.guard_paterns,
1482+
guard_patterns: candidate.extra_data.guard_patterns,
14831483
is_never: candidate.extra_data.is_never,
14841484
}
14851485
}
@@ -2435,23 +2435,22 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
24352435

24362436
// Lower an instance of the arm guard (if present) for this candidate,
24372437
// and then perform bindings for the arm body.
2438-
if let Some((arm, match_scope)) = arm_match_scope
2439-
{
2438+
if let Some((arm, match_scope)) = arm_match_scope {
24402439
let tcx = self.tcx;
2441-
2440+
24422441
let mut guards = sub_branch.guard_patterns;
24432442
if let Some(guard) = arm.guard {
24442443
guards.push(guard);
24452444
};
2446-
2445+
24472446
if guards.is_empty() {
24482447
self.bind_matched_candidate_for_arm_body(
24492448
block,
24502449
schedule_drops,
24512450
sub_branch.bindings.iter(),
24522451
);
2453-
2454-
return block
2452+
2453+
return block;
24552454
};
24562455

24572456
// Bindings for guards require some extra handling to automatically

tests/ui/pattern/rfc-3637-guard-patterns/name-resolution.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#![expect(incomplete_features)]
77

88
fn good_fn_item(((x if x) | x): bool) -> bool { x }
9-
//~^ ERROR: used binding `x` is possibly-uninitialized [E0381]
109

1110
fn bad_fn_item_1(x: bool, ((y if x) | y): bool) {}
1211
//~^ ERROR cannot find value `x` in this scope

tests/ui/pattern/rfc-3637-guard-patterns/name-resolution.stderr

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0408]: variable `y` is not bound in all patterns
2-
--> $DIR/name-resolution.rs:38:10
2+
--> $DIR/name-resolution.rs:37:10
33
|
44
LL | ((Ok(x) if y) | (Err(y) if x),) => x && y,
55
| ^^^^^^^^^^^^ - variable not in all patterns
@@ -13,7 +13,7 @@ LL + ((Ok(x) if y) | (Err(x) if x),) => x && y,
1313
|
1414

1515
error[E0408]: variable `x` is not bound in all patterns
16-
--> $DIR/name-resolution.rs:38:25
16+
--> $DIR/name-resolution.rs:37:25
1717
|
1818
LL | ((Ok(x) if y) | (Err(y) if x),) => x && y,
1919
| - ^^^^^^^^^^^^^ pattern doesn't bind `x`
@@ -27,15 +27,15 @@ LL + ((Ok(y) if y) | (Err(y) if x),) => x && y,
2727
|
2828

2929
error[E0408]: variable `x` is not bound in all patterns
30-
--> $DIR/name-resolution.rs:64:28
30+
--> $DIR/name-resolution.rs:63:28
3131
|
3232
LL | Some(x if x > 0) | None => {}
3333
| - ^^^^ pattern doesn't bind `x`
3434
| |
3535
| variable not in all patterns
3636

3737
error[E0425]: cannot find value `x` in this scope
38-
--> $DIR/name-resolution.rs:11:34
38+
--> $DIR/name-resolution.rs:10:34
3939
|
4040
LL | fn bad_fn_item_1(x: bool, ((y if x) | y): bool) {}
4141
| ^
@@ -47,7 +47,7 @@ LL + fn bad_fn_item_1(x: bool, ((y if y) | y): bool) {}
4747
|
4848

4949
error[E0425]: cannot find value `y` in this scope
50-
--> $DIR/name-resolution.rs:13:25
50+
--> $DIR/name-resolution.rs:12:25
5151
|
5252
LL | fn bad_fn_item_2(((x if y) | x): bool, y: bool) {}
5353
| ^
@@ -59,7 +59,7 @@ LL + fn bad_fn_item_2(((x if x) | x): bool, y: bool) {}
5959
|
6060

6161
error[E0425]: cannot find value `x` in this scope
62-
--> $DIR/name-resolution.rs:21:18
62+
--> $DIR/name-resolution.rs:20:18
6363
|
6464
LL | (x, y if x) => x && y,
6565
| ^
@@ -71,7 +71,7 @@ LL + (x, y if y) => x && y,
7171
|
7272

7373
error[E0425]: cannot find value `y` in this scope
74-
--> $DIR/name-resolution.rs:23:15
74+
--> $DIR/name-resolution.rs:22:15
7575
|
7676
LL | (x if y, y) => x && y,
7777
| ^
@@ -83,7 +83,7 @@ LL + (x if x, y) => x && y,
8383
|
8484

8585
error[E0425]: cannot find value `x` in this scope
86-
--> $DIR/name-resolution.rs:30:20
86+
--> $DIR/name-resolution.rs:29:20
8787
|
8888
LL | (x @ (y if x),) => x && y,
8989
| ^
@@ -95,7 +95,7 @@ LL + (x @ (y if y),) => x && y,
9595
|
9696

9797
error[E0425]: cannot find value `y` in this scope
98-
--> $DIR/name-resolution.rs:38:20
98+
--> $DIR/name-resolution.rs:37:20
9999
|
100100
LL | ((Ok(x) if y) | (Err(y) if x),) => x && y,
101101
| ^
@@ -107,7 +107,7 @@ LL + ((Ok(x) if x) | (Err(y) if x),) => x && y,
107107
|
108108

109109
error[E0425]: cannot find value `x` in this scope
110-
--> $DIR/name-resolution.rs:38:36
110+
--> $DIR/name-resolution.rs:37:36
111111
|
112112
LL | ((Ok(x) if y) | (Err(y) if x),) => x && y,
113113
| ^
@@ -119,13 +119,13 @@ LL + ((Ok(x) if y) | (Err(y) if y),) => x && y,
119119
|
120120

121121
error[E0425]: cannot find value `nonexistent` in this scope
122-
--> $DIR/name-resolution.rs:45:15
122+
--> $DIR/name-resolution.rs:44:15
123123
|
124124
LL | let (_ if nonexistent) = true;
125125
| ^^^^^^^^^^^ not found in this scope
126126

127127
error[E0425]: cannot find value `x` in this scope
128-
--> $DIR/name-resolution.rs:47:22
128+
--> $DIR/name-resolution.rs:46:22
129129
|
130130
LL | if let ((x, y if x) | (x if y, y)) = (true, true) { x && y; }
131131
| ^
@@ -137,7 +137,7 @@ LL + if let ((x, y if y) | (x if y, y)) = (true, true) { x && y; }
137137
|
138138

139139
error[E0425]: cannot find value `y` in this scope
140-
--> $DIR/name-resolution.rs:47:33
140+
--> $DIR/name-resolution.rs:46:33
141141
|
142142
LL | if let ((x, y if x) | (x if y, y)) = (true, true) { x && y; }
143143
| ^
@@ -149,7 +149,7 @@ LL + if let ((x, y if x) | (x if x, y)) = (true, true) { x && y; }
149149
|
150150

151151
error[E0425]: cannot find value `x` in this scope
152-
--> $DIR/name-resolution.rs:50:25
152+
--> $DIR/name-resolution.rs:49:25
153153
|
154154
LL | while let ((x, y if x) | (x if y, y)) = (true, true) { x && y; }
155155
| ^
@@ -161,7 +161,7 @@ LL + while let ((x, y if y) | (x if y, y)) = (true, true) { x && y; }
161161
|
162162

163163
error[E0425]: cannot find value `y` in this scope
164-
--> $DIR/name-resolution.rs:50:36
164+
--> $DIR/name-resolution.rs:49:36
165165
|
166166
LL | while let ((x, y if x) | (x if y, y)) = (true, true) { x && y; }
167167
| ^
@@ -173,7 +173,7 @@ LL + while let ((x, y if x) | (x if x, y)) = (true, true) { x && y; }
173173
|
174174

175175
error[E0425]: cannot find value `x` in this scope
176-
--> $DIR/name-resolution.rs:53:19
176+
--> $DIR/name-resolution.rs:52:19
177177
|
178178
LL | for ((x, y if x) | (x if y, y)) in [(true, true)] { x && y; }
179179
| ^
@@ -185,7 +185,7 @@ LL + for ((x, y if y) | (x if y, y)) in [(true, true)] { x && y; }
185185
|
186186

187187
error[E0425]: cannot find value `y` in this scope
188-
--> $DIR/name-resolution.rs:53:30
188+
--> $DIR/name-resolution.rs:52:30
189189
|
190190
LL | for ((x, y if x) | (x if y, y)) in [(true, true)] { x && y; }
191191
| ^
@@ -197,7 +197,7 @@ LL + for ((x, y if x) | (x if x, y)) in [(true, true)] { x && y; }
197197
|
198198

199199
error[E0425]: cannot find value `y` in this scope
200-
--> $DIR/name-resolution.rs:58:13
200+
--> $DIR/name-resolution.rs:57:13
201201
|
202202
LL | (|(x if y), (y if x)| x && y)(true, true);
203203
| ^
@@ -209,7 +209,7 @@ LL + (|(x if x), (y if x)| x && y)(true, true);
209209
|
210210

211211
error[E0425]: cannot find value `x` in this scope
212-
--> $DIR/name-resolution.rs:58:23
212+
--> $DIR/name-resolution.rs:57:23
213213
|
214214
LL | (|(x if y), (y if x)| x && y)(true, true);
215215
| ^
@@ -221,24 +221,15 @@ LL + (|(x if y), (y if y)| x && y)(true, true);
221221
|
222222

223223
error[E0308]: mismatched types
224-
--> $DIR/name-resolution.rs:76:18
224+
--> $DIR/name-resolution.rs:75:18
225225
|
226226
LL | local if local => 0,
227227
| ^^^^^ expected `bool`, found `({integer}, {integer})`
228228
|
229229
= note: expected type `bool`
230230
found tuple `({integer}, {integer})`
231231

232-
error[E0381]: used binding `x` is possibly-uninitialized
233-
--> $DIR/name-resolution.rs:8:49
234-
|
235-
LL | fn good_fn_item(((x if x) | x): bool) -> bool { x }
236-
| - - ^ `x` used here but it is possibly-uninitialized
237-
| | |
238-
| | binding initialized here in some conditions
239-
| binding declared here but left uninitialized
240-
241-
error: aborting due to 21 previous errors
232+
error: aborting due to 20 previous errors
242233

243-
Some errors have detailed explanations: E0308, E0381, E0408, E0425.
234+
Some errors have detailed explanations: E0308, E0408, E0425.
244235
For more information about an error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)