Skip to content

Commit 806cb35

Browse files
committed
rollup merge of rust-lang#20289: nick29581/shadowing
r? eddyb
2 parents d7a09cb + 9dce83c commit 806cb35

26 files changed

+403
-195
lines changed

src/libcollections/slice.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,10 @@ pub mod raw {
13431343
#[cfg(test)]
13441344
mod tests {
13451345
use std::boxed::Box;
1346-
use prelude::*;
1346+
use prelude::{Some, None, range, Vec, ToString, Clone, Greater, Less, Equal};
1347+
use prelude::{SliceExt, Iterator, IteratorExt, DoubleEndedIteratorExt};
1348+
use prelude::{OrdSliceExt, CloneSliceExt, PartialEqSliceExt, AsSlice};
1349+
use prelude::{RandomAccessIterator, Ord, VectorVector};
13471350
use core::cell::Cell;
13481351
use core::default::Default;
13491352
use core::mem;

src/libcollections/str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3347,7 +3347,7 @@ mod tests {
33473347
#[cfg(test)]
33483348
mod bench {
33493349
use super::*;
3350-
use prelude::*;
3350+
use prelude::{SliceExt, IteratorExt, DoubleEndedIteratorExt};
33513351
use test::Bencher;
33523352
use test::black_box;
33533353

src/librustc_resolve/lib.rs

+103-107
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,6 @@ impl Rib {
345345
#[deriving(Show,PartialEq,Clone,Copy)]
346346
enum Shadowable {
347347
Always,
348-
/// Means that the recorded import obeys the glob shadowing rules, i.e., can
349-
/// only be shadowed by another glob import.
350-
Glob,
351348
Never
352349
}
353350

@@ -462,6 +459,22 @@ impl ImportResolution {
462459

463460
target.unwrap().shadowable
464461
}
462+
463+
fn set_target_and_id(&mut self,
464+
namespace: Namespace,
465+
target: Option<Target>,
466+
id: NodeId) {
467+
match namespace {
468+
TypeNS => {
469+
self.type_target = target;
470+
self.type_id = id;
471+
}
472+
ValueNS => {
473+
self.value_target = target;
474+
self.value_id = id;
475+
}
476+
}
477+
}
465478
}
466479

467480
/// The link from a module up to its nearest parent node.
@@ -1719,11 +1732,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
17191732
view_path.span,
17201733
id,
17211734
is_public,
1722-
if shadowable == Shadowable::Never {
1723-
Shadowable::Glob
1724-
} else {
1725-
shadowable
1726-
});
1735+
shadowable);
17271736
}
17281737
}
17291738
}
@@ -2712,64 +2721,45 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
27122721
// We've successfully resolved the import. Write the results in.
27132722
let mut import_resolutions = module_.import_resolutions.borrow_mut();
27142723
let import_resolution = &mut (*import_resolutions)[target];
2724+
{
2725+
let check_and_write_import = |namespace, result: &_, used_public: &mut bool| {
2726+
let namespace_name = match namespace {
2727+
TypeNS => "type",
2728+
ValueNS => "value",
2729+
};
27152730

2716-
match value_result {
2717-
BoundResult(ref target_module, ref name_bindings) => {
2718-
debug!("(resolving single import) found value target: {}",
2719-
{ name_bindings.value_def.borrow().clone().unwrap().def });
2720-
self.check_for_conflicting_import(
2721-
&import_resolution.value_target,
2722-
directive.span,
2723-
target,
2724-
ValueNS);
2725-
2726-
self.check_that_import_is_importable(
2727-
&**name_bindings,
2728-
directive.span,
2729-
target,
2730-
ValueNS);
2731-
2732-
import_resolution.value_target =
2733-
Some(Target::new(target_module.clone(),
2734-
name_bindings.clone(),
2735-
directive.shadowable));
2736-
import_resolution.value_id = directive.id;
2737-
import_resolution.is_public = directive.is_public;
2738-
value_used_public = name_bindings.defined_in_public_namespace(ValueNS);
2739-
}
2740-
UnboundResult => { /* Continue. */ }
2741-
UnknownResult => {
2742-
panic!("value result should be known at this point");
2743-
}
2744-
}
2745-
match type_result {
2746-
BoundResult(ref target_module, ref name_bindings) => {
2747-
debug!("(resolving single import) found type target: {}",
2748-
{ name_bindings.type_def.borrow().clone().unwrap().type_def });
2749-
self.check_for_conflicting_import(
2750-
&import_resolution.type_target,
2751-
directive.span,
2752-
target,
2753-
TypeNS);
2754-
2755-
self.check_that_import_is_importable(
2756-
&**name_bindings,
2757-
directive.span,
2758-
target,
2759-
TypeNS);
2760-
2761-
import_resolution.type_target =
2762-
Some(Target::new(target_module.clone(),
2763-
name_bindings.clone(),
2764-
directive.shadowable));
2765-
import_resolution.type_id = directive.id;
2766-
import_resolution.is_public = directive.is_public;
2767-
type_used_public = name_bindings.defined_in_public_namespace(TypeNS);
2768-
}
2769-
UnboundResult => { /* Continue. */ }
2770-
UnknownResult => {
2771-
panic!("type result should be known at this point");
2772-
}
2731+
match *result {
2732+
BoundResult(ref target_module, ref name_bindings) => {
2733+
debug!("(resolving single import) found {} target: {}",
2734+
namespace_name,
2735+
name_bindings.def_for_namespace(namespace));
2736+
self.check_for_conflicting_import(
2737+
&import_resolution.target_for_namespace(namespace),
2738+
directive.span,
2739+
target,
2740+
namespace);
2741+
2742+
self.check_that_import_is_importable(
2743+
&**name_bindings,
2744+
directive.span,
2745+
target,
2746+
namespace);
2747+
2748+
let target = Some(Target::new(target_module.clone(),
2749+
name_bindings.clone(),
2750+
directive.shadowable));
2751+
import_resolution.set_target_and_id(namespace, target, directive.id);
2752+
import_resolution.is_public = directive.is_public;
2753+
*used_public = name_bindings.defined_in_public_namespace(namespace);
2754+
}
2755+
UnboundResult => { /* Continue. */ }
2756+
UnknownResult => {
2757+
panic!("{} result should be known at this point", namespace_name);
2758+
}
2759+
}
2760+
};
2761+
check_and_write_import(ValueNS, &value_result, &mut value_used_public);
2762+
check_and_write_import(TypeNS, &type_result, &mut type_used_public);
27732763
}
27742764

27752765
self.check_for_conflicts_between_imports_and_items(
@@ -2825,7 +2815,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
28252815

28262816
// Resolves a glob import. Note that this function cannot fail; it either
28272817
// succeeds or bails out (as importing * from an empty module or a module
2828-
// that exports nothing is valid).
2818+
// that exports nothing is valid). containing_module is the module we are
2819+
// actually importing, i.e., `foo` in `use foo::*`.
28292820
fn resolve_glob_import(&mut self,
28302821
module_: &Module,
28312822
containing_module: Rc<Module>,
@@ -2851,12 +2842,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
28512842
assert_eq!(containing_module.glob_count.get(), 0);
28522843

28532844
// Add all resolved imports from the containing module.
2854-
let import_resolutions = containing_module.import_resolutions
2855-
.borrow();
2845+
let import_resolutions = containing_module.import_resolutions.borrow();
28562846
for (ident, target_import_resolution) in import_resolutions.iter() {
28572847
debug!("(resolving glob import) writing module resolution \
28582848
{} into `{}`",
2859-
target_import_resolution.type_target.is_none(),
2849+
token::get_name(*ident),
28602850
self.module_to_string(module_));
28612851

28622852
if !target_import_resolution.is_public {
@@ -2876,17 +2866,23 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
28762866
// Continue.
28772867
}
28782868
Some(ref value_target) => {
2879-
dest_import_resolution.value_target =
2880-
Some(value_target.clone());
2869+
self.check_for_conflicting_import(&dest_import_resolution.value_target,
2870+
import_directive.span,
2871+
*ident,
2872+
ValueNS);
2873+
dest_import_resolution.value_target = Some(value_target.clone());
28812874
}
28822875
}
28832876
match target_import_resolution.type_target {
28842877
None => {
28852878
// Continue.
28862879
}
28872880
Some(ref type_target) => {
2888-
dest_import_resolution.type_target =
2889-
Some(type_target.clone());
2881+
self.check_for_conflicting_import(&dest_import_resolution.type_target,
2882+
import_directive.span,
2883+
*ident,
2884+
TypeNS);
2885+
dest_import_resolution.type_target = Some(type_target.clone());
28902886
}
28912887
}
28922888
dest_import_resolution.is_public = is_public;
@@ -2908,8 +2904,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
29082904
// Add all children from the containing module.
29092905
self.populate_module_if_necessary(&containing_module);
29102906

2911-
for (&name, name_bindings) in containing_module.children
2912-
.borrow().iter() {
2907+
for (&name, name_bindings) in containing_module.children.borrow().iter() {
29132908
self.merge_import_resolution(module_,
29142909
containing_module.clone(),
29152910
import_directive,
@@ -2919,8 +2914,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
29192914
}
29202915

29212916
// Add external module children from the containing module.
2922-
for (&name, module) in containing_module.external_module_children
2923-
.borrow().iter() {
2917+
for (&name, module) in containing_module.external_module_children.borrow().iter() {
29242918
let name_bindings =
29252919
Rc::new(Resolver::create_name_bindings_from_module(module.clone()));
29262920
self.merge_import_resolution(module_,
@@ -2965,41 +2959,39 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
29652959

29662960
debug!("(resolving glob import) writing resolution `{}` in `{}` \
29672961
to `{}`",
2968-
token::get_name(name).get().to_string(),
2962+
token::get_name(name).get(),
29692963
self.module_to_string(&*containing_module),
29702964
self.module_to_string(module_));
29712965

29722966
// Merge the child item into the import resolution.
2973-
if name_bindings.defined_in_namespace_with(ValueNS, IMPORTABLE | PUBLIC) {
2974-
debug!("(resolving glob import) ... for value target");
2975-
if dest_import_resolution.shadowable(ValueNS) == Shadowable::Never {
2976-
let msg = format!("a value named `{}` has already been imported \
2977-
in this module",
2978-
token::get_name(name).get());
2979-
self.session.span_err(import_directive.span, msg.as_slice());
2980-
} else {
2981-
dest_import_resolution.value_target =
2982-
Some(Target::new(containing_module.clone(),
2983-
name_bindings.clone(),
2984-
import_directive.shadowable));
2985-
dest_import_resolution.value_id = id;
2986-
}
2987-
}
2988-
if name_bindings.defined_in_namespace_with(TypeNS, IMPORTABLE | PUBLIC) {
2989-
debug!("(resolving glob import) ... for type target");
2990-
if dest_import_resolution.shadowable(TypeNS) == Shadowable::Never {
2991-
let msg = format!("a type named `{}` has already been imported \
2992-
in this module",
2993-
token::get_name(name).get());
2994-
self.session.span_err(import_directive.span, msg.as_slice());
2995-
} else {
2996-
dest_import_resolution.type_target =
2997-
Some(Target::new(containing_module,
2998-
name_bindings.clone(),
2999-
import_directive.shadowable));
3000-
dest_import_resolution.type_id = id;
3001-
}
2967+
{
2968+
let merge_child_item = |namespace| {
2969+
if name_bindings.defined_in_namespace_with(namespace, IMPORTABLE | PUBLIC) {
2970+
let namespace_name = match namespace {
2971+
TypeNS => "type",
2972+
ValueNS => "value",
2973+
};
2974+
debug!("(resolving glob import) ... for {} target", namespace_name);
2975+
if dest_import_resolution.shadowable(namespace) == Shadowable::Never {
2976+
let msg = format!("a {} named `{}` has already been imported \
2977+
in this module",
2978+
namespace_name,
2979+
token::get_name(name).get());
2980+
self.session.span_err(import_directive.span, msg.as_slice());
2981+
} else {
2982+
let target = Target::new(containing_module.clone(),
2983+
name_bindings.clone(),
2984+
import_directive.shadowable);
2985+
dest_import_resolution.set_target_and_id(namespace,
2986+
Some(target),
2987+
id);
2988+
}
2989+
}
2990+
};
2991+
merge_child_item(ValueNS);
2992+
merge_child_item(TypeNS);
30022993
}
2994+
30032995
dest_import_resolution.is_public = is_public;
30042996

30052997
self.check_for_conflicts_between_imports_and_items(
@@ -3019,6 +3011,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
30193011
return
30203012
}
30213013

3014+
debug!("check_for_conflicting_import: {}; target exists: {}",
3015+
token::get_name(name).get(),
3016+
target.is_some());
3017+
30223018
match *target {
30233019
Some(ref target) if target.shadowable != Shadowable::Always => {
30243020
let msg = format!("a {} named `{}` has already been imported \

src/librustc_trans/trans/base.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1545,8 +1545,7 @@ pub fn arg_kind<'a, 'tcx>(cx: &FunctionContext<'a, 'tcx>, t: Ty<'tcx>)
15451545
}
15461546

15471547
// work around bizarre resolve errors
1548-
pub type RvalueDatum<'tcx> = datum::Datum<'tcx, datum::Rvalue>;
1549-
pub type LvalueDatum<'tcx> = datum::Datum<'tcx, datum::Lvalue>;
1548+
type RvalueDatum<'tcx> = datum::Datum<'tcx, datum::Rvalue>;
15501549

15511550
// create_datums_for_fn_args: creates rvalue datums for each of the
15521551
// incoming function arguments. These will later be stored into

src/librustc_trans/trans/common.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ pub fn validate_substs(substs: &Substs) {
190190
}
191191

192192
// work around bizarre resolve errors
193-
pub type RvalueDatum<'tcx> = datum::Datum<'tcx, datum::Rvalue>;
194-
pub type LvalueDatum<'tcx> = datum::Datum<'tcx, datum::Lvalue>;
193+
type RvalueDatum<'tcx> = datum::Datum<'tcx, datum::Rvalue>;
194+
type LvalueDatum<'tcx> = datum::Datum<'tcx, datum::Lvalue>;
195195

196196
// Function context. Every LLVM function we create will have one of
197197
// these.

src/libstd/c_str.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,8 @@ pub unsafe fn from_c_multistring<F>(buf: *const libc::c_char,
537537
#[cfg(test)]
538538
mod tests {
539539
use super::*;
540-
use prelude::*;
540+
use prelude::{spawn, Some, None, Option, FnOnce, ToString, CloneSliceExt};
541+
use prelude::{Clone, RawPtr, Iterator, SliceExt, StrExt};
541542
use ptr;
542543
use thread::Thread;
543544
use libc;

0 commit comments

Comments
 (0)