Skip to content

Commit e42f3ae

Browse files
Defer tail call ret ty equality to check_tail_calls
1 parent e1b9081 commit e42f3ae

File tree

4 files changed

+30
-17
lines changed

4 files changed

+30
-17
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1931,7 +1931,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
19311931
self.tcx(),
19321932
self.infcx.typing_env(self.infcx.param_env),
19331933
) {
1934-
span_mirbug!(self, term, "call to converging function {:?} w/o dest", sig);
1934+
span_mirbug!(self, term, "call to diverging function {:?} w/o dest", sig);
19351935
}
19361936
}
19371937
}

compiler/rustc_mir_build/src/check_tail_calls.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl<'tcx> TailCallCkVisitor<'_, 'tcx> {
6060
let BodyTy::Fn(caller_sig) = self.thir.body_type else {
6161
span_bug!(
6262
call.span,
63-
"`become` outside of functions should have been disallowed by hit_typeck"
63+
"`become` outside of functions should have been disallowed by hir_typeck"
6464
)
6565
};
6666

@@ -118,21 +118,7 @@ impl<'tcx> TailCallCkVisitor<'_, 'tcx> {
118118
}
119119

120120
if caller_sig.inputs_and_output != callee_sig.inputs_and_output {
121-
if caller_sig.inputs() != callee_sig.inputs() {
122-
self.report_arguments_mismatch(expr.span, caller_sig, callee_sig);
123-
}
124-
125-
// FIXME(explicit_tail_calls): this currently fails for cases where opaques are used.
126-
// e.g.
127-
// ```
128-
// fn a() -> impl Sized { become b() } // ICE
129-
// fn b() -> u8 { 0 }
130-
// ```
131-
// we should think what is the expected behavior here.
132-
// (we should probably just accept this by revealing opaques?)
133-
if caller_sig.output() != callee_sig.output() {
134-
span_bug!(expr.span, "hir typeck should have checked the return type already");
135-
}
121+
self.report_arguments_mismatch(expr.span, caller_sig, callee_sig);
136122
}
137123

138124
{
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![feature(explicit_tail_calls)]
2+
#![allow(incomplete_features)]
3+
4+
fn foo() -> for<'a> fn(&'a i32) {
5+
become bar();
6+
//~^ ERROR mismatched signatures
7+
}
8+
9+
fn bar() -> fn(&'static i32) {
10+
dummy
11+
}
12+
13+
fn dummy(_: &i32) {}
14+
15+
fn main() {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error: mismatched signatures
2+
--> $DIR/ret-ty-hr-mismatch.rs:5:5
3+
|
4+
LL | become bar();
5+
| ^^^^^^^^^^^^
6+
|
7+
= note: `become` requires caller and callee to have matching signatures
8+
= note: caller signature: `fn() -> for<'a> fn(&'a i32)`
9+
= note: callee signature: `fn() -> fn(&i32)`
10+
11+
error: aborting due to 1 previous error
12+

0 commit comments

Comments
 (0)