Skip to content

Commit

Permalink
Fix xcrate enum namespacing
Browse files Browse the repository at this point in the history
Closes #19293
  • Loading branch information
sfackler committed Nov 25, 2014
1 parent 48ca6d1 commit 79d9beb
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 22 deletions.
10 changes: 0 additions & 10 deletions src/librustc/metadata/encoder.rs
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_llvm/lib.rs
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/test/auxiliary/issue-13872-2.rs
Expand Up @@ -10,4 +10,4 @@

extern crate "issue-13872-1" as foo;

pub use foo::B;
pub use foo::A::B;
14 changes: 14 additions & 0 deletions 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 <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 struct Foo (pub int);
pub enum MyEnum {
Foo(Foo),
}
18 changes: 18 additions & 0 deletions 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 <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.

// 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
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/unreachable-variant.rs
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/xc-private-method2.rs
Expand Up @@ -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
}
17 changes: 17 additions & 0 deletions 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 <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.

// aux-build:issue_19293.rs
extern crate issue_19293;
use issue_19293::{Foo, MyEnum};

fn main() {
MyEnum::Foo(Foo(5));
}
2 changes: 1 addition & 1 deletion src/test/run-pass/issue-2316-c.rs
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion src/test/run-pass/issue-8259.rs
Expand Up @@ -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() {}
2 changes: 1 addition & 1 deletion src/test/run-pass/struct_variant_xc.rs
Expand Up @@ -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 };
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/struct_variant_xc_match.rs
Expand Up @@ -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 }) {
Expand Down
10 changes: 5 additions & 5 deletions src/test/run-pass/xcrate-unit-struct.rs
Expand Up @@ -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) {}
Expand All @@ -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);
Expand Down

0 comments on commit 79d9beb

Please sign in to comment.