Skip to content

Prohibit renaming to primitive types' names in import lists #28406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2212,13 +2212,27 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {

ItemUse(ref view_path) => {
// check for imports shadowing primitive types
if let hir::ViewPathSimple(ident, _) = view_path.node {
match self.def_map.borrow().get(&item.id).map(|d| d.full_def()) {
let check_rename = |id, ident: Ident| {
match self.def_map.borrow().get(&id).map(|d| d.full_def()) {
Some(DefTy(..)) | Some(DefStruct(..)) | Some(DefTrait(..)) | None => {
self.check_if_primitive_type_name(ident.name, item.span);
}
_ => {}
}
};

match view_path.node {
hir::ViewPathSimple(ident, _) => {
check_rename(item.id, ident);
}
hir::ViewPathList(_, ref items) => {
for item in items {
if let Some(ident) = item.node.rename() {
check_rename(item.node.id(), ident);
}
}
}
_ => {}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/issue-20427.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ mod char {
//~^ ERROR user-defined types or type parameters cannot shadow the primitive types
use super::bool_ as bool;
//~^ ERROR user-defined types or type parameters cannot shadow the primitive types
use super::{bool_ as str};
//~^ ERROR user-defined types or type parameters cannot shadow the primitive types
use super::char_ as char;
}
}
Expand Down