-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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
base: master
Are you sure you want to change the base?
Resolve the prelude import in build_reduced_graph
#145322
Conversation
@@ -495,7 +495,22 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> { | |||
} | |||
// We don't add prelude imports to the globs since they only affect lexical scopes, | |||
// which are not relevant to import resolution. | |||
ImportKind::Glob { is_prelude: true, .. } => {} | |||
ImportKind::Glob { is_prelude: true, .. } => { |
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.
Could you avoid calling add_import
for prelude imports entirely?
And remove the is_prelude
field from ImportKind::Glob
.
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.
I don't think its avoidable, maybe_resolve_path
takes an ignore_import
, which is the glob_import itself.
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.
ignore_import
can be None
here, it doesn't make sense during the prelude import resolution.
None, | ||
&import.parent_scope, | ||
Some(import), | ||
); |
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.
Could you immediately report an error if maybe_resolve_path
returns anything other than PathResult::Module(ModuleOrUniformRoot::Module(..))
?
Just some error, having a good error here is not important since it's an implementation detail.
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.
Not possible I think, in library/core/src/lib.rs
there is:
#[prelude_import]
#[allow(unused)]
use prelude::rust_2024::*;
Which failed and thus throws the error.
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.
The import needs to be put after mod prelude;
.
It's an internal detail so we can do that.
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.
That was it, thanks!
) = path_res | ||
{ | ||
import.imported_module.set(Some(module_or_uniform_root)); | ||
self.r.prelude = Some(module); |
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.
Could you avoid calling maybe_resolve_path
and setting the prelude if it is already set?
Can also report some error in that case.
Could you also add this case to tests? //@ check-pass
#![feature(custom_inner_attributes)]
#![rustfmt::skip]
fn main() {
let _ = todo!();
} |
I am currently unable to implement any of your suggestions; it is the prelude import that can not be resolved during |
@Voultapher |
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:
I also can't avoid to only resolve the prelude path when the prelude is not set. Errors like these get emitted:
@rustbot ready |
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