]> git.lizzy.rs Git - rust.git/commitdiff
auto merge of #15733 : sanxiyn/rust/use-from-type, r=alexcrichton
authorbors <bors@rust-lang.org>
Fri, 18 Jul 2014 11:51:20 +0000 (11:51 +0000)
committerbors <bors@rust-lang.org>
Fri, 18 Jul 2014 11:51:20 +0000 (11:51 +0000)
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.

src/librustc/middle/resolve.rs
src/test/auxiliary/use_from_trait_xc.rs
src/test/compile-fail/use-from-trait-xc.rs

index 5bea24dfa90f6d53385099d5dbdbb7f2c7349822..3ff2ef770898c7b8e83402197abb73b0d318ed35 100644 (file)
@@ -1622,6 +1622,12 @@ fn handle_external_def(&mut self,
         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 @@ fn handle_external_def(&mut self,
 
                 child_name_bindings.define_module(parent_link,
                                                   Some(def_id),
-                                                  NormalModuleKind,
+                                                  kind,
                                                   true,
                                                   is_public,
                                                   DUMMY_SP);
index 19e53fcc61aa3ee33d3b96232eb3c7d08490205b..8c547c2800204e357b8b523523360b11ff796c7d 100644 (file)
@@ -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 @@ pub trait Trait {
 impl Foo {
     pub fn new() {}
 }
+
+mod sub {
+    pub struct Bar;
+
+    impl Bar {
+        pub fn new() {}
+    }
+}
index 8e197b901e610b5a3395756c7a0ed76a89b050ec..cea85955d37955a01c474e4f666dbc8ac8e6e1aa 100644 (file)
@@ -18,4 +18,7 @@
 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() {}