Skip to content

Commit 5527c5d

Browse files
committed
auto merge of #14561 : jakub-/rust/issue-11319, r=alexcrichton
Fixes #11319
2 parents ee97698 + b64046a commit 5527c5d

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

src/librustc/middle/typeck/check/_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub fn check_match(fcx: &FnCtxt,
8787
result_ty =
8888
infer::common_supertype(
8989
fcx.infcx(),
90-
infer::MatchExpression(expr.span),
90+
infer::MatchExpressionArm(expr.span, arm.body.span),
9191
true, // result_ty is "expected" here
9292
result_ty,
9393
bty);

src/librustc/middle/typeck/infer/error_reporting.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ impl<'a> ErrorReporting for InferCtxt<'a> {
346346
infer::ExprAssignable(_) => "mismatched types",
347347
infer::RelateTraitRefs(_) => "mismatched traits",
348348
infer::RelateSelfType(_) => "mismatched types",
349-
infer::MatchExpression(_) => "match arms have incompatible types",
349+
infer::MatchExpressionArm(_, _) => "match arms have incompatible types",
350350
infer::IfExpression(_) => "if and else have incompatible types",
351351
};
352352

@@ -356,6 +356,12 @@ impl<'a> ErrorReporting for InferCtxt<'a> {
356356
message_root_str,
357357
expected_found_str,
358358
ty::type_err_to_str(self.tcx, terr)).as_slice());
359+
360+
match trace.origin {
361+
infer::MatchExpressionArm(_, arm_span) =>
362+
self.tcx.sess.span_note(arm_span, "match arm with an incompatible type"),
363+
_ => ()
364+
}
359365
}
360366

361367
fn report_and_explain_type_error(&self,
@@ -1281,7 +1287,7 @@ impl<'a> ErrorReportingHelpers for InferCtxt<'a> {
12811287
infer::RelateSelfType(_) => {
12821288
format!("type matches impl")
12831289
}
1284-
infer::MatchExpression(_) => {
1290+
infer::MatchExpressionArm(_, _) => {
12851291
format!("match arms have compatible types")
12861292
}
12871293
infer::IfExpression(_) => {

src/librustc/middle/typeck/infer/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ pub enum TypeOrigin {
116116
// Relating trait refs when resolving vtables
117117
RelateSelfType(Span),
118118

119-
// Computing common supertype in a match expression
120-
MatchExpression(Span),
119+
// Computing common supertype in the arms of a match expression
120+
MatchExpressionArm(Span, Span),
121121

122122
// Computing common supertype in an if expression
123123
IfExpression(Span),
@@ -831,7 +831,7 @@ impl TypeOrigin {
831831
Misc(span) => span,
832832
RelateTraitRefs(span) => span,
833833
RelateSelfType(span) => span,
834-
MatchExpression(span) => span,
834+
MatchExpressionArm(match_span, _) => match_span,
835835
IfExpression(span) => span,
836836
}
837837
}
@@ -853,8 +853,8 @@ impl Repr for TypeOrigin {
853853
RelateSelfType(a) => {
854854
format!("RelateSelfType({})", a.repr(tcx))
855855
}
856-
MatchExpression(a) => {
857-
format!("MatchExpression({})", a.repr(tcx))
856+
MatchExpressionArm(a, b) => {
857+
format!("MatchExpressionArm({}, {})", a.repr(tcx), b.repr(tcx))
858858
}
859859
IfExpression(a) => {
860860
format!("IfExpression({})", a.repr(tcx))

src/test/compile-fail/issue-11319.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
match Some(10) {
13+
//~^ ERROR match arms have incompatible types: expected `bool` but found `()`
14+
Some(5) => false,
15+
Some(2) => true,
16+
None => (), //~ NOTE match arm with an incompatible type
17+
_ => true
18+
}
19+
}

0 commit comments

Comments
 (0)