Skip to content

Use a more appropriate span for ; suggestion #83956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions compiler/rustc_typeck/src/check/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1440,9 +1440,8 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
// as prior return coercions would not be relevant (#57664).
let parent_id = fcx.tcx.hir().get_parent_node(id);
let fn_decl = if let Some((expr, blk_id)) = expression {
pointing_at_return_type = fcx.suggest_mismatched_types_on_tail(
&mut err, expr, expected, found, cause.span, blk_id,
);
pointing_at_return_type =
fcx.suggest_mismatched_types_on_tail(&mut err, expr, expected, found, blk_id);
let parent = fcx.tcx.hir().get(parent_id);
if let (Some(cond_expr), true, false) = (
fcx.tcx.hir().get_if_cause(expr.hir_id),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&cause,
&mut |mut err| {
self.suggest_mismatched_types_on_tail(
&mut err, expr, ty, e_ty, cause.span, target_id,
&mut err, expr, ty, e_ty, target_id,
);
if let Some(val) = ty_kind_suggestion(ty) {
let label = destination
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expr: &'tcx hir::Expr<'tcx>,
expected: Ty<'tcx>,
found: Ty<'tcx>,
cause_span: Span,
blk_id: hir::HirId,
) -> bool {
let expr = expr.peel_drop_temps();
// If the expression is from an external macro, then do not suggest
// adding a semicolon, because there's nowhere to put it.
// See issue #81943.
if expr.can_have_side_effects() && !in_external_macro(self.tcx.sess, cause_span) {
self.suggest_missing_semicolon(err, expr, expected, cause_span);
if expr.can_have_side_effects() && !in_external_macro(self.tcx.sess, expr.span) {
self.suggest_missing_semicolon(err, expr, expected);
}
let mut pointing_at_return_type = false;
if let Some((fn_decl, can_suggest)) = self.get_fn_decl(blk_id) {
Expand Down Expand Up @@ -388,7 +387,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err: &mut DiagnosticBuilder<'_>,
expression: &'tcx hir::Expr<'tcx>,
expected: Ty<'tcx>,
cause_span: Span,
) {
if expected.is_unit() {
// `BlockTailExpression` only relevant if the tail expr would be
Expand All @@ -403,7 +401,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if expression.can_have_side_effects() =>
{
err.span_suggestion(
cause_span.shrink_to_hi(),
expression.span.shrink_to_hi(),
"consider using a semicolon here",
";".to_string(),
Applicability::MachineApplicable,
Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/suggestions/issue-83892.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// run-rustfix

fn func() -> u8 {
0
}

fn main() {
match () {
() => func() //~ ERROR mismatched types
};
}
11 changes: 11 additions & 0 deletions src/test/ui/suggestions/issue-83892.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// run-rustfix

fn func() -> u8 {
0
}

fn main() {
match () {
() => func() //~ ERROR mismatched types
}
}
14 changes: 14 additions & 0 deletions src/test/ui/suggestions/issue-83892.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0308]: mismatched types
--> $DIR/issue-83892.rs:9:15
|
LL | fn main() {
| - expected `()` because of default return type
LL | match () {
LL | () => func()
| ^^^^^^ expected `()`, found `u8`
LL | }
| - help: consider using a semicolon here: `;`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.