No need for Expectation::IsLast
This commit is contained in:
parent
aa70e5fb6e
commit
6868b93cf5
@ -137,13 +137,7 @@ pub fn check_match(
|
||||
Some(&arm.body),
|
||||
arm_ty,
|
||||
Some(&mut |err| {
|
||||
self.suggest_removing_semicolon_for_coerce(
|
||||
err,
|
||||
expr,
|
||||
orig_expected,
|
||||
arm_ty,
|
||||
prior_arm,
|
||||
)
|
||||
self.suggest_removing_semicolon_for_coerce(err, expr, arm_ty, prior_arm)
|
||||
}),
|
||||
false,
|
||||
);
|
||||
@ -181,7 +175,6 @@ fn suggest_removing_semicolon_for_coerce(
|
||||
&self,
|
||||
diag: &mut Diagnostic,
|
||||
expr: &hir::Expr<'tcx>,
|
||||
expectation: Expectation<'tcx>,
|
||||
arm_ty: Ty<'tcx>,
|
||||
prior_arm: Option<(Option<hir::HirId>, Ty<'tcx>, Span)>,
|
||||
) {
|
||||
@ -195,7 +188,7 @@ fn suggest_removing_semicolon_for_coerce(
|
||||
let hir::ExprKind::Block(block, _) = body.value.kind else {
|
||||
return;
|
||||
};
|
||||
let Some(hir::Stmt { kind: hir::StmtKind::Semi(last_expr), .. }) =
|
||||
let Some(hir::Stmt { kind: hir::StmtKind::Semi(last_expr), span: semi_span, .. }) =
|
||||
block.innermost_block().stmts.last()
|
||||
else {
|
||||
return;
|
||||
@ -212,9 +205,6 @@ fn suggest_removing_semicolon_for_coerce(
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let Expectation::IsLast(stmt) = expectation else {
|
||||
return;
|
||||
};
|
||||
|
||||
let can_coerce_to_return_ty = match self.ret_coercion.as_ref() {
|
||||
Some(ret_coercion) => {
|
||||
@ -231,7 +221,7 @@ fn suggest_removing_semicolon_for_coerce(
|
||||
return;
|
||||
}
|
||||
|
||||
let semi_span = expr.span.shrink_to_hi().with_hi(stmt.hi());
|
||||
let semi_span = expr.span.shrink_to_hi().with_hi(semi_span.hi());
|
||||
let mut ret_span: MultiSpan = semi_span.into();
|
||||
ret_span.push_span_label(
|
||||
expr.span,
|
||||
|
@ -21,8 +21,6 @@ pub enum Expectation<'tcx> {
|
||||
/// This rvalue expression will be wrapped in `&` or `Box` and coerced
|
||||
/// to `&Ty` or `Box<Ty>`, respectively. `Ty` is `[A]` or `Trait`.
|
||||
ExpectRvalueLikeUnsized(Ty<'tcx>),
|
||||
|
||||
IsLast(Span),
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Expectation<'tcx> {
|
||||
@ -88,13 +86,12 @@ fn resolve(self, fcx: &FnCtxt<'a, 'tcx>) -> Expectation<'tcx> {
|
||||
ExpectCastableToType(t) => ExpectCastableToType(fcx.resolve_vars_if_possible(t)),
|
||||
ExpectHasType(t) => ExpectHasType(fcx.resolve_vars_if_possible(t)),
|
||||
ExpectRvalueLikeUnsized(t) => ExpectRvalueLikeUnsized(fcx.resolve_vars_if_possible(t)),
|
||||
IsLast(sp) => IsLast(sp),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn to_option(self, fcx: &FnCtxt<'a, 'tcx>) -> Option<Ty<'tcx>> {
|
||||
match self.resolve(fcx) {
|
||||
NoExpectation | IsLast(_) => None,
|
||||
NoExpectation => None,
|
||||
ExpectCastableToType(ty) | ExpectHasType(ty) | ExpectRvalueLikeUnsized(ty) => Some(ty),
|
||||
}
|
||||
}
|
||||
@ -106,9 +103,7 @@ pub(super) fn to_option(self, fcx: &FnCtxt<'a, 'tcx>) -> Option<Ty<'tcx>> {
|
||||
pub(super) fn only_has_type(self, fcx: &FnCtxt<'a, 'tcx>) -> Option<Ty<'tcx>> {
|
||||
match self {
|
||||
ExpectHasType(ty) => Some(fcx.resolve_vars_if_possible(ty)),
|
||||
NoExpectation | ExpectCastableToType(_) | ExpectRvalueLikeUnsized(_) | IsLast(_) => {
|
||||
None
|
||||
}
|
||||
NoExpectation | ExpectCastableToType(_) | ExpectRvalueLikeUnsized(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1485,7 +1485,7 @@ pub fn check_decl_local(&self, local: &'tcx hir::Local<'tcx>) {
|
||||
self.check_decl(local.into());
|
||||
}
|
||||
|
||||
pub fn check_stmt(&self, stmt: &'tcx hir::Stmt<'tcx>, is_last: bool) {
|
||||
pub fn check_stmt(&self, stmt: &'tcx hir::Stmt<'tcx>) {
|
||||
// Don't do all the complex logic below for `DeclItem`.
|
||||
match stmt.kind {
|
||||
hir::StmtKind::Item(..) => return,
|
||||
@ -1512,14 +1512,7 @@ pub fn check_stmt(&self, stmt: &'tcx hir::Stmt<'tcx>, is_last: bool) {
|
||||
});
|
||||
}
|
||||
hir::StmtKind::Semi(ref expr) => {
|
||||
// All of this is equivalent to calling `check_expr`, but it is inlined out here
|
||||
// in order to capture the fact that this `match` is the last statement in its
|
||||
// function. This is done for better suggestions to remove the `;`.
|
||||
let expectation = match expr.kind {
|
||||
hir::ExprKind::Match(..) if is_last => IsLast(stmt.span),
|
||||
_ => NoExpectation,
|
||||
};
|
||||
self.check_expr_with_expectation(expr, expectation);
|
||||
self.check_expr(expr);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1570,8 +1563,8 @@ pub(in super::super) fn check_block_with_expected(
|
||||
let ctxt = BreakableCtxt { coerce: Some(coerce), may_break: false };
|
||||
|
||||
let (ctxt, ()) = self.with_breakable_ctxt(blk.hir_id, ctxt, || {
|
||||
for (pos, s) in blk.stmts.iter().enumerate() {
|
||||
self.check_stmt(s, blk.stmts.len() - 1 == pos);
|
||||
for s in blk.stmts {
|
||||
self.check_stmt(s);
|
||||
}
|
||||
|
||||
// check the tail expression **without** holding the
|
||||
|
Loading…
Reference in New Issue
Block a user