diff options
| author | bors <bors@rust-lang.org> | 2016-03-11 09:26:47 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-03-11 09:26:47 -0800 |
| commit | 5807fbbfde3ad04820f6fa0269711c81538057ec (patch) | |
| tree | cc108741a3523592608f23c2a0ea0783925469c9 /src | |
| parent | aeb85a953322df7773095186e9762f3fe73375e2 (diff) | |
| parent | 1a6092e05cecdaef984b2b0174089e6ae8c24181 (diff) | |
| download | rust-5807fbbfde3ad04820f6fa0269711c81538057ec.tar.gz rust-5807fbbfde3ad04820f6fa0269711c81538057ec.zip | |
Auto merge of #32134 - jseyfried:forbid_type_alias_as_module, r=nikomatsakis
Forbid glob-importing from a type alias This PR forbids glob-importing from a type alias or trait (fixes #30560): ```rust type Alias = (); use Alias::*; // This is currently allowed but shouldn't be ``` This is a [breaking-change]. Since the disallowed glob imports don't actually import anything, any breakage can be fixed by removing the offending glob import. r? @alexcrichton
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_resolve/build_reduced_graph.rs | 8 | ||||
| -rw-r--r-- | src/librustc_resolve/resolve_imports.rs | 4 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-30560.rs | 18 |
3 files changed, 25 insertions, 5 deletions
diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index ad4bcff1d3d..dba7d178b4c 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -330,10 +330,8 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> { // These items live in the type namespace. ItemTy(..) => { - let parent_link = ModuleParentLink(parent, name); let def = Def::TyAlias(self.ast_map.local_def_id(item.id)); - let module = self.new_module(parent_link, Some(def), false, is_public); - self.define(parent, name, TypeNS, (module, sp)); + self.define(parent, name, TypeNS, (def, sp, modifiers)); parent } @@ -495,7 +493,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> { } match def { - Def::Mod(_) | Def::ForeignMod(_) | Def::Enum(..) | Def::TyAlias(..) => { + Def::Mod(_) | Def::ForeignMod(_) | Def::Enum(..) => { debug!("(building reduced graph for external crate) building module {} {}", final_ident, is_public); @@ -548,7 +546,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> { let module = self.new_module(parent_link, Some(def), true, is_public); self.try_define(new_parent, name, TypeNS, (module, DUMMY_SP)); } - Def::AssociatedTy(..) => { + Def::TyAlias(..) | Def::AssociatedTy(..) => { debug!("(building reduced graph for external crate) building type {}", final_ident); self.try_define(new_parent, name, TypeNS, (def, DUMMY_SP, modifiers)); diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 97124b7f46a..ea16211c40d 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -607,6 +607,10 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> { target_module: Module<'b>, directive: &'b ImportDirective) -> ResolveResult<()> { + if let Some(Def::Trait(_)) = target_module.def { + self.resolver.session.span_err(directive.span, "items in traits are not importable."); + } + if module_.def_id() == target_module.def_id() { // This means we are trying to glob import a module into itself, and it is a no-go let msg = "Cannot glob-import a module into itself.".into(); diff --git a/src/test/compile-fail/issue-30560.rs b/src/test/compile-fail/issue-30560.rs new file mode 100644 index 00000000000..71c7e600965 --- /dev/null +++ b/src/test/compile-fail/issue-30560.rs @@ -0,0 +1,18 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +type Alias = (); +use Alias::*; //~ ERROR Not a module +use std::io::Result::*; //~ ERROR Not a module + +trait T {} +use T::*; //~ ERROR items in traits are not importable + +fn main() {} |
