Skip to content

Commit 44eca60

Browse files
committed
auto merge of #16482 : pcwalton/rust/resolve-shadowing, r=brson
declared with the same name in the same scope. This breaks several common patterns. First are unused imports: use foo::bar; use baz::bar; Change this code to the following: use baz::bar; Second, this patch breaks globs that import names that are shadowed by subsequent imports. For example: use foo::*; // including `bar` use baz::bar; Change this code to remove the glob: use foo::{boo, quux}; use baz::bar; Or qualify all uses of `bar`: use foo::{boo, quux}; use baz; ... baz::bar ... Finally, this patch breaks code that, at top level, explicitly imports `std` and doesn't disable the prelude. extern crate std; Because the prelude imports `std` implicitly, there is no need to explicitly import it; just remove such directives. The old behavior can be opted into via the `import_shadowing` feature gate. Use of this feature gate is discouraged. This implements RFC #116. Closes #16464. [breaking-change] r? @brson
2 parents 85fd37f + f3bd29a commit 44eca60

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+579
-433
lines changed

src/doc/guide-unsafe.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -537,11 +537,12 @@ extern crate core;
537537
use core::prelude::*;
538538
539539
use core::mem;
540-
use core::raw::Slice;
541540
542541
#[no_mangle]
543542
pub extern fn dot_product(a: *const u32, a_len: u32,
544543
b: *const u32, b_len: u32) -> u32 {
544+
use core::raw::Slice;
545+
545546
// Convert the provided arrays into Rust slices.
546547
// The core::raw module guarantees that the Slice
547548
// structure has the same memory layout as a &[T]

src/libcollections/bitv.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,11 @@ use core::default::Default;
6868
use core::fmt;
6969
use core::iter::Take;
7070
use core::iter;
71-
use core::ops::Index;
7271
use core::slice;
7372
use core::uint;
7473
use std::hash;
7574

76-
use {Collection, Mutable, Set, MutableSet, MutableSeq};
75+
use {Mutable, Set, MutableSet, MutableSeq};
7776
use vec::Vec;
7877

7978

src/libcollections/btree.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use alloc::boxed::Box;
2424
use core::fmt;
2525
use core::fmt::Show;
2626

27-
use {Collection, MutableSeq};
27+
use MutableSeq;
2828
use vec::Vec;
2929

3030
#[allow(missing_doc)]

src/libcollections/dlist.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use core::mem;
3131
use core::ptr;
3232
use std::hash::{Writer, Hash};
3333

34-
use {Collection, Mutable, Deque, MutableSeq};
34+
use {Mutable, Deque, MutableSeq};
3535

3636
/// A doubly-linked list.
3737
pub struct DList<T> {

src/libcollections/lib.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@
2222
html_playground_url = "http://play.rust-lang.org/")]
2323

2424
#![feature(macro_rules, managed_boxes, default_type_params, phase, globs)]
25-
#![feature(unsafe_destructor)]
25+
#![feature(unsafe_destructor, import_shadowing)]
2626
#![no_std]
2727

28+
// NOTE(stage0, pcwalton): Remove after snapshot.
29+
#![allow(unknown_features)]
30+
2831
#[phase(plugin, link)] extern crate core;
2932
extern crate unicode;
3033
extern crate alloc;
@@ -36,11 +39,11 @@ extern crate alloc;
3639
#[cfg(test)] #[phase(plugin, link)] extern crate std;
3740
#[cfg(test)] #[phase(plugin, link)] extern crate log;
3841

39-
use core::prelude::*;
42+
use core::prelude::Option;
4043

41-
pub use core::collections::Collection;
4244
pub use bitv::{Bitv, BitvSet};
4345
pub use btree::BTree;
46+
pub use core::prelude::Collection;
4447
pub use dlist::DList;
4548
pub use enum_set::EnumSet;
4649
pub use priority_queue::PriorityQueue;

src/libcollections/priority_queue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ use core::default::Default;
154154
use core::mem::{zeroed, replace, swap};
155155
use core::ptr;
156156

157-
use {Collection, Mutable, MutableSeq};
157+
use {Mutable, MutableSeq};
158158
use slice;
159159
use vec::Vec;
160160

src/libcollections/ringbuf.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ use core::prelude::*;
1818
use core::cmp;
1919
use core::default::Default;
2020
use core::fmt;
21-
use core::iter::RandomAccessIterator;
2221
use core::iter;
2322
use std::hash::{Writer, Hash};
2423

25-
use {Deque, Collection, Mutable, MutableSeq};
24+
use {Deque, Mutable, MutableSeq};
2625
use vec::Vec;
2726

2827
static INITIAL_CAPACITY: uint = 8u; // 2^3

src/libcollections/slice.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,22 @@ for &x in numbers.iter() {
8686

8787
#![doc(primitive = "slice")]
8888

89-
use core::prelude::*;
90-
9189
use core::cmp;
9290
use core::mem::size_of;
9391
use core::mem;
92+
use core::prelude::{Clone, Collection, Greater, Iterator, Less, None, Option};
93+
use core::prelude::{Ord, Ordering, RawPtr, Some, range};
9494
use core::ptr;
9595
use core::iter::{range_step, MultiplicativeIterator};
9696

97-
use {Collection, MutableSeq};
97+
use MutableSeq;
9898
use vec::Vec;
9999

100-
pub use core::slice::{ref_slice, mut_ref_slice, Splits, Windows};
101100
pub use core::slice::{Chunks, Slice, ImmutableSlice, ImmutablePartialEqSlice};
102101
pub use core::slice::{ImmutableOrdSlice, MutableSlice, Items, MutItems};
103-
pub use core::slice::{MutSplits, MutChunks};
104-
pub use core::slice::{bytes, MutableCloneableSlice};
105-
pub use core::slice::{BinarySearchResult, Found, NotFound};
102+
pub use core::slice::{MutSplits, MutChunks, Splits};
103+
pub use core::slice::{bytes, ref_slice, MutableCloneableSlice};
104+
pub use core::slice::{Found, NotFound};
106105

107106
// Functional utilities
108107

src/libcollections/smallintmap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use core::iter;
2121
use core::iter::{Enumerate, FilterMap};
2222
use core::mem::replace;
2323

24-
use {Collection, Mutable, Map, MutableMap, MutableSeq};
24+
use {Mutable, Map, MutableMap, MutableSeq};
2525
use {vec, slice};
2626
use vec::Vec;
2727
use hash;

src/libcollections/str.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,17 @@ is the same as `&[u8]`.
6969

7070
#![doc(primitive = "str")]
7171

72-
use core::prelude::*;
73-
7472
use core::default::Default;
7573
use core::fmt;
7674
use core::cmp;
7775
use core::iter::AdditiveIterator;
7876
use core::mem;
77+
use core::prelude::{Char, Clone, Collection, Eq, Equiv, ImmutableSlice};
78+
use core::prelude::{Iterator, MutableSlice, None, Option, Ord, Ordering};
79+
use core::prelude::{PartialEq, PartialOrd, Result, Slice, Some, Tuple2};
80+
use core::prelude::{range};
7981

80-
use {Collection, Deque, MutableSeq};
82+
use {Deque, MutableSeq};
8183
use hash;
8284
use ringbuf::RingBuf;
8385
use string::String;

src/libcollections/string.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ use core::mem;
2020
use core::ptr;
2121
// FIXME: ICE's abound if you import the `Slice` type while importing `Slice` trait
2222
use RawSlice = core::raw::Slice;
23-
use core::slice::Slice;
2423

25-
use {Collection, Mutable, MutableSeq};
24+
use {Mutable, MutableSeq};
2625
use hash;
2726
use str;
2827
use str::{CharRange, StrAllocating, MaybeOwned, Owned};

src/libcollections/treemap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use core::mem::{replace, swap};
4040
use core::ptr;
4141
use std::hash::{Writer, Hash};
4242

43-
use {Collection, Mutable, Set, MutableSet, MutableMap, Map, MutableSeq};
43+
use {Mutable, Set, MutableSet, MutableMap, Map, MutableSeq};
4444
use vec::Vec;
4545

4646
/// This is implemented as an AA tree, which is a simplified variation of

src/libcollections/trie.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use core::uint;
2323
use core::iter;
2424
use std::hash::{Writer, Hash};
2525

26-
use {Collection, Mutable, Map, MutableMap, Set, MutableSet};
26+
use {Mutable, Map, MutableMap, Set, MutableSet};
2727
use slice::{Items, MutItems};
2828
use slice;
2929

src/libcollections/vec.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,15 @@ use core::prelude::*;
1414

1515
use alloc::heap::{allocate, reallocate, deallocate};
1616
use RawSlice = core::raw::Slice;
17-
use core::slice::Slice;
1817
use core::cmp::max;
1918
use core::default::Default;
2019
use core::fmt;
2120
use core::mem;
22-
use core::num::{CheckedMul, CheckedAdd};
2321
use core::num;
2422
use core::ptr;
2523
use core::uint;
2624

27-
use {Collection, Mutable, MutableSeq};
25+
use {Mutable, MutableSeq};
2826
use slice::{MutableOrdSlice, MutableSliceAllocating, CloneableVector};
2927
use slice::{Items, MutItems};
3028

src/libcore/fmt/mod.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@
1414

1515
use any;
1616
use cell::{Cell, Ref, RefMut};
17-
use char::Char;
1817
use collections::Collection;
1918
use iter::{Iterator, range};
2019
use kinds::Copy;
2120
use mem;
22-
use num::Float;
2321
use option::{Option, Some, None};
2422
use ops::Deref;
2523
use result::{Ok, Err};
@@ -342,8 +340,12 @@ impl<'a> Formatter<'a> {
342340
///
343341
/// This function will correctly account for the flags provided as well as
344342
/// the minimum width. It will not take precision into account.
345-
pub fn pad_integral(&mut self, is_positive: bool, prefix: &str,
346-
buf: &[u8]) -> Result {
343+
pub fn pad_integral(&mut self,
344+
is_positive: bool,
345+
prefix: &str,
346+
buf: &[u8])
347+
-> Result {
348+
use char::Char;
347349
use fmt::rt::{FlagAlternate, FlagSignPlus, FlagSignAwareZeroPad};
348350

349351
let mut width = buf.len();
@@ -456,6 +458,7 @@ impl<'a> Formatter<'a> {
456458
padding: uint,
457459
default: rt::Alignment,
458460
f: |&mut Formatter| -> Result) -> Result {
461+
use char::Char;
459462
let align = match self.align {
460463
rt::AlignUnknown => default,
461464
rt::AlignLeft | rt::AlignRight => self.align
@@ -539,6 +542,8 @@ impl<'a, T: str::Str> String for T {
539542

540543
impl Char for char {
541544
fn fmt(&self, f: &mut Formatter) -> Result {
545+
use char::Char;
546+
542547
let mut utf8 = [0u8, ..4];
543548
let amt = self.encode_utf8(utf8);
544549
let s: &str = unsafe { mem::transmute(utf8.slice_to(amt)) };
@@ -571,7 +576,7 @@ impl<'a, T> Pointer for &'a mut T {
571576
macro_rules! floating(($ty:ident) => {
572577
impl Float for $ty {
573578
fn fmt(&self, fmt: &mut Formatter) -> Result {
574-
use num::Signed;
579+
use num::{Float, Signed};
575580

576581
let digits = match fmt.precision {
577582
Some(i) => float::DigExact(i),
@@ -592,7 +597,7 @@ macro_rules! floating(($ty:ident) => {
592597

593598
impl LowerExp for $ty {
594599
fn fmt(&self, fmt: &mut Formatter) -> Result {
595-
use num::Signed;
600+
use num::{Float, Signed};
596601

597602
let digits = match fmt.precision {
598603
Some(i) => float::DigExact(i),
@@ -613,7 +618,7 @@ macro_rules! floating(($ty:ident) => {
613618

614619
impl UpperExp for $ty {
615620
fn fmt(&self, fmt: &mut Formatter) -> Result {
616-
use num::Signed;
621+
use num::{Float, Signed};
617622

618623
let digits = match fmt.precision {
619624
Some(i) => float::DigExact(i),

src/libfmt_macros/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
#![license = "MIT/ASL2"]
2020
#![crate_type = "rlib"]
2121
#![crate_type = "dylib"]
22-
#![feature(macro_rules, globs)]
22+
#![feature(macro_rules, globs, import_shadowing)]
23+
24+
// NOTE(stage0, pcwalton): Remove after snapshot.
25+
#![allow(unknown_features)]
2326

2427
use std::char;
2528
use std::str;

src/libgetopts/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,12 @@
8888
html_root_url = "http://doc.rust-lang.org/master/",
8989
html_playground_url = "http://play.rust-lang.org/")]
9090
#![feature(globs, phase)]
91+
#![feature(import_shadowing)]
9192
#![deny(missing_doc)]
9293

94+
// NOTE(stage0, pcwalton): Remove after snapshot.
95+
#![allow(unknown_features)]
96+
9397
#[cfg(test)] extern crate debug;
9498
#[cfg(test)] #[phase(plugin, link)] extern crate log;
9599

src/liblibc/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ pub use funcs::bsd43::{shutdown};
226226
#[cfg(windows)] pub use consts::os::extra::{FILE_FLAG_BACKUP_SEMANTICS, INVALID_HANDLE_VALUE};
227227
#[cfg(windows)] pub use consts::os::extra::{MOVEFILE_REPLACE_EXISTING};
228228
#[cfg(windows)] pub use consts::os::extra::{GENERIC_READ, GENERIC_WRITE};
229-
#[cfg(windows)] pub use consts::os::extra::{VOLUME_NAME_DOS, FILE_ATTRIBUTE_NORMAL};
229+
#[cfg(windows)] pub use consts::os::extra::{VOLUME_NAME_DOS};
230230
#[cfg(windows)] pub use consts::os::extra::{PIPE_ACCESS_DUPLEX, FILE_FLAG_FIRST_PIPE_INSTANCE};
231231
#[cfg(windows)] pub use consts::os::extra::{FILE_FLAG_OVERLAPPED, PIPE_TYPE_BYTE};
232232
#[cfg(windows)] pub use consts::os::extra::{PIPE_READMODE_BYTE, PIPE_WAIT};
@@ -255,10 +255,10 @@ pub use funcs::bsd43::{shutdown};
255255
#[cfg(windows)] pub use funcs::extra::kernel32::{UnmapViewOfFile, CloseHandle};
256256
#[cfg(windows)] pub use funcs::extra::kernel32::{WaitForSingleObject, GetSystemTimeAsFileTime};
257257
#[cfg(windows)] pub use funcs::extra::kernel32::{QueryPerformanceCounter};
258-
#[cfg(windows)] pub use funcs::extra::kernel32::{WaitForSingleObject, QueryPerformanceFrequency};
258+
#[cfg(windows)] pub use funcs::extra::kernel32::{QueryPerformanceFrequency};
259259
#[cfg(windows)] pub use funcs::extra::kernel32::{GetExitCodeProcess, TerminateProcess};
260260
#[cfg(windows)] pub use funcs::extra::kernel32::{ReadFile, WriteFile, SetFilePointerEx};
261-
#[cfg(windows)] pub use funcs::extra::kernel32::{FlushFileBuffers, SetEndOfFile, CreateFileW};
261+
#[cfg(windows)] pub use funcs::extra::kernel32::{SetEndOfFile, CreateFileW};
262262
#[cfg(windows)] pub use funcs::extra::kernel32::{CreateDirectoryW, FindFirstFileW};
263263
#[cfg(windows)] pub use funcs::extra::kernel32::{FindNextFileW, FindClose, DeleteFileW};
264264
#[cfg(windows)] pub use funcs::extra::kernel32::{CreateHardLinkW, CreateEventW};

src/librand/distributions/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ that do not need to record state.
2424

2525
use core::prelude::*;
2626
use core::num;
27-
use core::num::CheckedAdd;
2827

2928
use {Rng, Rand};
3029

src/librand/distributions/range.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,11 @@ use distributions::{Sample, IndependentSample};
3535
/// # Example
3636
///
3737
/// ```rust
38-
/// use std::rand;
3938
/// use std::rand::distributions::{IndependentSample, Range};
4039
///
4140
/// fn main() {
4241
/// let between = Range::new(10u, 10000u);
43-
/// let mut rng = rand::task_rng();
42+
/// let mut rng = std::rand::task_rng();
4443
/// let mut sum = 0;
4544
/// for _ in range(0u, 1000) {
4645
/// sum += between.ind_sample(&mut rng);

src/librlibc/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@
2828
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
2929
html_root_url = "http://doc.rust-lang.org/master/")]
3030

31-
#![feature(intrinsics, phase)]
31+
#![feature(import_shadowing, intrinsics, phase)]
3232
#![no_std]
3333

3434
// This library defines the builtin functions, so it would be a shame for
3535
// LLVM to optimize these function calls to themselves!
3636
#![no_builtins]
3737

38+
// NOTE(stage0, pcwalton): Remove after snapshot.
39+
#![allow(unknown_features)]
40+
3841
#[cfg(test)] extern crate native;
3942
#[cfg(test)] extern crate test;
4043
#[cfg(test)] extern crate debug;

src/librustc/front/feature_gate.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
6868

6969
("rustc_diagnostic_macros", Active),
7070
("unboxed_closures", Active),
71+
("import_shadowing", Active),
7172

7273
// if you change this list without updating src/doc/rust.md, cmr will be sad
7374

@@ -98,7 +99,8 @@ pub struct Features {
9899
pub default_type_params: Cell<bool>,
99100
pub issue_5723_bootstrap: Cell<bool>,
100101
pub overloaded_calls: Cell<bool>,
101-
pub rustc_diagnostic_macros: Cell<bool>
102+
pub rustc_diagnostic_macros: Cell<bool>,
103+
pub import_shadowing: Cell<bool>,
102104
}
103105

104106
impl Features {
@@ -107,7 +109,8 @@ impl Features {
107109
default_type_params: Cell::new(false),
108110
issue_5723_bootstrap: Cell::new(false),
109111
overloaded_calls: Cell::new(false),
110-
rustc_diagnostic_macros: Cell::new(false)
112+
rustc_diagnostic_macros: Cell::new(false),
113+
import_shadowing: Cell::new(false),
111114
}
112115
}
113116
}
@@ -439,4 +442,6 @@ pub fn check_crate(sess: &Session, krate: &ast::Crate) {
439442
sess.features.issue_5723_bootstrap.set(cx.has_feature("issue_5723_bootstrap"));
440443
sess.features.overloaded_calls.set(cx.has_feature("overloaded_calls"));
441444
sess.features.rustc_diagnostic_macros.set(cx.has_feature("rustc_diagnostic_macros"));
445+
sess.features.import_shadowing.set(cx.has_feature("import_shadowing"));
442446
}
447+

0 commit comments

Comments
 (0)