Skip to content

Commit 7403b0c

Browse files
committed
Handle conflicting import of items declared in the same module
Fixes #19498
1 parent 3a325c6 commit 7403b0c

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

src/librustc/middle/resolve.rs

+29-5
Original file line numberDiff line numberDiff line change
@@ -2654,10 +2654,34 @@ impl<'a> Resolver<'a> {
26542654

26552655
}
26562656
Some(_) => {
2657-
// The import is unresolved. Bail out.
2658-
debug!("(resolving single import) unresolved import; \
2659-
bailing out");
2660-
return Indeterminate;
2657+
// If containing_module is the same module whose import we are resolving
2658+
// and there it has an unresolved import with the same name as `source`,
2659+
// then the user is actually trying to import an item that is declared
2660+
// in the same scope
2661+
//
2662+
// e.g
2663+
// use self::submodule;
2664+
// pub mod submodule;
2665+
//
2666+
// In this case we continue as if we resolved the import and let the
2667+
// check_for_conflicts_between_imports_and_items call below handle
2668+
// the conflict
2669+
match (module_.def_id.get(), containing_module.def_id.get()) {
2670+
(Some(id1), Some(id2)) if id1 == id2 => {
2671+
if value_result.is_unknown() {
2672+
value_result = UnboundResult;
2673+
}
2674+
if type_result.is_unknown() {
2675+
type_result = UnboundResult;
2676+
}
2677+
}
2678+
_ => {
2679+
// The import is unresolved. Bail out.
2680+
debug!("(resolving single import) unresolved import; \
2681+
bailing out");
2682+
return Indeterminate;
2683+
}
2684+
}
26612685
}
26622686
}
26632687
}
@@ -3018,7 +3042,7 @@ impl<'a> Resolver<'a> {
30183042
fn check_for_conflicts_between_imports_and_items(&mut self,
30193043
module: &Module,
30203044
import_resolution:
3021-
&mut ImportResolution,
3045+
&ImportResolution,
30223046
import_span: Span,
30233047
name: Name) {
30243048
if self.session.features.borrow().import_shadowing {

0 commit comments

Comments
 (0)