Skip to content

Tail call diagnostics to include lifetime info #145012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Kivooeo
Copy link
Contributor

@Kivooeo Kivooeo commented Aug 6, 2025

@rustbot
Copy link
Collaborator

rustbot commented Aug 6, 2025

WaffleLapkin is not on the review rotation at the moment.
They may take a while to respond.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 6, 2025
@Kivooeo Kivooeo changed the title fixed diagnostic Tail call diagnostics to include lifetime info Aug 6, 2025
@Kivooeo Kivooeo force-pushed the fun-problem-fun-fix branch 2 times, most recently from 9260c5d to 9a9f300 Compare August 6, 2025 17:07
@rustbot rustbot added the F-explicit_tail_calls `#![feature(explicit_tail_calls)]` label Aug 6, 2025
Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't fix the issue in the other direction, like:

fn foo(_: fn(&())) {
    become bar(dummy);
}

fn bar<'a>(_: fn(&'a ())) {}

fn dummy(_: &()) {}

self.report_arguments_mismatch(expr.span, caller_sig, callee_sig);
self.report_arguments_mismatch(
expr.span,
self.caller_ty.fn_sig(self.tcx).skip_binder(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.caller_ty.fn_sig(self.tcx).skip_binder(),
self.caller_ty.fn_sig(self.tcx).instantiate_identity(),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not work for me

error[E0599]: no method named `instantiate_identity` found for struct `Binder` in the current scope
   --> compiler/rustc_mir_build/src/check_tail_calls.rs:137:53
    |
137 |                     self.caller_ty.fn_sig(self.tcx).instantiate_identity(),
    |                                                     ^^^^^^^^^^^^^^^^^^^^ method not found in `Binder<TyCtxt<'_>, FnSig<TyCtxt<'_>>>`

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, it's a binder, not an early binder. that should be liberated then probably, use tcx.liberate_late_bound_regions instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love to hear why current approach is not best just to learn things

Also about 'static yes it shows, should I include this in test?

4 |     become bar(dummy);
  |     ^^^^^^^^^^^^^^^^^
  |
  = note: -Ztrack-diagnostics: created at compiler/rustc_mir_build/src/check_tail_calls.rs:368:14
  = note: `become` requires caller and callee to have matching signatures
  = note: caller signature: `fn(for<'a> fn(&'a ()))`
  = note: callee signature: `fn(fn(&'static ()))`

Copy link
Contributor Author

@Kivooeo Kivooeo Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did tcx.liberate_late_bound_regions it works but I did not found a better way to obtain DefId rather than do this

Update TailCallCkVisitor with adding a field that will contain def id

struct TailCallCkVisitor<'a, 'tcx> {
    ... // existed fields
    def: DefId,
}

And create it like this

    let mut visitor = TailCallCkVisitor {
        ... // eixsted fields
        def: def.to_def_id(),
    };

This might be a bad solution to pass DefId like this?

    self.report_arguments_mismatch(
        expr.span,
        self.tcx.liberate_late_bound_regions(self.def, self.caller_ty.fn_sig(self.tcx)),
        self.tcx.liberate_late_bound_regions(self.def, ty.fn_sig(self.tcx)),
    );

@Kivooeo Kivooeo force-pushed the fun-problem-fun-fix branch from 9a9f300 to b2997d5 Compare August 6, 2025 18:08
@Kivooeo
Copy link
Contributor Author

Kivooeo commented Aug 6, 2025

I fixed other direction, and make test description lesser (not want to shrink it to one liner tho)

If we have a better way to do so, I'm open for suggestions because it's literally first time me opening anything related to tail call

@compiler-errors
Copy link
Member

You should probably check if this also mentions regions like 'static since those may show up in the signature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-explicit_tail_calls `#![feature(explicit_tail_calls)]` S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tail call diagnostics omit lifetimes
4 participants