Skip to content

Commit 6868b93

Browse files
No need for Expectation::IsLast
1 parent aa70e5f commit 6868b93

File tree

3 files changed

+9
-31
lines changed

3 files changed

+9
-31
lines changed

compiler/rustc_hir_typeck/src/_match.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
137137
Some(&arm.body),
138138
arm_ty,
139139
Some(&mut |err| {
140-
self.suggest_removing_semicolon_for_coerce(
141-
err,
142-
expr,
143-
orig_expected,
144-
arm_ty,
145-
prior_arm,
146-
)
140+
self.suggest_removing_semicolon_for_coerce(err, expr, arm_ty, prior_arm)
147141
}),
148142
false,
149143
);
@@ -181,7 +175,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
181175
&self,
182176
diag: &mut Diagnostic,
183177
expr: &hir::Expr<'tcx>,
184-
expectation: Expectation<'tcx>,
185178
arm_ty: Ty<'tcx>,
186179
prior_arm: Option<(Option<hir::HirId>, Ty<'tcx>, Span)>,
187180
) {
@@ -195,7 +188,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
195188
let hir::ExprKind::Block(block, _) = body.value.kind else {
196189
return;
197190
};
198-
let Some(hir::Stmt { kind: hir::StmtKind::Semi(last_expr), .. }) =
191+
let Some(hir::Stmt { kind: hir::StmtKind::Semi(last_expr), span: semi_span, .. }) =
199192
block.innermost_block().stmts.last()
200193
else {
201194
return;
@@ -212,9 +205,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
212205
else {
213206
return;
214207
};
215-
let Expectation::IsLast(stmt) = expectation else {
216-
return;
217-
};
218208

219209
let can_coerce_to_return_ty = match self.ret_coercion.as_ref() {
220210
Some(ret_coercion) => {
@@ -231,7 +221,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
231221
return;
232222
}
233223

234-
let semi_span = expr.span.shrink_to_hi().with_hi(stmt.hi());
224+
let semi_span = expr.span.shrink_to_hi().with_hi(semi_span.hi());
235225
let mut ret_span: MultiSpan = semi_span.into();
236226
ret_span.push_span_label(
237227
expr.span,

compiler/rustc_hir_typeck/src/expectation.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ pub enum Expectation<'tcx> {
2121
/// This rvalue expression will be wrapped in `&` or `Box` and coerced
2222
/// to `&Ty` or `Box<Ty>`, respectively. `Ty` is `[A]` or `Trait`.
2323
ExpectRvalueLikeUnsized(Ty<'tcx>),
24-
25-
IsLast(Span),
2624
}
2725

2826
impl<'a, 'tcx> Expectation<'tcx> {
@@ -88,13 +86,12 @@ impl<'a, 'tcx> Expectation<'tcx> {
8886
ExpectCastableToType(t) => ExpectCastableToType(fcx.resolve_vars_if_possible(t)),
8987
ExpectHasType(t) => ExpectHasType(fcx.resolve_vars_if_possible(t)),
9088
ExpectRvalueLikeUnsized(t) => ExpectRvalueLikeUnsized(fcx.resolve_vars_if_possible(t)),
91-
IsLast(sp) => IsLast(sp),
9289
}
9390
}
9491

9592
pub(super) fn to_option(self, fcx: &FnCtxt<'a, 'tcx>) -> Option<Ty<'tcx>> {
9693
match self.resolve(fcx) {
97-
NoExpectation | IsLast(_) => None,
94+
NoExpectation => None,
9895
ExpectCastableToType(ty) | ExpectHasType(ty) | ExpectRvalueLikeUnsized(ty) => Some(ty),
9996
}
10097
}
@@ -106,9 +103,7 @@ impl<'a, 'tcx> Expectation<'tcx> {
106103
pub(super) fn only_has_type(self, fcx: &FnCtxt<'a, 'tcx>) -> Option<Ty<'tcx>> {
107104
match self {
108105
ExpectHasType(ty) => Some(fcx.resolve_vars_if_possible(ty)),
109-
NoExpectation | ExpectCastableToType(_) | ExpectRvalueLikeUnsized(_) | IsLast(_) => {
110-
None
111-
}
106+
NoExpectation | ExpectCastableToType(_) | ExpectRvalueLikeUnsized(_) => None,
112107
}
113108
}
114109

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14851485
self.check_decl(local.into());
14861486
}
14871487

1488-
pub fn check_stmt(&self, stmt: &'tcx hir::Stmt<'tcx>, is_last: bool) {
1488+
pub fn check_stmt(&self, stmt: &'tcx hir::Stmt<'tcx>) {
14891489
// Don't do all the complex logic below for `DeclItem`.
14901490
match stmt.kind {
14911491
hir::StmtKind::Item(..) => return,
@@ -1512,14 +1512,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15121512
});
15131513
}
15141514
hir::StmtKind::Semi(ref expr) => {
1515-
// All of this is equivalent to calling `check_expr`, but it is inlined out here
1516-
// in order to capture the fact that this `match` is the last statement in its
1517-
// function. This is done for better suggestions to remove the `;`.
1518-
let expectation = match expr.kind {
1519-
hir::ExprKind::Match(..) if is_last => IsLast(stmt.span),
1520-
_ => NoExpectation,
1521-
};
1522-
self.check_expr_with_expectation(expr, expectation);
1515+
self.check_expr(expr);
15231516
}
15241517
}
15251518

@@ -1570,8 +1563,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15701563
let ctxt = BreakableCtxt { coerce: Some(coerce), may_break: false };
15711564

15721565
let (ctxt, ()) = self.with_breakable_ctxt(blk.hir_id, ctxt, || {
1573-
for (pos, s) in blk.stmts.iter().enumerate() {
1574-
self.check_stmt(s, blk.stmts.len() - 1 == pos);
1566+
for s in blk.stmts {
1567+
self.check_stmt(s);
15751568
}
15761569

15771570
// check the tail expression **without** holding the

0 commit comments

Comments
 (0)