Skip to content

Add method find_ancestor_not_from_macro and find_ancestor_not_from_extern_macro to fix find_oldest_ancestor_in_same_ctxt #144268

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

xizheyin
Copy link
Contributor

As I was using it, I realized that the function is supposed to walk up to expand the chain? This seems to be the opposite of what I understood.

r? @jieyouxu

@rustbot
Copy link
Collaborator

rustbot commented Jul 21, 2025

jieyouxu is currently at their maximum review capacity.
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 Jul 21, 2025
Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

Hm, I'm not actually 100% this helper is doing what I originally wanted it to do... This will try to keep traversing up the macro invocation chain that produced the provided final span at hand to find the oldest ancestor which has... the same syntax context as the provided final span (???) I suppose this might work if the passed in span you know is "local" and the user actually has control over 🤔

I feel like this is wrong, or least quite confusing... I wonder if you could go the other direction and use instead https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.Span.html#method.find_ancestor_in_same_ctxt or https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.Span.html#method.find_ancestor_inside_same_ctxt and get rid of this helper.

@jieyouxu
Copy link
Member

@rustbot author (re. discussion)

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 22, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 22, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 22, 2025
@xizheyin
Copy link
Contributor Author

I found some problems with the comments of these APIs, I subconsciously thought that finding an ancestor would be traversing the macro expansion chain from bottom to top, but they all use “walk down”. This seems to create ambiguity. I'll look into these APIs later when I have time and find the best way to do it.

@xizheyin xizheyin force-pushed the find-oldest-ancestor branch from a2a1033 to 2f977ce Compare July 22, 2025 16:23
@xizheyin xizheyin changed the title Fix comments of find_oldest_ancestor_in_same_ctxt Add method find_ancestor_not_from_macro and find_ancestor_not_from_extern_macro to fix find_oldest_ancestor_in_same_ctxt Jul 22, 2025
@xizheyin
Copy link
Contributor Author

I found that find_oldest_ancestor_in_same_ctxt does have a logical problem, but by some mischance it works successfully in some places.
The places where it is needed are basically related to macros, and my understanding is that the proper ancestor should be found without any other span help, e.g. outer in span.find_ancestor_inside(outer).

I added two methods that allow for more fine-grained control. This change should help fix all the diagnostics shown in the macros in the standard library(#142403).

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 22, 2025
@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

Hm, is it possible to add specific test cases demonstrating the behaviors of

  • find_ancestor_not_from_macro
  • find_ancestor_not_from_extern_macro
  • find_oldest_ancestor_in_same_ctxt

Otherwise, we'd have no idea what effect changing the impls of these helpers might be.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

4 participants