Skip to content
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

fix: Properly resolve prelude paths inside modules inside blocks #18422

Merged
merged 1 commit into from
Oct 28, 2024

Conversation

ChayimFriedman2
Copy link
Contributor

I.e. the following situation:

fn foo() {
    mod bar {
        fn qux() {
            // Prelude path here (e.g. macro use prelude or extern prelude).
        }
    }
}

Those were previously unresolved, because, in order to support self and super properly, since #15148 we do not ascend block paths when there is a module in between, but only crate def maps register preludes, not block def maps, and we can't change this because block def map prelude can always be overridden by another block. E.g.

fn foo() {
    struct WithTheSameNameAsPreludeItem;
    {
        WithTheSameNameAsPreludeItem
    }
}

Here WithTheSameNameAsPreludeItem refer to the item from the top block, but if we would register prelude items in each block the child block would overwrite it incorrectly.

Fixes #18411.

I don't like the approach I took with the code, but I thought many times and couldn't find something better. I extracted a lot into functions. Still, name resolution is a meh (because it's a meh in Rust, not because of our implementation).

I.e. the following situation:
```
fn foo() {
    mod bar {
        fn qux() {
            // Prelude path here (e.g. macro use prelude or extern prelude).
        }
    }
}
```
Those were previously unresolved, because, in order to support `self` and `super` properly, since rust-lang#15148 we do not ascend block paths when there is a module in between, but only crate def maps register preludes, not block def maps, and we can't change this because block def map prelude can always be overridden by another block. E.g.
```
fn foo() {
    struct WithTheSameNameAsPreludeItem;
    {
        WithTheSameNameAsPreludeItem
    }
}
```
Here `WithTheSameNameAsPreludeItem` refer to the item from the top block, but if we would register prelude items in each block the child block would overwrite it incorrectly.
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 27, 2024
@Veykril Veykril added this pull request to the merge queue Oct 28, 2024
Merged via the queue into rust-lang:master with commit 343abd9 Oct 28, 2024
9 checks passed
@ChayimFriedman2 ChayimFriedman2 deleted the cursed-name-res branch October 28, 2024 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

#[test_log_macros::test] reports unresolved macro panic!()
3 participants