From 79d9bebf49ec56078439816f4856dc4e47aa6523 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Tue, 25 Nov 2014 10:00:46 -0800 Subject: [PATCH] Fix xcrate enum namespacing Closes #19293 --- src/librustc/metadata/encoder.rs | 10 ---------- src/librustc_llvm/lib.rs | 1 + src/test/auxiliary/issue-13872-2.rs | 2 +- src/test/auxiliary/issue_19293.rs | 14 ++++++++++++++ .../compile-fail/enums-are-namespaced-xc.rs | 18 ++++++++++++++++++ src/test/compile-fail/unreachable-variant.rs | 2 +- src/test/compile-fail/xc-private-method2.rs | 2 +- src/test/run-pass/issue-19293.rs | 17 +++++++++++++++++ src/test/run-pass/issue-2316-c.rs | 2 +- src/test/run-pass/issue-8259.rs | 2 +- src/test/run-pass/struct_variant_xc.rs | 2 +- src/test/run-pass/struct_variant_xc_match.rs | 2 +- src/test/run-pass/xcrate-unit-struct.rs | 10 +++++----- 13 files changed, 62 insertions(+), 22 deletions(-) create mode 100644 src/test/auxiliary/issue_19293.rs create mode 100644 src/test/compile-fail/enums-are-namespaced-xc.rs create mode 100644 src/test/run-pass/issue-19293.rs diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 7e4d2621f18..7f4e811f514 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -500,20 +500,10 @@ fn encode_reexported_static_methods(ecx: &EncodeContext, /// Iterates through "auxiliary node IDs", which are node IDs that describe /// top-level items that are sub-items of the given item. Specifically: /// -/// * For enums, iterates through the node IDs of the variants. -/// /// * For newtype structs, iterates through the node ID of the constructor. fn each_auxiliary_node_id(item: &ast::Item, callback: |NodeId| -> bool) -> bool { let mut continue_ = true; match item.node { - ast::ItemEnum(ref enum_def, _) => { - for variant in enum_def.variants.iter() { - continue_ = callback(variant.node.id); - if !continue_ { - break - } - } - } ast::ItemStruct(ref struct_def, _) => { // If this is a newtype struct, return the constructor. match struct_def.ctor_id { diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index d67d0fa59ae..8d14912a6d4 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -45,6 +45,7 @@ pub use self::DiagnosticKind::*; pub use self::CallConv::*; pub use self::Visibility::*; pub use self::DiagnosticSeverity::*; +pub use self::Linkage::*; use std::c_str::ToCStr; use std::cell::RefCell; diff --git a/src/test/auxiliary/issue-13872-2.rs b/src/test/auxiliary/issue-13872-2.rs index e2744b7910f..8294d2b4594 100644 --- a/src/test/auxiliary/issue-13872-2.rs +++ b/src/test/auxiliary/issue-13872-2.rs @@ -10,4 +10,4 @@ extern crate "issue-13872-1" as foo; -pub use foo::B; +pub use foo::A::B; diff --git a/src/test/auxiliary/issue_19293.rs b/src/test/auxiliary/issue_19293.rs new file mode 100644 index 00000000000..40c8eb9b23a --- /dev/null +++ b/src/test/auxiliary/issue_19293.rs @@ -0,0 +1,14 @@ +// Copyright 2014 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub struct Foo (pub int); +pub enum MyEnum { + Foo(Foo), +} diff --git a/src/test/compile-fail/enums-are-namespaced-xc.rs b/src/test/compile-fail/enums-are-namespaced-xc.rs new file mode 100644 index 00000000000..5315e6c834a --- /dev/null +++ b/src/test/compile-fail/enums-are-namespaced-xc.rs @@ -0,0 +1,18 @@ +// Copyright 2014 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:namespaced_enums.rs +extern crate namespaced_enums; + +fn main() { + let _ = namespaced_enums::A; //~ ERROR unresolved name + let _ = namespaced_enums::B(10); //~ ERROR unresolved name + let _ = namespaced_enums::C { a: 10 }; //~ ERROR does not name a structure +} diff --git a/src/test/compile-fail/unreachable-variant.rs b/src/test/compile-fail/unreachable-variant.rs index a6f17efe6b5..ef991d85337 100644 --- a/src/test/compile-fail/unreachable-variant.rs +++ b/src/test/compile-fail/unreachable-variant.rs @@ -13,5 +13,5 @@ extern crate "unreachable-variant" as other; fn main() { - let _x = other::super_sekrit::baz; //~ ERROR is private + let _x = other::super_sekrit::sooper_sekrit::baz; //~ ERROR is private } diff --git a/src/test/compile-fail/xc-private-method2.rs b/src/test/compile-fail/xc-private-method2.rs index 48b07a39eb8..26e055d7cbb 100644 --- a/src/test/compile-fail/xc-private-method2.rs +++ b/src/test/compile-fail/xc-private-method2.rs @@ -16,6 +16,6 @@ fn main() { let _ = xc_private_method_lib::Struct{ x: 10 }.meth_struct(); //~^ ERROR method `meth_struct` is private - let _ = xc_private_method_lib::Variant1(20).meth_enum(); + let _ = xc_private_method_lib::Enum::Variant1(20).meth_enum(); //~^ ERROR method `meth_enum` is private } diff --git a/src/test/run-pass/issue-19293.rs b/src/test/run-pass/issue-19293.rs new file mode 100644 index 00000000000..4a446a76de3 --- /dev/null +++ b/src/test/run-pass/issue-19293.rs @@ -0,0 +1,17 @@ +// Copyright 2014 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:issue_19293.rs +extern crate issue_19293; +use issue_19293::{Foo, MyEnum}; + +fn main() { + MyEnum::Foo(Foo(5)); +} diff --git a/src/test/run-pass/issue-2316-c.rs b/src/test/run-pass/issue-2316-c.rs index a27f0b8d659..a6fac423bb6 100644 --- a/src/test/run-pass/issue-2316-c.rs +++ b/src/test/run-pass/issue-2316-c.rs @@ -15,5 +15,5 @@ extern crate issue_2316_b; use issue_2316_b::cloth; pub fn main() { - let _c: cloth::fabric = cloth::calico; + let _c: cloth::fabric = cloth::fabric::calico; } diff --git a/src/test/run-pass/issue-8259.rs b/src/test/run-pass/issue-8259.rs index 4805b7713ee..fb893873bc4 100644 --- a/src/test/run-pass/issue-8259.rs +++ b/src/test/run-pass/issue-8259.rs @@ -11,6 +11,6 @@ // aux-build:issue-8259.rs extern crate "issue-8259" as other; -static a: other::Foo<'static> = other::A; +static a: other::Foo<'static> = other::Foo::A; pub fn main() {} diff --git a/src/test/run-pass/struct_variant_xc.rs b/src/test/run-pass/struct_variant_xc.rs index 11521e86117..923a1427869 100644 --- a/src/test/run-pass/struct_variant_xc.rs +++ b/src/test/run-pass/struct_variant_xc.rs @@ -11,7 +11,7 @@ // aux-build:struct_variant_xc_aux.rs extern crate struct_variant_xc_aux; -use struct_variant_xc_aux::StructVariant; +use struct_variant_xc_aux::Enum::StructVariant; pub fn main() { let _ = StructVariant { arg: 1 }; diff --git a/src/test/run-pass/struct_variant_xc_match.rs b/src/test/run-pass/struct_variant_xc_match.rs index e7bc61c1fb9..41dcb7ddbc8 100644 --- a/src/test/run-pass/struct_variant_xc_match.rs +++ b/src/test/run-pass/struct_variant_xc_match.rs @@ -11,7 +11,7 @@ // aux-build:struct_variant_xc_aux.rs extern crate struct_variant_xc_aux; -use struct_variant_xc_aux::{StructVariant, Variant}; +use struct_variant_xc_aux::Enum::{StructVariant, Variant}; pub fn main() { let arg = match (StructVariant { arg: 42 }) { diff --git a/src/test/run-pass/xcrate-unit-struct.rs b/src/test/run-pass/xcrate-unit-struct.rs index 7eb73968db5..30b5f47b2ae 100644 --- a/src/test/run-pass/xcrate-unit-struct.rs +++ b/src/test/run-pass/xcrate-unit-struct.rs @@ -12,10 +12,10 @@ extern crate xcrate_unit_struct; const s1: xcrate_unit_struct::Struct = xcrate_unit_struct::Struct; -static s2: xcrate_unit_struct::Unit = xcrate_unit_struct::UnitVariant; +static s2: xcrate_unit_struct::Unit = xcrate_unit_struct::Unit::UnitVariant; static s3: xcrate_unit_struct::Unit = - xcrate_unit_struct::Argument(xcrate_unit_struct::Struct); -static s4: xcrate_unit_struct::Unit = xcrate_unit_struct::Argument(s1); + xcrate_unit_struct::Unit::Argument(xcrate_unit_struct::Struct); +static s4: xcrate_unit_struct::Unit = xcrate_unit_struct::Unit::Argument(s1); static s5: xcrate_unit_struct::TupleStruct = xcrate_unit_struct::TupleStruct(20, "foo"); fn f1(_: xcrate_unit_struct::Struct) {} @@ -24,8 +24,8 @@ fn f3(_: xcrate_unit_struct::TupleStruct) {} pub fn main() { f1(xcrate_unit_struct::Struct); - f2(xcrate_unit_struct::UnitVariant); - f2(xcrate_unit_struct::Argument(xcrate_unit_struct::Struct)); + f2(xcrate_unit_struct::Unit::UnitVariant); + f2(xcrate_unit_struct::Unit::Argument(xcrate_unit_struct::Struct)); f3(xcrate_unit_struct::TupleStruct(10, "bar")); f1(s1);