Skip to content

Commit b71fc0c

Browse files
address review
1 parent 564c205 commit b71fc0c

File tree

2 files changed

+36
-35
lines changed

2 files changed

+36
-35
lines changed

compiler/rustc_resolve/src/imports.rs

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use rustc_span::{Ident, Span, Symbol, kw, sym};
2525
use smallvec::SmallVec;
2626
use tracing::debug;
2727

28-
use crate::Determinacy::{self};
2928
use crate::Namespace::*;
3029
use crate::diagnostics::{DiagMode, Suggestion, import_candidates};
3130
use crate::errors::{
@@ -34,7 +33,7 @@ use crate::errors::{
3433
ConsiderAddingMacroExport, ConsiderMarkingAsPub,
3534
};
3635
use crate::{
37-
AmbiguityError, AmbiguityKind, BindingKey, Finalize, ImportSuggestion, Module,
36+
AmbiguityError, AmbiguityKind, BindingKey, Determinacy, Finalize, ImportSuggestion, Module,
3837
ModuleOrUniformRoot, NameBinding, NameBindingData, NameBindingKind, ParentScope, PathResult,
3938
PerNS, ResolutionError, Resolver, ScopeSet, Segment, Used, module_to_string, names_to_string,
4039
};
@@ -568,7 +567,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
568567
if let ImportKind::Single { source, ref bindings, .. } = import.kind
569568
&& source.name == kw::SelfLower
570569
// Silence `unresolved import` error if E0429 is already emitted
571-
// `indings` here is "target_bindings", if it is "Err(Determined)" then `source_bindings` as well.
572570
&& let Progress::Ready(None) = bindings.value_ns.get()
573571
{
574572
continue;
@@ -832,29 +830,22 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
832830
let mut indeterminate_count = 0;
833831
self.per_ns(|this, ns| {
834832
if !type_ns_only || ns == TypeNS {
835-
if let Progress::Pending = bindings[ns].get() {
836-
let binding_result = this.maybe_resolve_ident_in_module(
837-
module,
838-
source,
839-
ns,
840-
&import.parent_scope,
841-
Some(import),
842-
);
843-
let binding = match binding_result {
844-
// We need the `target`, `source` can be extracted.
845-
Ok(binding) => Poll::Ready(Some(this.import(binding, import))),
846-
Err(Determinacy::Determined) => Poll::Ready(None),
847-
Err(Determinacy::Undetermined) => Poll::Pending,
848-
};
849-
bindings[ns].set(binding);
850-
} else {
833+
let Progress::Pending = bindings[ns].get() else {
851834
return;
852835
};
853-
836+
let binding_result = this.maybe_resolve_ident_in_module(
837+
module,
838+
source,
839+
ns,
840+
&import.parent_scope,
841+
Some(import),
842+
);
854843
let parent = import.parent_scope.module;
855-
match bindings[ns].get() {
856-
Progress::Ready(Some(binding)) => {
857-
if binding.is_assoc_item()
844+
let binding = match binding_result {
845+
Ok(binding) => {
846+
// We need the `target`, `source` can be extracted.
847+
let imported_binding = this.import(binding, import);
848+
if imported_binding.is_assoc_item()
858849
&& !this.tcx.features().import_trait_associated_functions()
859850
{
860851
feature_err(
@@ -865,19 +856,25 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
865856
)
866857
.emit();
867858
}
868-
this.define(parent, target, ns, binding);
859+
this.define(parent, target, ns, imported_binding);
860+
Poll::Ready(Some(imported_binding))
869861
}
870-
Progress::Ready(None) => {
862+
Err(Determinacy::Determined) => {
871863
// Don't update the resolution for underscores, because it was never added.
872864
if target.name != kw::Underscore {
873865
let key = BindingKey::new(target, ns);
874866
this.update_resolution(parent, key, false, |_, resolution| {
875867
resolution.single_imports.swap_remove(&import);
876868
});
877869
}
870+
Poll::Ready(None)
878871
}
879-
Progress::Pending => indeterminate_count += 1,
880-
}
872+
Err(Determinacy::Undetermined) => {
873+
indeterminate_count += 1;
874+
Poll::Pending
875+
}
876+
};
877+
bindings[ns].set(binding);
881878
}
882879
});
883880

@@ -1101,7 +1098,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
11011098
Ok(binding) => {
11021099
// Consistency checks, analogous to `finalize_macro_resolutions`.
11031100
let initial_res = bindings[ns].get().map(|maybe_binding| {
1104-
maybe_binding.and_then(|binding| binding.maybe_source_binding()).map(
1101+
maybe_binding.map(|binding| binding.import_source()).map(
11051102
|initial_binding| {
11061103
all_ns_err = false;
11071104
if let Progress::Ready(Some(binding)) = bindings[ns].get()
@@ -1272,7 +1269,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
12721269
let mut crate_private_reexport = false;
12731270
self.per_ns(|this, ns| {
12741271
let binding = match bindings[ns].get() {
1275-
Poll::Ready(Some(binding)) => binding.maybe_source_binding(),
1272+
Poll::Ready(Some(binding)) => Some(binding.import_source()),
12761273
_ => None,
12771274
};
12781275
let Some(binding) = binding else {
@@ -1346,7 +1343,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
13461343
let mut full_path = import.module_path.clone();
13471344
full_path.push(Segment::from_ident(ident));
13481345
self.per_ns(|this, ns| {
1349-
if let Progress::Ready(Some(binding)) = bindings[ns].get() {
1346+
let binding = match bindings[ns].get() {
1347+
Poll::Ready(Some(binding)) => Some(binding.import_source()),
1348+
_ => None,
1349+
};
1350+
if let Some(binding) = binding {
13501351
this.lint_if_path_starts_with_module(Some(finalize), &full_path, Some(binding));
13511352
}
13521353
});
@@ -1357,7 +1358,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
13571358
// purposes it's good enough to just favor one over the other.
13581359
self.per_ns(|this, ns| {
13591360
let binding = match bindings[ns].get() {
1360-
Poll::Ready(Some(binding)) => binding.maybe_source_binding(),
1361+
Poll::Ready(Some(binding)) => Some(binding.import_source()),
13611362
_ => None,
13621363
};
13631364
if let Some(binding) = binding {
@@ -1399,7 +1400,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
13991400
let mut redundant_span = PerNS { value_ns: None, type_ns: None, macro_ns: None };
14001401
self.per_ns(|this, ns| {
14011402
let binding = match bindings[ns].get() {
1402-
Poll::Ready(Some(binding)) => binding.maybe_source_binding(),
1403+
Poll::Ready(Some(binding)) => Some(binding.import_source()),
14031404
_ => None,
14041405
};
14051406
if is_redundant && let Some(binding) = binding {

compiler/rustc_resolve/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -891,10 +891,10 @@ impl<'ra> NameBindingData<'ra> {
891891
}
892892
}
893893

894-
fn maybe_source_binding(&self) -> Option<NameBinding<'ra>> {
894+
fn import_source(&self) -> NameBinding<'ra> {
895895
match self.kind {
896-
NameBindingKind::Import { binding, .. } => Some(binding),
897-
_ => None,
896+
NameBindingKind::Import { binding, .. } => binding,
897+
_ => unreachable!(),
898898
}
899899
}
900900

0 commit comments

Comments
 (0)