]> git.lizzy.rs Git - rust.git/commitdiff
rustc_resolve: bring back "struct called like a function" cross-crate.
authorEduard Burtescu <edy.burt@gmail.com>
Mon, 19 Sep 2016 00:45:38 +0000 (03:45 +0300)
committerEduard Burtescu <edy.burt@gmail.com>
Tue, 20 Sep 2016 17:08:07 +0000 (20:08 +0300)
src/librustc/middle/cstore.rs
src/librustc_metadata/csearch.rs
src/librustc_metadata/decoder.rs
src/librustc_resolve/build_reduced_graph.rs
src/test/compile-fail/auxiliary/issue_19452_aux.rs [new file with mode: 0644]
src/test/compile-fail/issue-19452.rs

index 2ebf7ba6d53d24f740b312b79d640d9a721ba244..e57e116cea7407e2a48b9fe87cf334e6ed226a7d 100644 (file)
@@ -200,6 +200,7 @@ fn def_index_for_def_key(&self,
                              -> Option<DefIndex>;
     fn def_key(&self, def: DefId) -> hir_map::DefKey;
     fn relative_def_path(&self, def: DefId) -> Option<hir_map::DefPath>;
+    fn variant_kind(&self, def_id: DefId) -> Option<ty::VariantKind>;
     fn struct_ctor_def_id(&self, struct_def_id: DefId) -> Option<DefId>;
     fn struct_field_names(&self, def: DefId) -> Vec<ast::Name>;
     fn item_children(&self, did: DefId) -> Vec<def::Export>;
@@ -283,7 +284,7 @@ fn describe_def(&self, def: DefId) -> Option<Def> { bug!("describe_def") }
     fn stability(&self, def: DefId) -> Option<attr::Stability> { bug!("stability") }
     fn deprecation(&self, def: DefId) -> Option<attr::Deprecation> { bug!("deprecation") }
     fn visibility(&self, def: DefId) -> ty::Visibility { bug!("visibility") }
-    fn closure_kind(&self, def_id: DefId) -> ty::ClosureKind  { bug!("closure_kind") }
+    fn closure_kind(&self, def_id: DefId) -> ty::ClosureKind { bug!("closure_kind") }
     fn closure_ty<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
                       -> ty::ClosureTy<'tcx>  { bug!("closure_ty") }
     fn item_variances(&self, def: DefId) -> Vec<ty::Variance> { bug!("item_variances") }
@@ -376,6 +377,7 @@ fn def_key(&self, def: DefId) -> hir_map::DefKey { bug!("def_key") }
     fn relative_def_path(&self, def: DefId) -> Option<hir_map::DefPath> {
         bug!("relative_def_path")
     }
+    fn variant_kind(&self, def_id: DefId) -> Option<ty::VariantKind> { bug!("variant_kind") }
     fn struct_ctor_def_id(&self, struct_def_id: DefId) -> Option<DefId>
         { bug!("struct_ctor_def_id") }
     fn struct_field_names(&self, def: DefId) -> Vec<ast::Name> { bug!("struct_field_names") }
index 7013720224a6407b507d31c09a74041bad4bf2dc..1f25136ffe1acc679c7870dc66be5362b2f3ff5c 100644 (file)
@@ -342,6 +342,12 @@ fn relative_def_path(&self, def: DefId) -> Option<hir_map::DefPath> {
         self.get_crate_data(def.krate).def_path(def.index)
     }
 
+    fn variant_kind(&self, def_id: DefId) -> Option<ty::VariantKind>
+    {
+        self.dep_graph.read(DepNode::MetaData(def_id));
+        self.get_crate_data(def_id.krate).get_variant_kind(def_id.index)
+    }
+
     fn struct_ctor_def_id(&self, struct_def_id: DefId) -> Option<DefId>
     {
         self.dep_graph.read(DepNode::MetaData(struct_def_id));
index e718a107bbe29bc688fb631e803b1bb3eb1abfbc..3e4a2542b270bc9f7b7bd3c22e56142b2f2dac21 100644 (file)
@@ -787,6 +787,15 @@ pub fn get_item_variances(&self, id: DefIndex) -> Vec<ty::Variance> {
         self.entry(id).variances.decode(self).collect()
     }
 
+    pub fn get_variant_kind(&self, node_id: DefIndex) -> Option<ty::VariantKind> {
+        match self.entry(node_id).kind {
+            EntryKind::Struct(data) |
+            EntryKind::Union(data) |
+            EntryKind::Variant(data) => Some(data.decode(self).kind),
+            _ => None
+        }
+    }
+
     pub fn get_struct_ctor_def_id(&self, node_id: DefIndex) -> Option<DefId> {
         match self.entry(node_id).kind {
             EntryKind::Struct(data) => {
index 3c5e9e6cd3a99ab679c420a17d2d041e4de95261..c9591c31831a850fe0ec7b30051ead1eac0ba45e 100644 (file)
@@ -411,12 +411,16 @@ fn build_reduced_graph_for_external_crate_def(&mut self, parent: Module<'b>,
                 let module = self.new_module(parent_link, Some(def), None);
                 let _ = self.try_define(parent, name, TypeNS, (module, DUMMY_SP, vis));
             }
-            Def::Variant(..) => {
+            Def::Variant(variant_id) => {
                 debug!("(building reduced graph for external crate) building variant {}", name);
                 // Variants are always treated as importable to allow them to be glob used.
                 // All variants are defined in both type and value namespaces as future-proofing.
                 let _ = self.try_define(parent, name, TypeNS, (def, DUMMY_SP, vis));
                 let _ = self.try_define(parent, name, ValueNS, (def, DUMMY_SP, vis));
+                if self.session.cstore.variant_kind(variant_id) == Some(ty::VariantKind::Struct) {
+                    // Not adding fields for variants as they are not accessed with a self receiver
+                    self.structs.insert(variant_id, Vec::new());
+                }
             }
             Def::Fn(..) |
             Def::Static(..) |
diff --git a/src/test/compile-fail/auxiliary/issue_19452_aux.rs b/src/test/compile-fail/auxiliary/issue_19452_aux.rs
new file mode 100644 (file)
index 0000000..205566e
--- /dev/null
@@ -0,0 +1,13 @@
+// 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.
+
+pub enum Homura {
+    Madoka { age: u32 }
+}
index 15d5d2b80c31d0053eeb75ae2915cefecbce8a19..34872b7c8c503edbb0e9521674e34f18f594b3b1 100644 (file)
@@ -8,6 +8,9 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// aux-build:issue_19452_aux.rs
+extern crate issue_19452_aux;
+
 enum Homura {
     Madoka { age: u32 }
 }
@@ -16,4 +19,8 @@ fn main() {
     let homura = Homura::Madoka;
     //~^ ERROR uses it like a function
     //~| struct called like a function
+
+    let homura = issue_19452_aux::Homura::Madoka;
+    //~^ ERROR uses it like a function
+    //~| struct called like a function
 }