Skip to content

Commit

Permalink
Utilize fewer reexports
Browse files Browse the repository at this point in the history
In regards to:

rust-lang#19253 (comment)

This commit:

* Changes the #deriving code so that it generates code that utilizes fewer
  reexports (in particur Option::* and Result::*), which is necessary to
  remove those reexports in the future
* Changes other areas of the codebase so that fewer reexports are utilized
  • Loading branch information
frewsxcv committed Nov 29, 2014
1 parent 6163581 commit 6614476
Show file tree
Hide file tree
Showing 85 changed files with 277 additions and 195 deletions.
6 changes: 3 additions & 3 deletions src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ An example of `use` declarations:

```
use std::iter::range_step;
use std::option::{Some, None};
use std::option::Option::{Some, None};
use std::collections::hash_map::{mod, HashMap};
fn foo<T>(_: T){}
Expand All @@ -1004,8 +1004,8 @@ fn main() {
// Equivalent to 'std::iter::range_step(0u, 10u, 2u);'
range_step(0u, 10u, 2u);
// Equivalent to 'foo(vec![std::option::Some(1.0f64),
// std::option::None]);'
// Equivalent to 'foo(vec![std::option::Option::Some(1.0f64),
// std::option::Option::None]);'
foo(vec![Some(1.0f64), None]);
// Both `hash_map` and `HashMap` are in scope.
Expand Down
16 changes: 9 additions & 7 deletions src/etc/unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def escape_char(c):
def emit_bsearch_range_table(f):
f.write("""
fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
use core::cmp::{Equal, Less, Greater};
use core::cmp::Ordering::{Equal, Less, Greater};
use core::slice::SlicePrelude;
r.binary_search(|&(lo,hi)| {
if lo <= c && c <= hi { Equal }
Expand Down Expand Up @@ -350,10 +350,11 @@ def emit_regex_module(f, cats, w_data):
def emit_conversions_module(f, lowerupper, upperlower):
f.write("pub mod conversions {")
f.write("""
use core::cmp::{Equal, Less, Greater};
use core::cmp::Ordering::{Equal, Less, Greater};
use core::slice::SlicePrelude;
use core::tuple::Tuple2;
use core::option::{Option, Some, None};
use core::option::Option;
use core::option::Option::{Some, None};
use core::slice;
pub fn to_lower(c: char) -> char {
Expand Down Expand Up @@ -403,7 +404,7 @@ def emit_grapheme_module(f, grapheme_table, grapheme_cats):
f.write(""" }
fn bsearch_range_value_table(c: char, r: &'static [(char, char, GraphemeCat)]) -> GraphemeCat {
use core::cmp::{Equal, Less, Greater};
use core::cmp::Ordering::{Equal, Less, Greater};
match r.binary_search(|&(lo, hi, _)| {
if lo <= c && c <= hi { Equal }
else if hi < c { Less }
Expand All @@ -430,12 +431,13 @@ def emit_grapheme_module(f, grapheme_table, grapheme_cats):

def emit_charwidth_module(f, width_table):
f.write("pub mod charwidth {\n")
f.write(" use core::option::{Option, Some, None};\n")
f.write(" use core::option::Option;\n")
f.write(" use core::option::Option::{Some, None};\n")
f.write(" use core::slice::SlicePrelude;\n")
f.write(" use core::slice;\n")
f.write("""
fn bsearch_range_value_table(c: char, is_cjk: bool, r: &'static [(char, char, u8, u8)]) -> u8 {
use core::cmp::{Equal, Less, Greater};
use core::cmp::Ordering::{Equal, Less, Greater};
match r.binary_search(|&(lo, hi, _, _)| {
if lo <= c && c <= hi { Equal }
else if hi < c { Less }
Expand Down Expand Up @@ -530,7 +532,7 @@ def comp_pfun(char):

f.write("""
fn bsearch_range_value_table(c: char, r: &'static [(char, char, u8)]) -> u8 {
use core::cmp::{Equal, Less, Greater};
use core::cmp::Ordering::{Equal, Less, Greater};
use core::slice::SlicePrelude;
use core::slice;
match r.binary_search(|&(lo, hi, _)| {
Expand Down
6 changes: 4 additions & 2 deletions src/liballoc/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ use core::kinds::{Sync, Send};
use core::mem::{min_align_of, size_of, drop};
use core::mem;
use core::ops::{Drop, Deref};
use core::option::{Some, None, Option};
use core::option::Option;
use core::option::Option::{Some, None};
use core::ptr::RawPtr;
use core::ptr;
use heap::deallocate;
Expand Down Expand Up @@ -326,7 +327,8 @@ mod tests {
use std::comm::channel;
use std::mem::drop;
use std::ops::Drop;
use std::option::{Option, Some, None};
use std::option::Option;
use std::option::Option::{Some, None};
use std::str::Str;
use std::sync::atomic;
use std::task;
Expand Down
3 changes: 2 additions & 1 deletion src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use core::kinds::Sized;
use core::mem;
use core::option::Option;
use core::raw::TraitObject;
use core::result::{Ok, Err, Result};
use core::result::Result;
use core::result::Result::{Ok, Err};

/// A value that represents the global exchange heap. This is the default
/// place that the `box` keyword allocates into when no place is supplied.
Expand Down
3 changes: 2 additions & 1 deletion src/liballoc/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ const MIN_ALIGN: uint = 16;

#[cfg(jemalloc)]
mod imp {
use core::option::{None, Option};
use core::option::Option;
use core::option::Option::None;
use core::ptr::{null_mut, null};
use core::num::Int;
use libc::{c_char, c_int, c_void, size_t};
Expand Down
11 changes: 7 additions & 4 deletions src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,12 @@ use core::fmt;
use core::kinds::marker;
use core::mem::{transmute, min_align_of, size_of, forget};
use core::ops::{Deref, Drop};
use core::option::{Option, Some, None};
use core::option::Option;
use core::option::Option::{Some, None};
use core::ptr;
use core::ptr::RawPtr;
use core::result::{Result, Ok, Err};
use core::result::Result;
use core::result::Result::{Ok, Err};

use heap::deallocate;

Expand Down Expand Up @@ -739,8 +741,9 @@ impl<T> RcBoxPtr<T> for Weak<T> {
mod tests {
use super::{Rc, Weak, weak_count, strong_count};
use std::cell::RefCell;
use std::option::{Option, Some, None};
use std::result::{Err, Ok};
use std::option::Option;
use std::option::Option::{Some, None};
use std::result::Result::{Err, Ok};
use std::mem::drop;
use std::clone::Clone;

Expand Down
6 changes: 4 additions & 2 deletions src/libcollections/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,8 +825,10 @@ mod tests {
use std::default::Default;
use std::char::Char;
use std::clone::Clone;
use std::cmp::{Equal, Greater, Less, Ord, PartialOrd, Equiv};
use std::option::{Some, None};
use std::cmp::{Ord, PartialOrd, Equiv};
use std::cmp::Ordering::{Equal, Greater, Less};
use std::option::Option;
use std::option::Option::{Some, None};
use std::ptr::RawPtr;
use std::iter::{Iterator, IteratorExt, DoubleEndedIteratorExt};

Expand Down
3 changes: 2 additions & 1 deletion src/libcore/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
#![stable]

use mem::{transmute};
use option::{Option, Some, None};
use option::Option;
use option::Option::{Some, None};
use raw::TraitObject;
use intrinsics::TypeId;

Expand Down
3 changes: 2 additions & 1 deletion src/libcore/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ use cmp::PartialEq;
use default::Default;
use kinds::{marker, Copy};
use ops::{Deref, DerefMut, Drop};
use option::{None, Option, Some};
use option::Option;
use option::Option::{None, Some};

/// A mutable memory location that admits only `Copy` data.
#[unstable = "likely to be renamed; otherwise stable"]
Expand Down
3 changes: 2 additions & 1 deletion src/libcore/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
#![doc(primitive = "char")]

use mem::transmute;
use option::{None, Option, Some};
use option::Option;
use option::Option::{None, Some};
use iter::{range_step, Iterator, RangeStep};
use slice::SlicePrelude;

Expand Down
10 changes: 6 additions & 4 deletions src/libcore/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
pub use self::Ordering::*;

use kinds::Sized;
use option::{Option, Some, None};
use option::Option;
use option::Option::{Some, None};

/// Trait for values that can be compared for equality and inequality.
///
Expand Down Expand Up @@ -288,10 +289,11 @@ pub fn partial_max<T: PartialOrd>(v1: T, v2: T) -> Option<T> {

// Implementation of PartialEq, Eq, PartialOrd and Ord for primitive types
mod impls {
use cmp::{PartialOrd, Ord, PartialEq, Eq, Ordering,
Less, Greater, Equal};
use cmp::{PartialOrd, Ord, PartialEq, Eq, Ordering};
use cmp::Ordering::{Less, Greater, Equal};
use kinds::Sized;
use option::{Option, Some, None};
use option::Option;
use option::Option::{Some, None};

macro_rules! partial_eq_impl(
($($t:ty)*) => ($(
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/fmt/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use fmt;
use iter::{range, DoubleEndedIteratorExt};
use num::{Float, FPNaN, FPInfinite, ToPrimitive};
use num::cast;
use result::Ok;
use result::Result::Ok;
use slice::{mod, SlicePrelude};
use str::StrPrelude;

Expand Down
5 changes: 3 additions & 2 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ use cell::{Cell, Ref, RefMut};
use iter::{Iterator, IteratorExt, range};
use kinds::{Copy, Sized};
use mem;
use option::{Option, Some, None};
use option::Option;
use option::Option::{Some, None};
use ops::Deref;
use result::{Ok, Err};
use result::Result::{Ok, Err};
use result;
use slice::SlicePrelude;
use slice;
Expand Down
23 changes: 13 additions & 10 deletions src/libcore/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ use cmp::Ord;
use mem;
use num::{ToPrimitive, Int};
use ops::{Add, Deref};
use option::{Option, Some, None};
use option::Option;
use option::Option::{Some, None};
use uint;

#[deprecated = "renamed to Extend"] pub use self::Extend as Extendable;
Expand Down Expand Up @@ -2427,7 +2428,9 @@ pub fn repeat<T: Clone>(elt: T) -> Repeat<T> {
pub mod order {
use cmp;
use cmp::{Eq, Ord, PartialOrd, PartialEq};
use option::{Option, Some, None};
use cmp::Ordering::{Equal, Less, Greater};
use option::Option;
use option::Option::{Some, None};
use super::Iterator;

/// Compare `a` and `b` for equality using `Eq`
Expand All @@ -2445,11 +2448,11 @@ pub mod order {
pub fn cmp<A: Ord, T: Iterator<A>, S: Iterator<A>>(mut a: T, mut b: S) -> cmp::Ordering {
loop {
match (a.next(), b.next()) {
(None, None) => return cmp::Equal,
(None, _ ) => return cmp::Less,
(_ , None) => return cmp::Greater,
(None, None) => return Equal,
(None, _ ) => return Less,
(_ , None) => return Greater,
(Some(x), Some(y)) => match x.cmp(&y) {
cmp::Equal => (),
Equal => (),
non_eq => return non_eq,
},
}
Expand All @@ -2461,11 +2464,11 @@ pub mod order {
-> Option<cmp::Ordering> {
loop {
match (a.next(), b.next()) {
(None, None) => return Some(cmp::Equal),
(None, _ ) => return Some(cmp::Less),
(_ , None) => return Some(cmp::Greater),
(None, None) => return Some(Equal),
(None, _ ) => return Some(Less),
(_ , None) => return Some(Greater),
(Some(x), Some(y)) => match x.partial_cmp(&y) {
Some(cmp::Equal) => (),
Some(Equal) => (),
non_eq => return non_eq,
},
}
Expand Down
3 changes: 2 additions & 1 deletion src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ use kinds::Copy;
use mem::size_of;
use ops::{Add, Sub, Mul, Div, Rem, Neg};
use ops::{Not, BitAnd, BitOr, BitXor, Shl, Shr};
use option::{Option, Some, None};
use option::Option;
use option::Option::{Some, None};
use str::{FromStr, from_str, StrPrelude};

/// Simultaneous division and remainder
Expand Down
3 changes: 2 additions & 1 deletion src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ use cmp::{Eq, Ord};
use default::Default;
use iter::{Iterator, IteratorExt, DoubleEndedIterator, FromIterator, ExactSizeIterator};
use mem;
use result::{Result, Ok, Err};
use result::Result;
use result::Result::{Ok, Err};
use slice;
use slice::AsSlice;
use clone::Clone;
Expand Down
7 changes: 5 additions & 2 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,12 @@
use mem;
use clone::Clone;
use intrinsics;
use option::{Some, None, Option};
use option::Option;
use option::Option::{Some, None};

use cmp::{PartialEq, Eq, PartialOrd, Equiv, Ordering, Less, Equal, Greater};
use cmp::{PartialEq, Eq, PartialOrd, Equiv};
use cmp::Ordering;
use cmp::Ordering::{Less, Equal, Greater};

pub use intrinsics::copy_memory;
pub use intrinsics::copy_nonoverlapping_memory;
Expand Down
3 changes: 2 additions & 1 deletion src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ use std::fmt::Show;
use slice;
use slice::AsSlice;
use iter::{Iterator, IteratorExt, DoubleEndedIterator, FromIterator, ExactSizeIterator};
use option::{None, Option, Some};
use option::Option;
use option::Option::{None, Some};

/// `Result` is a type that represents either success (`Ok`) or failure (`Err`).
///
Expand Down
9 changes: 6 additions & 3 deletions src/libcore/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@

use mem::transmute;
use clone::Clone;
use cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering, Less, Equal, Greater, Equiv};
use cmp::{Ordering, PartialEq, PartialOrd, Eq, Ord, Equiv};
use cmp::Ordering::{Less, Equal, Greater};
use cmp;
use default::Default;
use iter::*;
use num::Int;
use ops;
use option::{None, Option, Some};
use option::Option;
use option::Option::{None, Some};
use ptr;
use ptr::RawPtr;
use mem;
Expand Down Expand Up @@ -1702,7 +1704,8 @@ pub mod raw {
use mem::transmute;
use ptr::RawPtr;
use raw::Slice;
use option::{None, Option, Some};
use option::Option;
use option::Option::{None, Some};

/// Form a slice from a pointer and length (as a number of units,
/// not bytes).
Expand Down
9 changes: 6 additions & 3 deletions src/libcore/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ use iter::range;
use kinds::Sized;
use mem;
use num::Int;
use option::{Option, None, Some};
use option::Option;
use option::Option::{None, Some};
use ptr::RawPtr;
use raw::{Repr, Slice};
use slice::{mod, SlicePrelude};
Expand Down Expand Up @@ -1209,9 +1210,11 @@ Section: Trait implementations

#[allow(missing_docs)]
pub mod traits {
use cmp::{Ord, Ordering, Less, Equal, Greater, PartialEq, PartialOrd, Equiv, Eq};
use cmp::{Ordering, Ord, PartialEq, PartialOrd, Equiv, Eq};
use cmp::Ordering::{Less, Equal, Greater};
use iter::IteratorExt;
use option::{Option, Some};
use option::Option;
use option::Option::Some;
use ops;
use str::{Str, StrPrelude, eq_slice};

Expand Down
3 changes: 2 additions & 1 deletion src/libcore/tuple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ pub use unit;
use clone::Clone;
use cmp::*;
use default::Default;
use option::{Option, Some};
use option::Option;
use option::Option::Some;

// macro for implementing n-ary tuple functions and operations
macro_rules! tuple_impls {
Expand Down
Loading

6 comments on commit 6614476

@sfackler
Copy link

Choose a reason for hiding this comment

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

r+

@Gankra
Copy link

@Gankra Gankra commented on 6614476 Nov 30, 2014

Choose a reason for hiding this comment

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

@bors: retry

@frewsxcv
Copy link
Owner Author

Choose a reason for hiding this comment

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

@Gankra
Copy link

@Gankra Gankra commented on 6614476 Nov 30, 2014

Choose a reason for hiding this comment

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

@bors: retry

@frewsxcv
Copy link
Owner Author

Choose a reason for hiding this comment

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

Got the same error again...not sure what to do at this point...

@Gankra
Copy link

@Gankra Gankra commented on 6614476 Nov 30, 2014

Choose a reason for hiding this comment

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

It's not unheard-of to get multiple spurious errors (statistics and all that), but I thought the build had gotten more stable than that again. But maybe this patch exacerbates it?

Edit: oh whoops, just saw Alex's explanation

Please sign in to comment.