Skip to content

Commit 971608b

Browse files
committed
Auto merge of #83956 - estebank:issue-83892, r=varkor
Use a more appropriate span for `;` suggestion Fix #83892.
2 parents cd56e25 + 650877d commit 971608b

File tree

6 files changed

+42
-9
lines changed

6 files changed

+42
-9
lines changed

compiler/rustc_typeck/src/check/coercion.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1440,9 +1440,8 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
14401440
// as prior return coercions would not be relevant (#57664).
14411441
let parent_id = fcx.tcx.hir().get_parent_node(id);
14421442
let fn_decl = if let Some((expr, blk_id)) = expression {
1443-
pointing_at_return_type = fcx.suggest_mismatched_types_on_tail(
1444-
&mut err, expr, expected, found, cause.span, blk_id,
1445-
);
1443+
pointing_at_return_type =
1444+
fcx.suggest_mismatched_types_on_tail(&mut err, expr, expected, found, blk_id);
14461445
let parent = fcx.tcx.hir().get(parent_id);
14471446
if let (Some(cond_expr), true, false) = (
14481447
fcx.tcx.hir().get_if_cause(expr.hir_id),

compiler/rustc_typeck/src/check/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
603603
&cause,
604604
&mut |mut err| {
605605
self.suggest_mismatched_types_on_tail(
606-
&mut err, expr, ty, e_ty, cause.span, target_id,
606+
&mut err, expr, ty, e_ty, target_id,
607607
);
608608
if let Some(val) = ty_kind_suggestion(ty) {
609609
let label = destination

compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
4141
expr: &'tcx hir::Expr<'tcx>,
4242
expected: Ty<'tcx>,
4343
found: Ty<'tcx>,
44-
cause_span: Span,
4544
blk_id: hir::HirId,
4645
) -> bool {
4746
let expr = expr.peel_drop_temps();
4847
// If the expression is from an external macro, then do not suggest
4948
// adding a semicolon, because there's nowhere to put it.
5049
// See issue #81943.
51-
if expr.can_have_side_effects() && !in_external_macro(self.tcx.sess, cause_span) {
52-
self.suggest_missing_semicolon(err, expr, expected, cause_span);
50+
if expr.can_have_side_effects() && !in_external_macro(self.tcx.sess, expr.span) {
51+
self.suggest_missing_semicolon(err, expr, expected);
5352
}
5453
let mut pointing_at_return_type = false;
5554
if let Some((fn_decl, can_suggest)) = self.get_fn_decl(blk_id) {
@@ -389,7 +388,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
389388
err: &mut DiagnosticBuilder<'_>,
390389
expression: &'tcx hir::Expr<'tcx>,
391390
expected: Ty<'tcx>,
392-
cause_span: Span,
393391
) {
394392
if expected.is_unit() {
395393
// `BlockTailExpression` only relevant if the tail expr would be
@@ -404,7 +402,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
404402
if expression.can_have_side_effects() =>
405403
{
406404
err.span_suggestion(
407-
cause_span.shrink_to_hi(),
405+
expression.span.shrink_to_hi(),
408406
"consider using a semicolon here",
409407
";".to_string(),
410408
Applicability::MachineApplicable,
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// run-rustfix
2+
3+
fn func() -> u8 {
4+
0
5+
}
6+
7+
fn main() {
8+
match () {
9+
() => func() //~ ERROR mismatched types
10+
};
11+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// run-rustfix
2+
3+
fn func() -> u8 {
4+
0
5+
}
6+
7+
fn main() {
8+
match () {
9+
() => func() //~ ERROR mismatched types
10+
}
11+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-83892.rs:9:15
3+
|
4+
LL | fn main() {
5+
| - expected `()` because of default return type
6+
LL | match () {
7+
LL | () => func()
8+
| ^^^^^^ expected `()`, found `u8`
9+
LL | }
10+
| - help: consider using a semicolon here: `;`
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)