mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 19:58:32 +00:00
parent
16143d1067
commit
650877de45
@ -1440,9 +1440,8 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
|
|||||||
// as prior return coercions would not be relevant (#57664).
|
// as prior return coercions would not be relevant (#57664).
|
||||||
let parent_id = fcx.tcx.hir().get_parent_node(id);
|
let parent_id = fcx.tcx.hir().get_parent_node(id);
|
||||||
let fn_decl = if let Some((expr, blk_id)) = expression {
|
let fn_decl = if let Some((expr, blk_id)) = expression {
|
||||||
pointing_at_return_type = fcx.suggest_mismatched_types_on_tail(
|
pointing_at_return_type =
|
||||||
&mut err, expr, expected, found, cause.span, blk_id,
|
fcx.suggest_mismatched_types_on_tail(&mut err, expr, expected, found, blk_id);
|
||||||
);
|
|
||||||
let parent = fcx.tcx.hir().get(parent_id);
|
let parent = fcx.tcx.hir().get(parent_id);
|
||||||
if let (Some(cond_expr), true, false) = (
|
if let (Some(cond_expr), true, false) = (
|
||||||
fcx.tcx.hir().get_if_cause(expr.hir_id),
|
fcx.tcx.hir().get_if_cause(expr.hir_id),
|
||||||
|
@ -603,7 +603,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
&cause,
|
&cause,
|
||||||
&mut |mut err| {
|
&mut |mut err| {
|
||||||
self.suggest_mismatched_types_on_tail(
|
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) {
|
if let Some(val) = ty_kind_suggestion(ty) {
|
||||||
let label = destination
|
let label = destination
|
||||||
|
@ -41,15 +41,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
expr: &'tcx hir::Expr<'tcx>,
|
expr: &'tcx hir::Expr<'tcx>,
|
||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
found: Ty<'tcx>,
|
found: Ty<'tcx>,
|
||||||
cause_span: Span,
|
|
||||||
blk_id: hir::HirId,
|
blk_id: hir::HirId,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let expr = expr.peel_drop_temps();
|
let expr = expr.peel_drop_temps();
|
||||||
// If the expression is from an external macro, then do not suggest
|
// If the expression is from an external macro, then do not suggest
|
||||||
// adding a semicolon, because there's nowhere to put it.
|
// adding a semicolon, because there's nowhere to put it.
|
||||||
// See issue #81943.
|
// See issue #81943.
|
||||||
if expr.can_have_side_effects() && !in_external_macro(self.tcx.sess, cause_span) {
|
if expr.can_have_side_effects() && !in_external_macro(self.tcx.sess, expr.span) {
|
||||||
self.suggest_missing_semicolon(err, expr, expected, cause_span);
|
self.suggest_missing_semicolon(err, expr, expected);
|
||||||
}
|
}
|
||||||
let mut pointing_at_return_type = false;
|
let mut pointing_at_return_type = false;
|
||||||
if let Some((fn_decl, can_suggest)) = self.get_fn_decl(blk_id) {
|
if let Some((fn_decl, can_suggest)) = self.get_fn_decl(blk_id) {
|
||||||
@ -388,7 +387,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
err: &mut DiagnosticBuilder<'_>,
|
err: &mut DiagnosticBuilder<'_>,
|
||||||
expression: &'tcx hir::Expr<'tcx>,
|
expression: &'tcx hir::Expr<'tcx>,
|
||||||
expected: Ty<'tcx>,
|
expected: Ty<'tcx>,
|
||||||
cause_span: Span,
|
|
||||||
) {
|
) {
|
||||||
if expected.is_unit() {
|
if expected.is_unit() {
|
||||||
// `BlockTailExpression` only relevant if the tail expr would be
|
// `BlockTailExpression` only relevant if the tail expr would be
|
||||||
@ -403,7 +401,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
if expression.can_have_side_effects() =>
|
if expression.can_have_side_effects() =>
|
||||||
{
|
{
|
||||||
err.span_suggestion(
|
err.span_suggestion(
|
||||||
cause_span.shrink_to_hi(),
|
expression.span.shrink_to_hi(),
|
||||||
"consider using a semicolon here",
|
"consider using a semicolon here",
|
||||||
";".to_string(),
|
";".to_string(),
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
|
11
src/test/ui/suggestions/issue-83892.fixed
Normal file
11
src/test/ui/suggestions/issue-83892.fixed
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// run-rustfix
|
||||||
|
|
||||||
|
fn func() -> u8 {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
match () {
|
||||||
|
() => func() //~ ERROR mismatched types
|
||||||
|
};
|
||||||
|
}
|
11
src/test/ui/suggestions/issue-83892.rs
Normal file
11
src/test/ui/suggestions/issue-83892.rs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// run-rustfix
|
||||||
|
|
||||||
|
fn func() -> u8 {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
match () {
|
||||||
|
() => func() //~ ERROR mismatched types
|
||||||
|
}
|
||||||
|
}
|
14
src/test/ui/suggestions/issue-83892.stderr
Normal file
14
src/test/ui/suggestions/issue-83892.stderr
Normal file
@ -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`.
|
Loading…
Reference in New Issue
Block a user