diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 6062bd048b3d2..8817c6f8d1eda 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3392,8 +3392,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { if let Some(ref e) = *expr_opt { self.check_expr(&e); } - span_err!(tcx.sess, expr.span, E0166, - "`return` in a function declared as diverging"); + struct_span_err!(tcx.sess, expr.span, E0166, + "`return` in a function declared as diverging") + .span_label(expr.span, &format!("diverging function cannot return")) + .emit(); } } self.write_ty(id, self.next_diverging_ty_var()); diff --git a/src/test/compile-fail/E0166.rs b/src/test/compile-fail/E0166.rs index 9fa41249aa50b..f8585d71b402a 100644 --- a/src/test/compile-fail/E0166.rs +++ b/src/test/compile-fail/E0166.rs @@ -8,7 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo() -> ! { return; } //~ ERROR E0166 +fn foo() -> ! { return; } + //~^ ERROR E0166 + //~| NOTE diverging function cannot return fn main() { } diff --git a/src/test/compile-fail/bad-bang-ann-3.rs b/src/test/compile-fail/bad-bang-ann-3.rs index de315a41361a7..1a5496f055150 100644 --- a/src/test/compile-fail/bad-bang-ann-3.rs +++ b/src/test/compile-fail/bad-bang-ann-3.rs @@ -11,7 +11,9 @@ // Tests that a function with a ! annotation always actually fails fn bad_bang(i: usize) -> ! { - return 7; //~ ERROR `return` in a function declared as diverging [E0166] + return 7; + //~^ ERROR `return` in a function declared as diverging [E0166] + //~| NOTE diverging function cannot return } fn main() { bad_bang(5); }