Skip to content

Commit 5407fbd

Browse files
committed
Match discriminant -> scrutinee
1 parent d51b5cd commit 5407fbd

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

src/librustc_mir/build/expr/into.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
5353
ExprKind::Block { body: ast_block } => {
5454
this.ast_block(destination, block, ast_block, source_info)
5555
}
56-
ExprKind::Match { discriminant, arms } => {
57-
this.match_expr(destination, expr_span, block, discriminant, arms)
56+
ExprKind::Match { scrutinee, arms } => {
57+
this.match_expr(destination, expr_span, block, scrutinee, arms)
5858
}
5959
ExprKind::NeverToAny { source } => {
6060
let source = this.hir.mirror(source);

src/librustc_mir/build/matches/mod.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
3333
/// ```text
3434
/// [ 0. Pre-match ]
3535
/// |
36-
/// [ 1. Evaluate Scrutinee]
36+
/// [ 1. Evaluate Scrutinee (expression being matched on) ]
3737
/// [ (fake read of scrutinee) ]
3838
/// |
3939
/// [ 2. Decision tree -- check discriminants ] <--------+
@@ -102,38 +102,38 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
102102
destination: &Place<'tcx>,
103103
span: Span,
104104
mut block: BasicBlock,
105-
discriminant: ExprRef<'tcx>,
105+
scrutinee: ExprRef<'tcx>,
106106
arms: Vec<Arm<'tcx>>,
107107
) -> BlockAnd<()> {
108108
let tcx = self.hir.tcx();
109109

110110
// Step 1. Evaluate the scrutinee and add the fake read of it.
111111

112-
let discriminant_span = discriminant.span();
113-
let discriminant_place = unpack!(block = self.as_place(block, discriminant));
112+
let scrutinee_span = scrutinee.span();
113+
let scrutinee_place = unpack!(block = self.as_place(block, scrutinee));
114114

115-
// Matching on a `discriminant_place` with an uninhabited type doesn't
115+
// Matching on a `scrutinee_place` with an uninhabited type doesn't
116116
// generate any memory reads by itself, and so if the place "expression"
117117
// contains unsafe operations like raw pointer dereferences or union
118118
// field projections, we wouldn't know to require an `unsafe` block
119119
// around a `match` equivalent to `std::intrinsics::unreachable()`.
120120
// See issue #47412 for this hole being discovered in the wild.
121121
//
122122
// HACK(eddyb) Work around the above issue by adding a dummy inspection
123-
// of `discriminant_place`, specifically by applying `ReadForMatch`.
123+
// of `scrutinee_place`, specifically by applying `ReadForMatch`.
124124
//
125-
// NOTE: ReadForMatch also checks that the discriminant is initialized.
125+
// NOTE: ReadForMatch also checks that the scrutinee is initialized.
126126
// This is currently needed to not allow matching on an uninitialized,
127127
// uninhabited value. If we get never patterns, those will check that
128128
// the place is initialized, and so this read would only be used to
129129
// check safety.
130130

131-
let source_info = self.source_info(discriminant_span);
131+
let source_info = self.source_info(scrutinee_span);
132132
self.cfg.push(block, Statement {
133133
source_info,
134134
kind: StatementKind::FakeRead(
135135
FakeReadCause::ForMatchedPlace,
136-
discriminant_place.clone(),
136+
scrutinee_place.clone(),
137137
),
138138
});
139139

@@ -175,7 +175,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
175175
Candidate {
176176
span: pattern.span,
177177
match_pairs: vec![
178-
MatchPair::new(discriminant_place.clone(), pattern),
178+
MatchPair::new(scrutinee_place.clone(), pattern),
179179
],
180180
bindings: vec![],
181181
ascriptions: vec![],
@@ -216,10 +216,10 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
216216
.flat_map(|(_, candidates)| candidates)
217217
.collect::<Vec<_>>();
218218

219-
// this will generate code to test discriminant_place and
219+
// this will generate code to test scrutinee_place and
220220
// branch to the appropriate arm block
221221
let otherwise = self.match_candidates(
222-
discriminant_span,
222+
scrutinee_span,
223223
candidates,
224224
block,
225225
&mut fake_borrows,
@@ -245,7 +245,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
245245
// places. Create the required temporaries for them.
246246

247247
let fake_borrow_temps = if let Some(ref borrows) = fake_borrows {
248-
self.calculate_fake_borrows(borrows, discriminant_span)
248+
self.calculate_fake_borrows(borrows, scrutinee_span)
249249
} else {
250250
Vec::new()
251251
};
@@ -267,7 +267,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
267267
LintLevel::Inherited,
268268
&arm.patterns[..],
269269
ArmHasGuard(arm.guard.is_some()),
270-
Some((Some(&discriminant_place), discriminant_span)),
270+
Some((Some(&scrutinee_place), scrutinee_span)),
271271
);
272272

273273
for (pat_index, candidate) in candidates.into_iter().enumerate() {
@@ -276,7 +276,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
276276
arm.guard.clone(),
277277
arm_block,
278278
&fake_borrow_temps,
279-
discriminant_span,
279+
scrutinee_span,
280280
pat_index,
281281
);
282282
}
@@ -1302,7 +1302,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
13021302
guard: Option<Guard<'tcx>>,
13031303
arm_block: BasicBlock,
13041304
fake_borrows: &Vec<(&Place<'tcx>, BorrowKind, Local)>,
1305-
discriminant_span: Span,
1305+
scrutinee_span: Span,
13061306
pat_index: usize,
13071307
) {
13081308
debug!("bind_and_guard_matched_candidate(candidate={:?})", candidate);
@@ -1427,7 +1427,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
14271427
}
14281428

14291429
let re_erased = tcx.types.re_erased;
1430-
let discriminant_source_info = self.source_info(discriminant_span);
1430+
let scrutinee_source_info = self.source_info(scrutinee_span);
14311431
for &(place, borrow_kind, temp) in fake_borrows {
14321432
let borrow = Rvalue::Ref(
14331433
re_erased,
@@ -1436,7 +1436,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
14361436
);
14371437
self.cfg.push_assign(
14381438
block,
1439-
discriminant_source_info,
1439+
scrutinee_source_info,
14401440
&Place::Local(temp),
14411441
borrow,
14421442
);

src/librustc_mir/hair/cx/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
611611
}
612612
hir::ExprKind::Match(ref discr, ref arms, _) => {
613613
ExprKind::Match {
614-
discriminant: discr.to_ref(),
614+
scrutinee: discr.to_ref(),
615615
arms: arms.iter().map(|a| convert_arm(cx, a)).collect(),
616616
}
617617
}

src/librustc_mir/hair/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ pub enum ExprKind<'tcx> {
203203
body: ExprRef<'tcx>,
204204
},
205205
Match {
206-
discriminant: ExprRef<'tcx>,
206+
scrutinee: ExprRef<'tcx>,
207207
arms: Vec<Arm<'tcx>>,
208208
},
209209
Block {

0 commit comments

Comments
 (0)