Skip to content

Commit 1dec116

Browse files
correct assignment of bindings and remove PerNs::into_iter_(with)
1 parent 36df273 commit 1dec116

File tree

2 files changed

+23
-39
lines changed

2 files changed

+23
-39
lines changed

compiler/rustc_hir/src/def.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -708,24 +708,6 @@ impl<T> PerNS<T> {
708708
pub fn iter(&self) -> IntoIter<&T, 3> {
709709
[&self.value_ns, &self.type_ns, &self.macro_ns].into_iter()
710710
}
711-
712-
pub fn into_iter_with(self) -> IntoIter<(Namespace, T), 3> {
713-
[
714-
(Namespace::TypeNS, self.type_ns),
715-
(Namespace::ValueNS, self.value_ns),
716-
(Namespace::MacroNS, self.macro_ns),
717-
]
718-
.into_iter()
719-
}
720-
721-
pub fn iter_with(&self) -> IntoIter<(Namespace, &T), 3> {
722-
[
723-
(Namespace::TypeNS, &self.type_ns),
724-
(Namespace::ValueNS, &self.value_ns),
725-
(Namespace::MacroNS, &self.macro_ns),
726-
]
727-
.into_iter()
728-
}
729711
}
730712

731713
impl<T> ::std::ops::Index<Namespace> for PerNS<T> {

compiler/rustc_resolve/src/imports.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -82,32 +82,40 @@ impl<'ra> ImportResolutionOutputs<'ra> {
8282
ImportKind::Single { target, bindings, .. },
8383
SideEffectBindings::Single { import_bindings },
8484
) => {
85-
for (ns, pending_binding) in import_bindings.into_iter_with() {
86-
match pending_binding {
85+
r.per_ns(|this, ns| {
86+
match import_bindings[ns] {
8787
PendingBinding::Ready(Some(binding)) => {
8888
if binding.is_assoc_item()
89-
&& !r.tcx.features().import_trait_associated_functions()
89+
&& !this.tcx.features().import_trait_associated_functions()
9090
{
9191
feature_err(
92-
r.tcx.sess,
92+
this.tcx.sess,
9393
sym::import_trait_associated_functions,
9494
import.span,
9595
"`use` associated items of traits is unstable",
9696
)
9797
.emit();
9898
}
99-
r.define_binding_local(parent, *target, ns, binding);
99+
this.define_binding_local(parent, *target, ns, binding);
100100
}
101101
PendingBinding::Ready(None) => {
102-
let key = BindingKey::new(*target, ns);
103-
r.update_local_resolution(parent, key, false, |_, resolution| {
104-
resolution.single_imports.swap_remove(&import);
105-
});
102+
// Don't remove underscores from `single_imports`, they were never added.
103+
if target.name != kw::Underscore {
104+
let key = BindingKey::new(*target, ns);
105+
this.update_local_resolution(
106+
parent,
107+
key,
108+
false,
109+
|_, resolution| {
110+
resolution.single_imports.swap_remove(&import);
111+
},
112+
);
113+
}
106114
}
107115
_ => {}
108116
}
109-
bindings[ns].set(pending_binding);
110-
}
117+
bindings[ns].set(import_bindings[ns]);
118+
});
111119
}
112120
(ImportKind::Glob { id, .. }, SideEffectBindings::Glob { import_bindings }) => {
113121
let ModuleOrUniformRoot::Module(module) = import.imported_module.get().unwrap()
@@ -973,7 +981,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
973981
}
974982
};
975983

976-
let (source, target, bindings, type_ns_only) = match import.kind {
984+
let (source, _, bindings, type_ns_only) = match import.kind {
977985
ImportKind::Single { source, target, ref bindings, type_ns_only, .. } => {
978986
(source, target, bindings, type_ns_only)
979987
}
@@ -989,7 +997,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
989997
_ => unreachable!(),
990998
};
991999

992-
let mut import_bindings = PerNS::default();
1000+
let mut import_bindings = bindings.clone().map(|b| b.get());
9931001
let mut indeterminate_count = 0;
9941002
self.reborrow().per_ns_cm(|this, ns| {
9951003
if !type_ns_only || ns == TypeNS {
@@ -1009,16 +1017,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10091017
let imported_binding = this.import(binding, import);
10101018
PendingBinding::Ready(Some(imported_binding))
10111019
}
1012-
Err(Determinacy::Determined) => {
1013-
// Don't remove underscores from `single_imports`, they were never added.
1014-
if target.name == kw::Underscore {
1015-
return;
1016-
}
1017-
PendingBinding::Ready(None)
1018-
}
1020+
Err(Determinacy::Determined) => PendingBinding::Ready(None),
10191021
Err(Determinacy::Undetermined) => {
10201022
indeterminate_count += 1;
1021-
return;
1023+
PendingBinding::Pending
10221024
}
10231025
};
10241026
import_bindings[ns] = pending_binding;

0 commit comments

Comments
 (0)