Skip to content

Resolve the prelude import in build_reduced_graph #145322

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 6 commits into
base: master
Choose a base branch
from

Conversation

LorrensP-2158466
Copy link
Contributor

@LorrensP-2158466 LorrensP-2158466 commented Aug 12, 2025

This pr tries to resolve the prelude import at the build_reduced_graph stage.
Part of batched import resolution in #145108 (cherry picked commit) and maybe needed for #139493.

r? petrochenkov

@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 12, 2025
@petrochenkov
Copy link
Contributor

Could you also add this case to tests?

//@ check-pass

#![feature(custom_inner_attributes)]

#![rustfmt::skip]

fn main() {
    let _ = todo!();
}

@petrochenkov petrochenkov 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 Aug 12, 2025
@LorrensP-2158466
Copy link
Contributor Author

LorrensP-2158466 commented Aug 12, 2025

I am currently unable to implement any of your suggestions; it is the prelude import that can not be resolved during build_reduced_graph. Which makes me think that this change doesn't actually do anything useful? At least the prelude import in stdlib keeps failing with every change.

@petrochenkov
Copy link
Contributor

@Voultapher
This change should fix your issues with #139493 and custom inner attributes.
Could you check it when it's ready?

@LorrensP-2158466
Copy link
Contributor Author

Suggestions worked, however, we can't emit an error when the prelude is already set, I just used a panic for ease of use, and it was triggered when compiling stdlib:

prelude already set: [Segment { ident: prelude#0, id: Some(NodeId(479)), has_generic_args: false, has_lifetime_args: false, args_span: no-location (#0) }, Segment { ident: rust_2021#0, id: Some(NodeId(480)), has_generic_args: false, has_lifetime_args: false, args_span: no-location (#0) }]

I also can't avoid to only resolve the prelude path when the prelude is not set. Errors like these get emitted:

error[E0433]: failed to resolve: use of undeclared type `String`
   --> library/std/src/panicking.rs:642:29
    |
642 |                 let mut s = String::new();
    |                             ^^^^^^ use of undeclared type `String`
    |
help: consider importing one of these structs
    |
 12 + use crate::prelude::rust_future::String;
    |
 12 + use alloc::string::String;
    |

error[E0433]: failed to resolve: use of undeclared type `Box`
   --> library/std/src/panicking.rs:656:13
    |
656 |             Box::into_raw(Box::new(contents))
    |             ^^^ use of undeclared type `Box`
    |
help: consider importing one of these structs
    |
 12 + use crate::prelude::rust_future::Box;
    |
 12 + use alloc::boxed::Box;

@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 Aug 13, 2025
@petrochenkov
Copy link
Contributor

Okay, I see, in std and in some tests we first apply the prelude import injected implicitly, and then the prelude import written explicitly.
Let's keep it as is then.

@petrochenkov petrochenkov 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 Aug 13, 2025
@rust-log-analyzer

This comment has been minimized.

@Voultapher
Copy link
Contributor

@petrochenkov I've tested #139493 with this PR and I can confirm it does resolve the problem in question, but I'm also seeing the same UI test failures reported by the CI here.

@Voultapher
Copy link
Contributor

Small addendum, I had hopped that fixing the custom_inner_attributes issue would also resolve the change in errors produced in the where-allowed test since it uses custom_inner_attributes and a top level non prelude macro, but alas the change in errors produced still occurs.

@LorrensP-2158466
Copy link
Contributor Author

Which tests are you talking about?

@LorrensP-2158466
Copy link
Contributor Author

I also tried to make CI green, those changes are in the second commit.

@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 Aug 14, 2025
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. 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.

5 participants