Skip to content

Commit bb1ff9d

Browse files
authored
Rollup merge of rust-lang#35288 - Roybie:35271-E0166-update-error-format, r=GuillaumeGomez
Update error message for E0166 Fixes rust-lang#35271 as part of rust-lang#35233. r? @jonathandturner
2 parents d9cc84b + 5eebb92 commit bb1ff9d

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
@@ -3415,8 +3415,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
34153415
if let Some(ref e) = *expr_opt {
34163416
self.check_expr(&e);
34173417
}
3418-
span_err!(tcx.sess, expr.span, E0166,
3419-
"`return` in a function declared as diverging");
3418+
struct_span_err!(tcx.sess, expr.span, E0166,
3419+
"`return` in a function declared as diverging")
3420+
.span_label(expr.span, &format!("diverging function cannot return"))
3421+
.emit();
34203422
}
34213423
}
34223424
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)