Skip to content

Commit 9a9f300

Browse files
committed
fixed diagnostic
1 parent ec7c026 commit 9a9f300

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

compiler/rustc_mir_build/src/check_tail_calls.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,11 @@ impl<'tcx> TailCallCkVisitor<'_, 'tcx> {
132132

133133
if caller_sig.inputs_and_output != callee_sig.inputs_and_output {
134134
if caller_sig.inputs() != callee_sig.inputs() {
135-
self.report_arguments_mismatch(expr.span, caller_sig, callee_sig);
135+
self.report_arguments_mismatch(
136+
expr.span,
137+
self.caller_ty.fn_sig(self.tcx).skip_binder(),
138+
callee_sig,
139+
);
136140
}
137141

138142
// FIXME(explicit_tail_calls): this currently fails for cases where opaques are used.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//! Regression test for: https://github.com/rust-lang/rust/issues/144957
2+
//!
3+
//! Once upon a time, the compiler decided lifetimes weren’t important enough to show in diagnostics
4+
//! That decision did not go well. This test ensures we don’t repeat that mistake.
5+
//!
6+
//! Specifically: we’re checking that the `become` call produces an error
7+
//! **with** lifetimes preserved
8+
//! in both caller and callee signatures. Otherwise, good luck figuring out what went wrong.
9+
//!
10+
//! If this test fails:
11+
//! - Either lifetimes are being omitted from the diagnostic again (bad, fix it),
12+
//! - Or the message format changed (okay, update the test).
13+
14+
#![feature(explicit_tail_calls)]
15+
#![allow(incomplete_features)]
16+
17+
fn foo<'a>(_: fn(&'a ())) {
18+
become bar(dummy);
19+
//~^ ERROR mismatched signatures
20+
//~| NOTE `become` requires caller and callee to have matching signatures
21+
//~| NOTE caller signature: `fn(fn(&'a ()))`
22+
//~| NOTE callee signature: `fn(for<'a> fn(&'a ()))`
23+
}
24+
25+
fn bar(_: fn(&())) {}
26+
27+
fn dummy(_: &()) {}
28+
29+
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/caller-lifetime-presence.rs:18:5
3+
|
4+
LL | become bar(dummy);
5+
| ^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `become` requires caller and callee to have matching signatures
8+
= note: caller signature: `fn(fn(&'a ()))`
9+
= note: callee signature: `fn(for<'a> fn(&'a ()))`
10+
11+
error: aborting due to 1 previous error
12+

0 commit comments

Comments
 (0)