diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2015-09-15 01:07:17 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2015-09-15 01:07:17 +0300 |
| commit | cfa2925f2e4f9832aaa1c439163ff6b24cac8342 (patch) | |
| tree | 105b168cfbf834ff25fdb60b11bf9cb03529d0ca /src | |
| parent | 9040b06ed28d37022d7c5135a6809aba951a243e (diff) | |
| download | rust-cfa2925f2e4f9832aaa1c439163ff6b24cac8342.tar.gz rust-cfa2925f2e4f9832aaa1c439163ff6b24cac8342.zip | |
Prohibit renaming to primitive types' names in import lists
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_resolve/lib.rs | 18 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-20427.rs | 2 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index cd5f2a2e764..58564f2e057 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -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); + } + } + } + _ => {} } } diff --git a/src/test/compile-fail/issue-20427.rs b/src/test/compile-fail/issue-20427.rs index 96d4fae8b03..a4b25ab9e56 100644 --- a/src/test/compile-fail/issue-20427.rs +++ b/src/test/compile-fail/issue-20427.rs @@ -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; } } |
