Skip to content

Commit 5eebb92

Browse files
author
Roy Brunton
committed
Update error message for E0166
1 parent 40f3ee2 commit 5eebb92

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/librustc_typeck/check/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3392,8 +3392,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
33923392
if let Some(ref e) = *expr_opt {
33933393
self.check_expr(&e);
33943394
}
3395-
span_err!(tcx.sess, expr.span, E0166,
3396-
"`return` in a function declared as diverging");
3395+
struct_span_err!(tcx.sess, expr.span, E0166,
3396+
"`return` in a function declared as diverging")
3397+
.span_label(expr.span, &format!("diverging function cannot return"))
3398+
.emit();
33973399
}
33983400
}
33993401
self.write_ty(id, self.next_diverging_ty_var());

src/test/compile-fail/E0166.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
fn foo() -> ! { return; } //~ ERROR E0166
11+
fn foo() -> ! { return; }
12+
//~^ ERROR E0166
13+
//~| NOTE diverging function cannot return
1214

1315
fn main() {
1416
}

src/test/compile-fail/bad-bang-ann-3.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
// Tests that a function with a ! annotation always actually fails
1212

1313
fn bad_bang(i: usize) -> ! {
14-
return 7; //~ ERROR `return` in a function declared as diverging [E0166]
14+
return 7;
15+
//~^ ERROR `return` in a function declared as diverging [E0166]
16+
//~| NOTE diverging function cannot return
1517
}
1618

1719
fn main() { bad_bang(5); }

0 commit comments

Comments
 (0)