Skip to content

Commit 73f0893

Browse files
committed
---
yaml --- r: 116406 b: refs/heads/snap-stage3 c: 4e0b936 h: refs/heads/master v: v3
1 parent f9c4ce5 commit 73f0893

File tree

5 files changed

+34
-9
lines changed

5 files changed

+34
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: bee4e6adac17f87b1cdc26ab69f8c0f5d82575a3
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: d58f27a82f34bfbfec1fc2dfdfcbed26e4f09f58
4+
refs/heads/snap-stage3: 4e0b936900275bcee7ba61894857030c39faec7d
55
refs/heads/try: 009d898a9422ac04c1aa60c0e9aff3abc5fa4672
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/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);

branches/snap-stage3/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(_) => {

branches/snap-stage3/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))
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)