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";
}
}
},
+ 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,
+ );
+ }
+ }
_ => (),
}
}
}
_ => "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"),
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",