auto merge of #14561 : jakub-/rust/issue-11319, r=alexcrichton
Fixes #11319
This commit is contained in:
commit
5527c5dc06
4 changed files with 33 additions and 8 deletions
|
@ -87,7 +87,7 @@ pub fn check_match(fcx: &FnCtxt,
|
|||
result_ty =
|
||||
infer::common_supertype(
|
||||
fcx.infcx(),
|
||||
infer::MatchExpression(expr.span),
|
||||
infer::MatchExpressionArm(expr.span, arm.body.span),
|
||||
true, // result_ty is "expected" here
|
||||
result_ty,
|
||||
bty);
|
||||
|
|
|
@ -346,7 +346,7 @@ impl<'a> ErrorReporting for InferCtxt<'a> {
|
|||
infer::ExprAssignable(_) => "mismatched types",
|
||||
infer::RelateTraitRefs(_) => "mismatched traits",
|
||||
infer::RelateSelfType(_) => "mismatched types",
|
||||
infer::MatchExpression(_) => "match arms have incompatible types",
|
||||
infer::MatchExpressionArm(_, _) => "match arms have incompatible types",
|
||||
infer::IfExpression(_) => "if and else have incompatible types",
|
||||
};
|
||||
|
||||
|
@ -356,6 +356,12 @@ impl<'a> ErrorReporting for InferCtxt<'a> {
|
|||
message_root_str,
|
||||
expected_found_str,
|
||||
ty::type_err_to_str(self.tcx, terr)).as_slice());
|
||||
|
||||
match trace.origin {
|
||||
infer::MatchExpressionArm(_, arm_span) =>
|
||||
self.tcx.sess.span_note(arm_span, "match arm with an incompatible type"),
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
||||
fn report_and_explain_type_error(&self,
|
||||
|
@ -1281,7 +1287,7 @@ impl<'a> ErrorReportingHelpers for InferCtxt<'a> {
|
|||
infer::RelateSelfType(_) => {
|
||||
format!("type matches impl")
|
||||
}
|
||||
infer::MatchExpression(_) => {
|
||||
infer::MatchExpressionArm(_, _) => {
|
||||
format!("match arms have compatible types")
|
||||
}
|
||||
infer::IfExpression(_) => {
|
||||
|
|
|
@ -116,8 +116,8 @@ pub enum TypeOrigin {
|
|||
// Relating trait refs when resolving vtables
|
||||
RelateSelfType(Span),
|
||||
|
||||
// Computing common supertype in a match expression
|
||||
MatchExpression(Span),
|
||||
// Computing common supertype in the arms of a match expression
|
||||
MatchExpressionArm(Span, Span),
|
||||
|
||||
// Computing common supertype in an if expression
|
||||
IfExpression(Span),
|
||||
|
@ -831,7 +831,7 @@ impl TypeOrigin {
|
|||
Misc(span) => span,
|
||||
RelateTraitRefs(span) => span,
|
||||
RelateSelfType(span) => span,
|
||||
MatchExpression(span) => span,
|
||||
MatchExpressionArm(match_span, _) => match_span,
|
||||
IfExpression(span) => span,
|
||||
}
|
||||
}
|
||||
|
@ -853,8 +853,8 @@ impl Repr for TypeOrigin {
|
|||
RelateSelfType(a) => {
|
||||
format!("RelateSelfType({})", a.repr(tcx))
|
||||
}
|
||||
MatchExpression(a) => {
|
||||
format!("MatchExpression({})", a.repr(tcx))
|
||||
MatchExpressionArm(a, b) => {
|
||||
format!("MatchExpressionArm({}, {})", a.repr(tcx), b.repr(tcx))
|
||||
}
|
||||
IfExpression(a) => {
|
||||
format!("IfExpression({})", a.repr(tcx))
|
||||
|
|
19
src/test/compile-fail/issue-11319.rs
Normal file
19
src/test/compile-fail/issue-11319.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn main() {
|
||||
match Some(10) {
|
||||
//~^ ERROR match arms have incompatible types: expected `bool` but found `()`
|
||||
Some(5) => false,
|
||||
Some(2) => true,
|
||||
None => (), //~ NOTE match arm with an incompatible type
|
||||
_ => true
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue