Skip to content

Commit e2a2a77

Browse files
authored
Rollup merge of rust-lang#145012 - Kivooeo:fun-problem-fun-fix, r=compiler-errors
Tail call diagnostics to include lifetime info Fixes rust-lang#144957 r? ``@WaffleLapkin`` ``@compiler-errors``
2 parents a7f95ad + 51df1da commit e2a2a77

File tree

3 files changed

+93
-1
lines changed

3 files changed

+93
-1
lines changed

compiler/rustc_mir_build/src/check_tail_calls.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use rustc_data_structures::stack::ensure_sufficient_stack;
33
use rustc_errors::Applicability;
44
use rustc_hir::LangItem;
55
use rustc_hir::def::DefKind;
6+
use rustc_hir::def_id::CRATE_DEF_ID;
67
use rustc_middle::span_bug;
78
use rustc_middle::thir::visit::{self, Visitor};
89
use rustc_middle::thir::{BodyTy, Expr, ExprId, ExprKind, Thir};
@@ -136,7 +137,15 @@ impl<'tcx> TailCallCkVisitor<'_, 'tcx> {
136137

137138
if caller_sig.inputs_and_output != callee_sig.inputs_and_output {
138139
if caller_sig.inputs() != callee_sig.inputs() {
139-
self.report_arguments_mismatch(expr.span, caller_sig, callee_sig);
140+
self.report_arguments_mismatch(
141+
expr.span,
142+
self.tcx.liberate_late_bound_regions(
143+
CRATE_DEF_ID.to_def_id(),
144+
self.caller_ty.fn_sig(self.tcx),
145+
),
146+
self.tcx
147+
.liberate_late_bound_regions(CRATE_DEF_ID.to_def_id(), ty.fn_sig(self.tcx)),
148+
);
140149
}
141150

142151
// FIXME(explicit_tail_calls): this currently fails for cases where opaques are used.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 foo__(_: fn(&'static ())) {
40+
become bar(dummy3);
41+
//~^ ERROR mismatched signatures
42+
//~| NOTE `become` requires caller and callee to have matching signatures
43+
//~| NOTE caller signature: `fn(fn(&'static ()))`
44+
//~| NOTE callee signature: `fn(for<'a> fn(&'a ()))`
45+
}
46+
47+
fn bar2(_: fn(&())) {}
48+
49+
fn dummy3(_: &()) {}
50+
51+
fn main() {}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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: mismatched signatures
22+
--> $DIR/caller-lifetime-presence.rs:40:5
23+
|
24+
LL | become bar(dummy3);
25+
| ^^^^^^^^^^^^^^^^^^
26+
|
27+
= note: `become` requires caller and callee to have matching signatures
28+
= note: caller signature: `fn(fn(&'static ()))`
29+
= note: callee signature: `fn(for<'a> fn(&'a ()))`
30+
31+
error: aborting due to 3 previous errors
32+

0 commit comments

Comments
 (0)