diff options
| author | bors <bors@rust-lang.org> | 2014-07-18 11:51:20 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-07-18 11:51:20 +0000 |
| commit | 441866417764cb0ad32bce50ebda83deec525997 (patch) | |
| tree | f1fd7e8d1e688841135ecf717947fdf2f6f52687 | |
| parent | d9f1d6b7f69f293ba5f060fd9e179de228d9497b (diff) | |
| parent | 99bd9265d98b74283ee2fa7fa45782e83e5bb79c (diff) | |
| download | rust-441866417764cb0ad32bce50ebda83deec525997.tar.gz rust-441866417764cb0ad32bce50ebda83deec525997.zip | |
auto merge of #15733 : sanxiyn/rust/use-from-type, r=alexcrichton
Importing from types was disallowed in #6462. Flag was set for paths whether it is a module or a type. Type flag was set when impl was seen. The problem is, for cross-crate situations, when reexport is involved, it is possible that impl is seen too late because metadata is loaded lazily. Fix #15664.
| -rw-r--r-- | src/librustc/middle/resolve.rs | 8 | ||||
| -rw-r--r-- | src/test/auxiliary/use_from_trait_xc.rs | 10 | ||||
| -rw-r--r-- | src/test/compile-fail/use-from-trait-xc.rs | 3 |
3 files changed, 20 insertions, 1 deletions
diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 5bea24dfa90..3ff2ef77089 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -1622,6 +1622,12 @@ impl<'a> Resolver<'a> { if is_exported { self.external_exports.insert(def.def_id()); } + + let kind = match def { + DefStruct(..) | DefTy(..) => ImplModuleKind, + _ => NormalModuleKind + }; + match def { DefMod(def_id) | DefForeignMod(def_id) | DefStruct(def_id) | DefTy(def_id) => { @@ -1640,7 +1646,7 @@ impl<'a> Resolver<'a> { child_name_bindings.define_module(parent_link, Some(def_id), - NormalModuleKind, + kind, true, is_public, DUMMY_SP); diff --git a/src/test/auxiliary/use_from_trait_xc.rs b/src/test/auxiliary/use_from_trait_xc.rs index 19e53fcc61a..8c547c28002 100644 --- a/src/test/auxiliary/use_from_trait_xc.rs +++ b/src/test/auxiliary/use_from_trait_xc.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +pub use self::sub::Bar; + pub trait Trait { fn foo(); } @@ -17,3 +19,11 @@ struct Foo; impl Foo { pub fn new() {} } + +mod sub { + pub struct Bar; + + impl Bar { + pub fn new() {} + } +} diff --git a/src/test/compile-fail/use-from-trait-xc.rs b/src/test/compile-fail/use-from-trait-xc.rs index 8e197b901e6..cea85955d37 100644 --- a/src/test/compile-fail/use-from-trait-xc.rs +++ b/src/test/compile-fail/use-from-trait-xc.rs @@ -18,4 +18,7 @@ use use_from_trait_xc::Trait::foo; use use_from_trait_xc::Foo::new; //~^ ERROR unresolved import `use_from_trait_xc::Foo::new`. Cannot import from a trait or type imple +use use_from_trait_xc::Bar::new; +//~^ ERROR unresolved import `use_from_trait_xc::Bar::new`. Cannot import from a trait or type + fn main() {} |
