X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustc%2Finfer%2Ferror_reporting%2Fmod.rs;h=2995b25308d4c9f455565cf6278f92fa3e3fd988;hb=0d883cb8f82ec5d99f63d03bd43c6fc87d96aeef;hp=4cce8343c02c871f83efe94c4c7f61ac84f92a5d;hpb=dd3e27357d47c4a983d40e19539e3abee22c532d;p=rust.git diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 4cce8343c02..2995b25308d 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -487,6 +487,11 @@ fn check_and_note_conflicting_crates( fn note_error_origin(&self, err: &mut DiagnosticBuilder<'tcx>, cause: &ObligationCause<'tcx>) { match cause.code { + ObligationCauseCode::MatchExpressionArmPattern { span, ty } => { + if ty.is_suggestable() { // don't show type `_` + err.span_label(span, format!("this match expression has type `{}`", ty)); + } + } ObligationCauseCode::MatchExpressionArm { arm_span, source } => match source { hir::MatchSource::IfLetDesugar { .. } => { let msg = "`if let` arm with an incompatible type"; @@ -506,6 +511,18 @@ fn note_error_origin(&self, err: &mut DiagnosticBuilder<'tcx>, cause: &Obligatio } } }, + ObligationCauseCode::IfExpression { then, outer, semicolon } => { + err.span_label(then, "expected because of this"); + outer.map(|sp| err.span_label(sp, "if and else have incompatible types")); + if let Some(sp) = semicolon { + err.span_suggestion_short_with_applicability( + sp, + "consider removing this semicolon", + String::new(), + Applicability::MachineApplicable, + ); + } + } _ => (), } } @@ -1455,7 +1472,7 @@ fn as_failure_code(&self, terr: &TypeError<'tcx>) -> FailureCode { } _ => "match arms have incompatible types", }), - IfExpression => Error0308("if and else have incompatible types"), + IfExpression { .. } => Error0308("if and else have incompatible types"), IfExpressionWithNoElse => Error0317("if may be missing an else clause"), MainFunctionType => Error0580("main function has wrong type"), StartFunctionType => Error0308("start function has wrong type"), @@ -1483,7 +1500,7 @@ fn as_requirement_str(&self) -> &'static str { hir::MatchSource::IfLetDesugar { .. } => "`if let` arms have compatible types", _ => "match arms have compatible types", }, - IfExpression => "if and else have compatible types", + IfExpression { .. } => "if and else have compatible types", IfExpressionWithNoElse => "if missing an else returns ()", MainFunctionType => "`main` function has the correct type", StartFunctionType => "`start` function has the correct type",