Skip to content

Commit 1a6092e

Browse files
committed
Forbid use Trait::*
1 parent e2171bf commit 1a6092e

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/librustc_resolve/resolve_imports.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,10 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
586586
target_module: Module<'b>,
587587
directive: &'b ImportDirective)
588588
-> ResolveResult<()> {
589+
if let Some(Def::Trait(_)) = target_module.def {
590+
self.resolver.session.span_err(directive.span, "items in traits are not importable.");
591+
}
592+
589593
if module_.def_id() == target_module.def_id() {
590594
// This means we are trying to glob import a module into itself, and it is a no-go
591595
let msg = "Cannot glob-import a module into itself.".into();

src/test/compile-fail/issue-30560.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ type Alias = ();
1212
use Alias::*; //~ ERROR Not a module
1313
use std::io::Result::*; //~ ERROR Not a module
1414

15+
trait T {}
16+
use T::*; //~ ERROR items in traits are not importable
17+
1518
fn main() {}

0 commit comments

Comments
 (0)