-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Add method find_ancestor_not_from_macro
and find_ancestor_not_from_extern_macro
to supersede 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
Conversation
|
There was a problem hiding this 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.
@rustbot author (re. discussion) |
Reminder, once the PR becomes ready for a review, use |
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. |
a2a1033
to
2f977ce
Compare
find_oldest_ancestor_in_same_ctxt
find_ancestor_not_from_macro
and find_ancestor_not_from_extern_macro
to fix find_oldest_ancestor_in_same_ctxt
I found that 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 |
This comment has been minimized.
This comment has been minimized.
2f977ce
to
66d2d16
Compare
There was a problem hiding this 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.
I don't know how to add the right test cases, but I can find the test case corresponding to the diagnostic I modified in this PR, which should be very helpful to understand its behavior. I'm going to insert the debug macro in the method of concern, and then print the debug message via what compile-flag? Do you have a better idea? |
For rust/tests/ui/borrowck/span-semicolon-issue-139049.rs Lines 11 to 17 in d242a8b
rust/tests/ui/borrowck/span-semicolon-issue-139049.stderr Lines 18 to 21 in d242a8b
For rust/tests/ui/typeck/issue-110017-format-into-help-deletes-macro.rs Lines 32 to 39 in d242a8b
For the rust/compiler/rustc_span/src/lib.rs Lines 795 to 803 in d242a8b
For both examples, it worked successfully by mistake.
This problem was discovered when I was solving #144266. Because it had multiple layers of macro calls, so the returned span of @rustbot ready |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I think there might still be cases where these are insufficient, but at least find_oldest_ancestor_in_same_ctxt
seems definitely wrong.
Thanks |
…ieyouxu Add method `find_ancestor_not_from_macro` and `find_ancestor_not_from_extern_macro` to supersede `find_oldest_ancestor_in_same_ctxt` 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`
Rollup of 11 pull requests Successful merges: - #143289 (Remove `[T]::array_chunks(_mut)`) - #143883 (Add `--link-targets-dir` argument to linkchecker) - #144034 (tests: Test line number in debuginfo for diverging function calls) - #144236 (Add `core::mem::DropGuard`) - #144268 (Add method `find_ancestor_not_from_macro` and `find_ancestor_not_from_extern_macro` to supersede `find_oldest_ancestor_in_same_ctxt`) - #144303 (Consolidate staging for `rustc_private` tools) - #144539 (constify with_exposed_provenance) - #144569 (rustc-dev-guide subtree update) - #144573 (Raw Pointers are Constant PatKinds too) - #144578 (Ensure correct aligement of rustc_hir::Lifetime on platforms with lower default alignments.) - #144582 (fix `Atomic*::as_ptr` wording) r? `@ghost` `@rustbot` modify labels: rollup
…ieyouxu Add method `find_ancestor_not_from_macro` and `find_ancestor_not_from_extern_macro` to supersede `find_oldest_ancestor_in_same_ctxt` 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``
…ieyouxu Add method `find_ancestor_not_from_macro` and `find_ancestor_not_from_extern_macro` to supersede `find_oldest_ancestor_in_same_ctxt` 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```
This seems to have failed in rollup: #144619 (comment) @bors r- |
This comment has been minimized.
This comment has been minimized.
i should rebase the branch |
Signed-off-by: xizheyin <[email protected]>
66d2d16
to
81176b1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
waiting for CI green
@@ -1302,7 +1302,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||
None => ".clone()".to_string(), | |||
}; | |||
|
|||
let span = expr.span.find_oldest_ancestor_in_same_ctxt().shrink_to_hi(); | |||
let span = expr.span.find_ancestor_not_from_macro().unwrap_or(expr.span).shrink_to_hi(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rebased.
ready:> |
@bors r+ |
Rollup of 6 pull requests Successful merges: - #144042 (Verify llvm-needs-components are not empty and match the --target value) - #144268 (Add method `find_ancestor_not_from_macro` and `find_ancestor_not_from_extern_macro` to supersede `find_oldest_ancestor_in_same_ctxt`) - #144411 (Remove `hello_world` directory) - #144662 (compiletest: Move directive names back into a separate file) - #144666 (Make sure to account for the right item universal regions in borrowck) - #144668 ([test][run-make] add needs-llvm-components) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #144268 - xizheyin:find-oldest-ancestor, r=jieyouxu Add method `find_ancestor_not_from_macro` and `find_ancestor_not_from_extern_macro` to supersede `find_oldest_ancestor_in_same_ctxt` 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`
Rollup of 6 pull requests Successful merges: - rust-lang/rust#144042 (Verify llvm-needs-components are not empty and match the --target value) - rust-lang/rust#144268 (Add method `find_ancestor_not_from_macro` and `find_ancestor_not_from_extern_macro` to supersede `find_oldest_ancestor_in_same_ctxt`) - rust-lang/rust#144411 (Remove `hello_world` directory) - rust-lang/rust#144662 (compiletest: Move directive names back into a separate file) - rust-lang/rust#144666 (Make sure to account for the right item universal regions in borrowck) - rust-lang/rust#144668 ([test][run-make] add needs-llvm-components) r? `@ghost` `@rustbot` modify labels: rollup
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