Skip to content

Commit 834fb17

Browse files
committed
Fix bug in duplicate checking for extern crates.
1 parent 41611ba commit 834fb17

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

src/librustc_resolve/build_reduced_graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
325325

326326
debug!("(build reduced graph for item) found extern `{}`",
327327
module_to_string(&*external_module));
328-
self.check_for_conflicts_between_external_crates(&**parent, name, sp);
328+
self.check_for_conflicts_for_external_crate(&parent, name, sp);
329329
parent.external_module_children
330330
.borrow_mut()
331331
.insert(name, external_module.clone());

src/librustc_resolve/lib.rs

+21-12
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ enum SuggestionType {
122122
}
123123

124124
pub enum ResolutionError<'a> {
125+
/// error E0260: name conflicts with an extern crate
126+
NameConflictsWithExternCrate(Name),
125127
/// error E0401: can't use type parameters from outer function
126128
TypeParametersFromOuterFunction,
127129
/// error E0402: cannot use an outer type parameter in this context
@@ -228,6 +230,14 @@ fn resolve_struct_error<'b, 'a: 'b, 'tcx: 'a>(resolver: &'b Resolver<'a, 'tcx>,
228230
}
229231

230232
match resolution_error {
233+
ResolutionError::NameConflictsWithExternCrate(name) => {
234+
struct_span_err!(resolver.session,
235+
span,
236+
E0260,
237+
"the name `{}` conflicts with an external crate \
238+
that has been imported into this module",
239+
name)
240+
}
231241
ResolutionError::TypeParametersFromOuterFunction => {
232242
struct_span_err!(resolver.session,
233243
span,
@@ -1292,19 +1302,23 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
12921302
}
12931303
}
12941304

1295-
/// Checks that the names of external crates don't collide with other
1296-
/// external crates.
1297-
fn check_for_conflicts_between_external_crates(&self,
1298-
module: &Module,
1299-
name: Name,
1300-
span: Span) {
1305+
/// Check that an external crate doesn't collide with items or other external crates.
1306+
fn check_for_conflicts_for_external_crate(&self, module: &Module, name: Name, span: Span) {
13011307
if module.external_module_children.borrow().contains_key(&name) {
13021308
span_err!(self.session,
13031309
span,
13041310
E0259,
13051311
"an external crate named `{}` has already been imported into this module",
13061312
name);
13071313
}
1314+
match module.children.borrow().get(&name) {
1315+
Some(name_bindings) if name_bindings.type_ns.defined() => {
1316+
resolve_error(self,
1317+
name_bindings.type_ns.span().unwrap_or(codemap::DUMMY_SP),
1318+
ResolutionError::NameConflictsWithExternCrate(name));
1319+
}
1320+
_ => {},
1321+
}
13081322
}
13091323

13101324
/// Checks that the names of items don't collide with external crates.
@@ -1313,12 +1327,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
13131327
name: Name,
13141328
span: Span) {
13151329
if module.external_module_children.borrow().contains_key(&name) {
1316-
span_err!(self.session,
1317-
span,
1318-
E0260,
1319-
"the name `{}` conflicts with an external crate that has been imported \
1320-
into this module",
1321-
name);
1330+
resolve_error(self, span, ResolutionError::NameConflictsWithExternCrate(name));
13221331
}
13231332
}
13241333

0 commit comments

Comments
 (0)