diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index de68cc707ad7a..142f8f5c719c2 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -1431,6 +1431,23 @@ fn make_child<'elve>(x: &mut &'elve isize, y: &mut &'elve isize) { ``` "##, +E0317: r##" +This error occurs when an `if` expression without an `else` block is used in a +context where a type other than `()` is expected, for example a `let` +expression: + +```compile_fail,E0317 +fn main() { + let x = 5; + let a = if x == 5 { 1 }; +} +``` + +An `if` expression without an `else` block has the type `()`, so this is a type +error. To resolve it, add an `else` block having the same type as the `if` +block. +"##, + E0398: r##" In Rust 1.3, the default object lifetime bounds are expected to change, as described in RFC #1156 [1]. You are getting a warning because the compiler diff --git a/src/librustc/infer/error_reporting.rs b/src/librustc/infer/error_reporting.rs index 3f216d6916851..373ea4aac57b0 100644 --- a/src/librustc/infer/error_reporting.rs +++ b/src/librustc/infer/error_reporting.rs @@ -577,11 +577,16 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { terr: &TypeError<'tcx>) -> DiagnosticBuilder<'tcx> { - // FIXME: do we want to use a different error code for each origin? - let mut diag = struct_span_err!( - self.tcx.sess, trace.origin.span(), E0308, - "{}", trace.origin.as_failure_str() - ); + let span = trace.origin.span(); + let failure_str = trace.origin.as_failure_str(); + let mut diag = match trace.origin { + TypeOrigin::IfExpressionWithNoElse(_) => { + struct_span_err!(self.tcx.sess, span, E0317, "{}", failure_str) + }, + _ => { + struct_span_err!(self.tcx.sess, span, E0308, "{}", failure_str) + }, + }; self.note_type_err(&mut diag, trace.origin, None, Some(trace.values), terr); diag } diff --git a/src/test/compile-fail/if-without-else-result.rs b/src/test/compile-fail/if-without-else-result.rs index e8aa1f70ea1dc..95bcce5a8474a 100644 --- a/src/test/compile-fail/if-without-else-result.rs +++ b/src/test/compile-fail/if-without-else-result.rs @@ -10,7 +10,7 @@ fn main() { let a = if true { true }; - //~^ ERROR if may be missing an else clause + //~^ ERROR if may be missing an else clause [E0317] //~| expected type `()` //~| found type `bool` //~| expected (), found bool