First stage of enum namespacing changes

This commit is contained in:
Steven Fackler 2014-10-18 23:46:08 -07:00
parent 88b6e93d35
commit d7ff7da65a
17 changed files with 584 additions and 94 deletions

View file

@ -0,0 +1,38 @@
// 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.
#![feature(globs, struct_variant)]
pub use Foo::*;
pub enum Foo {
A,
B(int),
C { a: int },
}
impl Foo {
pub fn foo() {}
}
pub mod nest {
pub use self::Bar::*;
pub enum Bar {
D,
E(int),
F { a: int },
}
impl Bar {
pub fn foo() {}
}
}

View file

@ -0,0 +1,22 @@
// 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.
#![feature(struct_variant)]
pub enum Foo {
A,
B(int),
C { a: int },
}
impl Foo {
pub fn foo() {}
pub fn bar(&self) {}
}

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
pub use self::sub::Bar;
pub use self::sub::{Bar, Baz};
pub trait Trait {
fn foo();
@ -26,4 +26,10 @@ mod sub {
impl Bar {
pub fn new() {}
}
pub enum Baz {}
impl Baz {
pub fn new() {}
}
}

View file

@ -13,7 +13,7 @@ mod Foo {
}
enum Foo { //~ ERROR duplicate definition of type or module `Foo`
X
X //~ ERROR duplicate definition of value `X`
}
fn main() {}

View file

@ -0,0 +1,28 @@
// 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
#![feature(struct_variant, globs)]
extern crate namespaced_enums;
mod m {
pub use namespaced_enums::Foo::*;
}
pub fn main() {
use namespaced_enums::Foo::*;
foo(); //~ ERROR unresolved name `foo`
m::foo(); //~ ERROR unresolved name `m::foo`
bar(); //~ ERROR unresolved name `bar`
m::bar(); //~ ERROR unresolved name `m::bar`
}

View file

@ -0,0 +1,36 @@
// 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.
#![feature(struct_variant, globs)]
mod m2 {
pub enum Foo {
A,
B(int),
C { a: int },
}
impl Foo {
pub fn foo() {}
pub fn bar(&self) {}
}
}
mod m {
pub use m2::Foo::*;
}
pub fn main() {
use m2::Foo::*;
foo(); //~ ERROR unresolved name `foo`
m::foo(); //~ ERROR unresolved name `m::foo`
bar(); //~ ERROR unresolved name `bar`
m::bar(); //~ ERROR unresolved name `m::bar`
}

View file

@ -13,12 +13,15 @@
extern crate use_from_trait_xc;
use use_from_trait_xc::Trait::foo;
//~^ ERROR unresolved import `use_from_trait_xc::Trait::foo`. Cannot import from a trait or type imp
//~^ ERROR `foo` is not directly importable
use use_from_trait_xc::Foo::new;
//~^ ERROR unresolved import `use_from_trait_xc::Foo::new`. Cannot import from a trait or type imple
//~^ ERROR `new` is not directly importable
use use_from_trait_xc::Bar::new;
//~^ ERROR unresolved import `use_from_trait_xc::Bar::new`. Cannot import from a trait or type
use use_from_trait_xc::Bar::new as bnew;
//~^ ERROR `bnew` is not directly importable
use use_from_trait_xc::Baz::new as baznew;
//~^ ERROR `baznew` is not directly importable
fn main() {}

View file

@ -9,9 +9,9 @@
// except according to those terms.
use Trait::foo;
//~^ ERROR unresolved import `Trait::foo`. Cannot import from a trait or type implementation
//~^ ERROR `foo` is not directly importable
use Foo::new;
//~^ ERROR unresolved import `Foo::new`. Cannot import from a trait or type implementation
//~^ ERROR `new` is not directly importable
pub trait Trait {
fn foo();

View file

@ -0,0 +1,32 @@
// 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_enum_emulate_flat.rs
#![feature(struct_variant)]
extern crate namespaced_enum_emulate_flat;
use namespaced_enum_emulate_flat::{Foo, A, B, C};
use namespaced_enum_emulate_flat::nest::{Bar, D, E, F};
fn _f(f: Foo) {
match f {
A | B(_) | C { .. } => {}
}
}
fn _f2(f: Bar) {
match f {
D | E(_) | F { .. } => {}
}
}
pub fn main() {}

View file

@ -0,0 +1,51 @@
// 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.
#![feature(globs, struct_variant)]
pub use Foo::*;
use nest::{Bar, D, E, F};
pub enum Foo {
A,
B(int),
C { a: int },
}
impl Foo {
pub fn foo() {}
}
fn _f(f: Foo) {
match f {
A | B(_) | C { .. } => {}
}
}
mod nest {
pub use self::Bar::*;
pub enum Bar {
D,
E(int),
F { a: int },
}
impl Bar {
pub fn foo() {}
}
}
fn _f2(f: Bar) {
match f {
D | E(_) | F { .. } => {}
}
}
fn main() {}

View file

@ -0,0 +1,34 @@
// 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
#![feature(globs, struct_variant)]
extern crate namespaced_enums;
fn _f(f: namespaced_enums::Foo) {
use namespaced_enums::Foo::*;
match f {
A | B(_) | C { .. } => {}
}
}
mod m {
pub use namespaced_enums::Foo::*;
}
fn _f2(f: namespaced_enums::Foo) {
match f {
m::A | m::B(_) | m::C { .. } => {}
}
}
pub fn main() {}

View file

@ -0,0 +1,42 @@
// 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.
#![feature(globs, struct_variant)]
mod m2 {
pub enum Foo {
A,
B(int),
C { a: int },
}
impl Foo {
pub fn foo() {}
}
}
mod m {
pub use m2::Foo::*;
}
fn _f(f: m2::Foo) {
use m2::Foo::*;
match f {
A | B(_) | C { .. } => {}
}
}
fn _f2(f: m2::Foo) {
match f {
m::A | m::B(_) | m::C { .. } => {}
}
}
pub fn main() {}

View file

@ -0,0 +1,25 @@
// 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
#![feature(struct_variant)]
extern crate namespaced_enums;
use namespaced_enums::Foo;
fn _foo (f: Foo) {
match f {
Foo::A | Foo::B(_) | Foo::C { .. } => {}
}
}
pub fn main() {}

View file

@ -0,0 +1,24 @@
// 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.
#![feature(struct_variant)]
enum Foo {
A,
B(int),
C { a: int },
}
fn _foo (f: Foo) {
match f {
Foo::A | Foo::B(_) | Foo::C { .. } => {}
}
}
pub fn main() {}