rustc_resolve: bring back "struct called like a function" cross-crate.
This commit is contained in:
parent
564f2ee33c
commit
521d3ea193
6 changed files with 43 additions and 2 deletions
|
|
@ -200,6 +200,7 @@ pub trait CrateStore<'tcx> {
|
|||
-> 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 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
|
|||
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 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
|
|||
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") }
|
||||
|
|
|
|||
|
|
@ -342,6 +342,12 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
|
|||
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));
|
||||
|
|
|
|||
|
|
@ -787,6 +787,15 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
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) => {
|
||||
|
|
|
|||
|
|
@ -411,12 +411,16 @@ impl<'b> Resolver<'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(..) |
|
||||
|
|
|
|||
13
src/test/compile-fail/auxiliary/issue_19452_aux.rs
Normal file
13
src/test/compile-fail/auxiliary/issue_19452_aux.rs
Normal file
|
|
@ -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 }
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue