Skip to content

Commit b2997d5

Browse files
committed
fixed diagnostic
1 parent ec7c026 commit b2997d5

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-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+
ty.fn_sig(self.tcx).skip_binder(),
139+
);
136140
}
137141

138142
// FIXME(explicit_tail_calls): this currently fails for cases where opaques are used.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//! Regression test for: https://github.com/rust-lang/rust/issues/144957
2+
//!
3+
//! This test ensures that lifetime information is included in diagnostics.
4+
//!
5+
//! Specifically, it checks that the `become` call produces an error with lifetimes shown
6+
//! in both caller and callee signatures.
7+
//!
8+
//! If the test fails:
9+
//! - Lifetimes may be missing (fix the diagnostic), or
10+
//! - The message format changed (update the test).
11+
12+
#![feature(explicit_tail_calls)]
13+
#![allow(incomplete_features)]
14+
15+
fn foo<'a>(_: fn(&'a ())) {
16+
become bar(dummy);
17+
//~^ ERROR mismatched signatures
18+
//~| NOTE `become` requires caller and callee to have matching signatures
19+
//~| NOTE caller signature: `fn(fn(&'a ()))`
20+
//~| NOTE callee signature: `fn(for<'a> fn(&'a ()))`
21+
}
22+
23+
fn bar(_: fn(&())) {}
24+
25+
fn dummy(_: &()) {}
26+
27+
fn foo_(_: fn(&())) {
28+
become bar1(dummy2);
29+
//~^ ERROR mismatched signatures
30+
//~| NOTE `become` requires caller and callee to have matching signatures
31+
//~| NOTE caller signature: `fn(for<'a> fn(&'a ()))`
32+
//~| NOTE callee signature: `fn(fn(&'a ()))`
33+
}
34+
35+
fn bar1<'a>(_: fn(&'a ())) {}
36+
37+
fn dummy2(_: &()) {}
38+
39+
fn main() {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error: mismatched signatures
2+
--> $DIR/caller-lifetime-presence.rs:16: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: mismatched signatures
12+
--> $DIR/caller-lifetime-presence.rs:28:5
13+
|
14+
LL | become bar1(dummy2);
15+
| ^^^^^^^^^^^^^^^^^^^
16+
|
17+
= note: `become` requires caller and callee to have matching signatures
18+
= note: caller signature: `fn(for<'a> fn(&'a ()))`
19+
= note: callee signature: `fn(fn(&'a ()))`
20+
21+
error: aborting due to 2 previous errors
22+

0 commit comments

Comments
 (0)