Skip to content

Commit

Permalink
Switch to purely namespaced enums
Browse files Browse the repository at this point in the history
This breaks code that referred to variant names in the same namespace as
their enum. Reexport the variants in the old location or alter code to
refer to the new locations:

```
pub enum Foo {
    A,
    B
}

fn main() {
    let a = A;
}
```
=>
```
pub use self::Foo::{A, B};

pub enum Foo {
    A,
    B
}

fn main() {
    let a = A;
}
```
or
```
pub enum Foo {
    A,
    B
}

fn main() {
    let a = Foo::A;
}
```

[breaking-change]
  • Loading branch information
sfackler committed Nov 17, 2014
1 parent aad7547 commit 7a87302
Show file tree
Hide file tree
Showing 483 changed files with 1,711 additions and 1,109 deletions.
1 change: 1 addition & 0 deletions src/compiletest/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// <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 use self::Mode::*;

use std::fmt;
use std::str::FromStr;
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

#![crate_type = "bin"]
#![feature(phase, slicing_syntax)]
#![feature(phase, slicing_syntax, globs)]

#![deny(warnings)]

Expand Down
2 changes: 2 additions & 0 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
// <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.
#[cfg(not(stage0))]
use self::TargetLocation::*;

use common::Config;
use common::{CompileFail, Pretty, RunFail, RunPass, RunPassValgrind, DebugInfoGdb};
Expand Down
20 changes: 10 additions & 10 deletions src/doc/guide-lifetimes.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ copying.
# }
fn compute_area(shape: &Shape) -> f64 {
match *shape {
Circle(_, radius) => std::f64::consts::PI * radius * radius,
Rectangle(_, ref size) => size.w * size.h
Shape::Circle(_, radius) => std::f64::consts::PI * radius * radius,
Shape::Rectangle(_, ref size) => size.w * size.h
}
}
~~~
Expand Down Expand Up @@ -478,14 +478,14 @@ example:
# a: &'r T, b: &'r T) -> &'r T {
# if compute_area(shape) > threshold {a} else {b}
# }
// -+ r
fn select_based_on_unit_circle<'r, T>( // |-+ B
threshold: f64, a: &'r T, b: &'r T) -> &'r T { // | |
// | |
let shape = Circle(Point {x: 0., y: 0.}, 1.); // | |
select(&shape, threshold, a, b) // | |
} // |-+
// -+
// -+ r
fn select_based_on_unit_circle<'r, T>( // |-+ B
threshold: f64, a: &'r T, b: &'r T) -> &'r T { // | |
// | |
let shape = Shape::Circle(Point {x: 0., y: 0.}, 1.); // | |
select(&shape, threshold, a, b) // | |
} // |-+
// -+
~~~

In this call to `select()`, the lifetime of the first parameter shape
Expand Down
40 changes: 20 additions & 20 deletions src/doc/guide-macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ doing nothing otherwise:
~~~~
# enum T { SpecialA(uint), SpecialB(uint) }
# fn f() -> uint {
# let input_1 = SpecialA(0);
# let input_2 = SpecialA(0);
# let input_1 = T::SpecialA(0);
# let input_2 = T::SpecialA(0);
match input_1 {
SpecialA(x) => { return x; }
T::SpecialA(x) => { return x; }
_ => {}
}
// ...
match input_2 {
SpecialB(x) => { return x; }
T::SpecialB(x) => { return x; }
_ => {}
}
# return 0u;
Expand All @@ -49,20 +49,20 @@ the pattern in the above code:
# #![feature(macro_rules)]
# enum T { SpecialA(uint), SpecialB(uint) }
# fn f() -> uint {
# let input_1 = SpecialA(0);
# let input_2 = SpecialA(0);
# let input_1 = T::SpecialA(0);
# let input_2 = T::SpecialA(0);
macro_rules! early_return(
($inp:expr $sp:ident) => ( // invoke it like `(input_5 SpecialE)`
($inp:expr $sp:path) => ( // invoke it like `(input_5 SpecialE)`
match $inp {
$sp(x) => { return x; }
_ => {}
}
);
)
// ...
early_return!(input_1 SpecialA);
early_return!(input_1 T::SpecialA);
// ...
early_return!(input_2 SpecialB);
early_return!(input_2 T::SpecialB);
# return 0;
# }
# fn main() {}
Expand Down Expand Up @@ -169,10 +169,10 @@ instead of `*` to mean "at least one".
# #![feature(macro_rules)]
# enum T { SpecialA(uint),SpecialB(uint),SpecialC(uint),SpecialD(uint)}
# fn f() -> uint {
# let input_1 = SpecialA(0);
# let input_2 = SpecialA(0);
# let input_1 = T::SpecialA(0);
# let input_2 = T::SpecialA(0);
macro_rules! early_return(
($inp:expr, [ $($sp:ident)|+ ]) => (
($inp:expr, [ $($sp:path)|+ ]) => (
match $inp {
$(
$sp(x) => { return x; }
Expand All @@ -182,9 +182,9 @@ macro_rules! early_return(
);
)
// ...
early_return!(input_1, [SpecialA|SpecialC|SpecialD]);
early_return!(input_1, [T::SpecialA|T::SpecialC|T::SpecialD]);
// ...
early_return!(input_2, [SpecialB]);
early_return!(input_2, [T::SpecialB]);
# return 0;
# }
# fn main() {}
Expand Down Expand Up @@ -234,9 +234,9 @@ Now consider code like the following:
# enum T3 { Good2(uint), Bad2}
# fn f(x: T1) -> uint {
match x {
Good1(g1, val) => {
T1::Good1(g1, val) => {
match g1.body {
Good2(result) => {
T3::Good2(result) => {
// complicated stuff goes here
return result + val;
},
Expand Down Expand Up @@ -281,9 +281,9 @@ macro_rules! biased_match (
# struct T2 { body: T3 }
# enum T3 { Good2(uint), Bad2}
# fn f(x: T1) -> uint {
biased_match!((x) ~ (Good1(g1, val)) else { return 0 };
biased_match!((x) ~ (T1::Good1(g1, val)) else { return 0 };
binds g1, val )
biased_match!((g1.body) ~ (Good2(result) )
biased_match!((g1.body) ~ (T3::Good2(result) )
else { panic!("Didn't get good_2") };
binds result )
// complicated stuff goes here
Expand Down Expand Up @@ -396,8 +396,8 @@ macro_rules! biased_match (
# enum T3 { Good2(uint), Bad2}
# fn f(x: T1) -> uint {
biased_match!(
(x) ~ (Good1(g1, val)) else { return 0 };
(g1.body) ~ (Good2(result) ) else { panic!("Didn't get Good2") };
(x) ~ (T1::Good1(g1, val)) else { return 0 };
(g1.body) ~ (T3::Good2(result) ) else { panic!("Didn't get Good2") };
binds val, result )
// complicated stuff goes here
return result + val;
Expand Down
2 changes: 1 addition & 1 deletion src/doc/guide-pointers.md
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ enum List<T> {
}
fn main() {
let list: List<int> = Cons(1, box Cons(2, box Cons(3, box Nil)));
let list: List<int> = List::Cons(1, box List::Cons(2, box List::Cons(3, box List::Nil)));
println!("{}", list);
}
```
Expand Down
40 changes: 20 additions & 20 deletions src/doc/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -1263,17 +1263,17 @@ enum OptionalInt {
}
fn main() {
let x = Value(5);
let y = Missing;
let x = OptionalInt::Value(5);
let y = OptionalInt::Missing;
match x {
Value(n) => println!("x is {}", n),
Missing => println!("x is missing!"),
OptionalInt::Value(n) => println!("x is {}", n),
OptionalInt::Missing => println!("x is missing!"),
}
match y {
Value(n) => println!("y is {}", n),
Missing => println!("y is missing!"),
OptionalInt::Value(n) => println!("y is {}", n),
OptionalInt::Missing => println!("y is missing!"),
}
}
```
Expand Down Expand Up @@ -1702,17 +1702,17 @@ enum OptionalInt {
}
fn main() {
let x = Value(5);
let y = Missing;
let x = OptionalInt::Value(5);
let y = OptionalInt::Missing;
match x {
Value(n) => println!("x is {}", n),
Missing => println!("x is missing!"),
OptionalInt::Value(n) => println!("x is {}", n),
OptionalInt::Missing => println!("x is missing!"),
}
match y {
Value(n) => println!("y is {}", n),
Missing => println!("y is missing!"),
OptionalInt::Value(n) => println!("y is {}", n),
OptionalInt::Missing => println!("y is missing!"),
}
}
```
Expand Down Expand Up @@ -3709,7 +3709,7 @@ enum List {
}
fn main() {
let list = Node(0, box Node(1, box Nil));
let list = List::Node(0, box List::Node(1, box List::Nil));
}
```

Expand Down Expand Up @@ -3895,11 +3895,11 @@ enum OptionalInt {
Missing,
}
let x = Value(5i);
let x = OptionalInt::Value(5i);
match x {
Value(..) => println!("Got an int!"),
Missing => println!("No such luck."),
OptionalInt::Value(..) => println!("Got an int!"),
OptionalInt::Missing => println!("No such luck."),
}
```

Expand All @@ -3911,12 +3911,12 @@ enum OptionalInt {
Missing,
}
let x = Value(5i);
let x = OptionalInt::Value(5i);
match x {
Value(i) if i > 5 => println!("Got an int bigger than five!"),
Value(..) => println!("Got an int!"),
Missing => println!("No such luck."),
OptionalInt::Value(i) if i > 5 => println!("Got an int bigger than five!"),
OptionalInt::Value(..) => println!("Got an int!"),
OptionalInt::Missing => println!("No such luck."),
}
```

Expand Down
34 changes: 17 additions & 17 deletions src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1331,8 +1331,8 @@ enum Animal {
Cat
}
let mut a: Animal = Dog;
a = Cat;
let mut a: Animal = Animal::Dog;
a = Animal::Cat;
```

Enumeration constructors can have either named or unnamed fields:
Expand All @@ -1345,8 +1345,8 @@ enum Animal {
Cat { name: String, weight: f64 }
}
let mut a: Animal = Dog("Cocoa".to_string(), 37.2);
a = Cat { name: "Spotty".to_string(), weight: 2.7 };
let mut a: Animal = Animal::Dog("Cocoa".to_string(), 37.2);
a = Animal::Cat { name: "Spotty".to_string(), weight: 2.7 };
# }
```

Expand Down Expand Up @@ -3308,12 +3308,12 @@ fields of a particular variant. For example:
```
enum List<X> { Nil, Cons(X, Box<List<X>>) }
let x: List<int> = Cons(10, box Cons(11, box Nil));
let x: List<int> = List::Cons(10, box List::Cons(11, box List::Nil));
match x {
Cons(_, box Nil) => panic!("singleton list"),
Cons(..) => return,
Nil => panic!("empty list")
List::Cons(_, box List::Nil) => panic!("singleton list"),
List::Cons(..) => return,
List::Nil => panic!("empty list")
}
```

Expand Down Expand Up @@ -3371,16 +3371,16 @@ An example of a `match` expression:
enum List<X> { Nil, Cons(X, Box<List<X>>) }
let x: List<int> = Cons(10, box Cons(11, box Nil));
let x: List<int> = List::Cons(10, box List::Cons(11, box List::Nil));
match x {
Cons(a, box Cons(b, _)) => {
List::Cons(a, box List::Cons(b, _)) => {
process_pair(a, b);
}
Cons(10, _) => {
List::Cons(10, _) => {
process_ten();
}
Nil => {
List::Nil => {
return;
}
_ => {
Expand All @@ -3402,18 +3402,18 @@ enum List { Nil, Cons(uint, Box<List>) }
fn is_sorted(list: &List) -> bool {
match *list {
Nil | Cons(_, box Nil) => true,
Cons(x, ref r @ box Cons(_, _)) => {
List::Nil | List::Cons(_, box List::Nil) => true,
List::Cons(x, ref r @ box List::Cons(_, _)) => {
match *r {
box Cons(y, _) => (x <= y) && is_sorted(&**r),
box List::Cons(y, _) => (x <= y) && is_sorted(&**r),
_ => panic!()
}
}
}
}
fn main() {
let a = Cons(6, box Cons(7, box Cons(42, box Nil)));
let a = List::Cons(6, box List::Cons(7, box List::Cons(42, box List::Nil)));
assert!(is_sorted(&a));
}
Expand Down Expand Up @@ -3718,7 +3718,7 @@ enum List<T> {
Cons(T, Box<List<T>>)
}
let a: List<int> = Cons(7, box Cons(13, box Nil));
let a: List<int> = List::Cons(7, box List::Cons(13, box List::Nil));
```

### Pointer types
Expand Down
1 change: 1 addition & 0 deletions src/etc/unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ def emit_conversions_module(f, lowerupper, upperlower):
def emit_grapheme_module(f, grapheme_table, grapheme_cats):
f.write("""pub mod grapheme {
use core::slice::SlicePrelude;
pub use self::GraphemeCat::*;
use core::slice;
#[allow(non_camel_case_types)]
Expand Down
4 changes: 4 additions & 0 deletions src/libcollections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
// writing (August 2014) freely licensed under the following Creative Commons Attribution
// License: [CC BY 2.5 CA](http://creativecommons.org/licenses/by/2.5/ca/).

pub use self::Entry::*;

use core::prelude::*;

use self::StackOp::*;
use super::node::*;
use std::hash::{Writer, Hash};
use core::default::Default;
Expand Down Expand Up @@ -445,6 +448,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// to nodes. By using this module much better safety guarantees can be made, and more search
/// boilerplate gets cut out.
mod stack {
pub use self::PushResult::*;
use core::prelude::*;
use super::BTreeMap;
use super::super::node::*;
Expand Down
4 changes: 4 additions & 0 deletions src/libcollections/btree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
// This module represents all the internal representation and logic for a B-Tree's node
// with a safe interface, so that BTreeMap itself does not depend on any of these details.

pub use self::InsertionResult::*;
pub use self::SearchResult::*;
pub use self::TraversalItem::*;

use core::prelude::*;

use core::{slice, mem, ptr};
Expand Down
Loading

4 comments on commit 7a87302

@bors
Copy link
Contributor

@bors bors commented on 7a87302 Nov 17, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pcwalton
at sfackler@7a87302

@bors
Copy link
Contributor

@bors bors commented on 7a87302 Nov 17, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging sfackler/rust/enum-namespace-pt2 = 7a87302 into auto

@bors
Copy link
Contributor

@bors bors commented on 7a87302 Nov 17, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sfackler/rust/enum-namespace-pt2 = 7a87302 merged ok, testing candidate = ccd6403f

@bors
Copy link
Contributor

@bors bors commented on 7a87302 Nov 17, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.