Skip to content

Commit c7f94d9

Browse files
fix duplicate errors
1 parent ac73317 commit c7f94d9

File tree

1 file changed

+36
-40
lines changed

1 file changed

+36
-40
lines changed

compiler/rustc_resolve/src/imports.rs

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ enum SideEffectBindings<'ra> {
5353
import_bindings: PerNS<Option<Option<NameBinding<'ra>>>>,
5454
},
5555
Glob {
56-
import_bindings: Vec<(NameBinding<'ra>, BindingKey, bool /* warn_ambiguity */)>,
56+
import_bindings: Vec<(NameBinding<'ra>, BindingKey)>,
5757
},
5858
}
5959

@@ -601,9 +601,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
601601
&mut self,
602602
import_resolutions: Vec<(Import<'ra>, SideEffect<'ra>)>,
603603
) {
604-
self.determined_imports.reserve(self.determined_imports.len());
605604
for (import, side_effect) in import_resolutions.iter() {
606-
self.determined_imports.push(*import);
607605
let SideEffect { imported_module, .. } = side_effect;
608606
import.imported_module.set(Some(*imported_module));
609607

@@ -679,12 +677,17 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
679677
.emit();
680678
}
681679

682-
for (binding, key, warn_ambiguity) in import_bindings {
680+
for (binding, key) in import_bindings {
681+
let imported_binding = self.import(binding, import);
682+
let warn_ambiguity = self
683+
.resolution(import.parent_scope.module, key)
684+
.and_then(|r| r.binding())
685+
.is_some_and(|binding| binding.warn_ambiguity_recursive());
683686
let _ = self.try_define_local(
684687
parent,
685688
key.ident.0,
686689
key.ns,
687-
binding,
690+
imported_binding,
688691
warn_ambiguity,
689692
);
690693
}
@@ -1592,47 +1595,40 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15921595
false
15931596
}
15941597

1595-
fn resolve_glob_import<'r>(
1596-
self: &mut CmResolver<'r, 'ra, 'tcx>,
1598+
fn resolve_glob_import(
1599+
&self,
15971600
import: Import<'ra>,
15981601
imported_module: ModuleOrUniformRoot<'ra>,
15991602
) -> SideEffectBindings<'ra> {
1600-
// This function is only called for glob imports.
1601-
let ImportKind::Glob { .. } = import.kind else { unreachable!() };
1603+
match imported_module {
1604+
ModuleOrUniformRoot::Module(module) if module != import.parent_scope.module => {
1605+
let import_bindings = self
1606+
.resolutions(module)
1607+
.borrow()
1608+
.iter()
1609+
.filter_map(|(key, resolution)| {
1610+
let binding = resolution.borrow().binding()?;
1611+
let mut key = *key;
1612+
let scope = match key
1613+
.ident
1614+
.0
1615+
.span
1616+
.reverse_glob_adjust(module.expansion, import.span)
1617+
{
1618+
Some(Some(def)) => self.expn_def_scope(def),
1619+
Some(None) => import.parent_scope.module,
1620+
None => return None,
1621+
};
1622+
self.is_accessible_from(binding.vis, scope).then(|| (binding, key))
1623+
})
1624+
.collect::<Vec<_>>();
16021625

1603-
let ModuleOrUniformRoot::Module(module) = imported_module else {
1604-
return SideEffectBindings::None;
1605-
};
1626+
SideEffectBindings::Glob { import_bindings }
1627+
}
16061628

1607-
if module == import.parent_scope.module {
1608-
return SideEffectBindings::None;
1629+
// Errors are reported in `commit_imports_resolutions`
1630+
_ => SideEffectBindings::None,
16091631
}
1610-
1611-
let import_bindings = self
1612-
.resolutions(module)
1613-
.borrow()
1614-
.iter()
1615-
.filter_map(|(key, resolution)| {
1616-
let binding = resolution.borrow().binding()?;
1617-
let mut key = *key;
1618-
let scope =
1619-
match key.ident.0.span.reverse_glob_adjust(module.expansion, import.span) {
1620-
Some(Some(def)) => self.expn_def_scope(def),
1621-
Some(None) => import.parent_scope.module,
1622-
None => return None,
1623-
};
1624-
self.is_accessible_from(binding.vis, scope).then(|| {
1625-
let imported_binding = self.import(binding, import);
1626-
let warn_ambiguity = self
1627-
.resolution(import.parent_scope.module, key)
1628-
.and_then(|r| r.binding())
1629-
.is_some_and(|binding| binding.warn_ambiguity_recursive());
1630-
(imported_binding, key, warn_ambiguity)
1631-
})
1632-
})
1633-
.collect::<Vec<_>>();
1634-
1635-
SideEffectBindings::Glob { import_bindings }
16361632
}
16371633

16381634
// Miscellaneous post-processing, including recording re-exports,

0 commit comments

Comments
 (0)