Skip to content

Commit 0dd0925

Browse files
committed
Tidying up and reformatting
1 parent a547962 commit 0dd0925

File tree

5 files changed

+154
-116
lines changed

5 files changed

+154
-116
lines changed

src/librustc/middle/def.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub enum Def {
6565
/// <T as Trait>::AssocX::AssocY::MethodOrAssocType
6666
/// ^~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~
6767
/// base_def depth = 2
68-
#[derive(Copy, Debug)]
68+
#[derive(Copy, Clone, Debug)]
6969
pub struct PathResolution {
7070
pub base_def: Def,
7171
pub last_private: LastPrivate,
@@ -85,6 +85,17 @@ impl PathResolution {
8585
pub fn def_id(&self) -> ast::DefId {
8686
self.full_def().def_id()
8787
}
88+
89+
pub fn new(base_def: Def,
90+
last_private: LastPrivate,
91+
depth: usize)
92+
-> PathResolution {
93+
PathResolution {
94+
base_def: base_def,
95+
last_private: last_private,
96+
depth: depth,
97+
}
98+
}
8899
}
89100

90101
// Definition mapping

src/librustc/middle/privacy.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub type ExternalExports = DefIdSet;
3232
/// reexporting a public struct doesn't inline the doc).
3333
pub type PublicItems = NodeSet;
3434

35-
#[derive(Copy, Debug)]
35+
#[derive(Copy, Clone, Debug)]
3636
pub enum LastPrivate {
3737
LastMod(PrivateDep),
3838
// `use` directives (imports) can refer to two separate definitions in the
@@ -46,14 +46,14 @@ pub enum LastPrivate {
4646
type_used: ImportUse},
4747
}
4848

49-
#[derive(Copy, Debug)]
49+
#[derive(Copy, Clone, Debug)]
5050
pub enum PrivateDep {
5151
AllPublic,
5252
DependsOn(ast::DefId),
5353
}
5454

5555
// How an import is used.
56-
#[derive(Copy, PartialEq, Debug)]
56+
#[derive(Copy, Clone, PartialEq, Debug)]
5757
pub enum ImportUse {
5858
Unused, // The import is not used.
5959
Used, // The import is used.

src/librustc_resolve/lib.rs

+41-53
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,12 @@ impl NamespaceResult {
162162
}
163163

164164
enum NameDefinition {
165-
NoNameDefinition, //< The name was unbound.
166-
ChildNameDefinition(Def, LastPrivate), //< The name identifies an immediate child.
167-
ImportNameDefinition(Def, LastPrivate) //< The name identifies an import.
165+
// The name was unbound.
166+
NoNameDefinition,
167+
// The name identifies an immediate child.
168+
ChildNameDefinition(Def, LastPrivate),
169+
// The name identifies an import.
170+
ImportNameDefinition(Def, LastPrivate),
168171
}
169172

170173
impl<'a, 'v, 'tcx> Visitor<'v> for Resolver<'a, 'tcx> {
@@ -795,11 +798,6 @@ pub struct Resolver<'a, 'tcx:'a> {
795798
// The current self type if inside an impl (used for better errors).
796799
current_self_type: Option<Ty>,
797800

798-
// The ident for the keyword "self".
799-
self_name: Name,
800-
// The ident for the non-keyword "Self".
801-
type_self_name: Name,
802-
803801
// The idents for the primitive types.
804802
primitive_type_table: PrimitiveTypeTable,
805803

@@ -869,9 +867,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
869867
current_trait_ref: None,
870868
current_self_type: None,
871869

872-
self_name: special_names::self_,
873-
type_self_name: special_names::type_self,
874-
875870
primitive_type_table: PrimitiveTypeTable::new(),
876871

877872
def_map: RefCell::new(NodeMap()),
@@ -1822,7 +1817,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
18221817
let mut self_type_rib = Rib::new(ItemRibKind);
18231818

18241819
// plain insert (no renaming, types are not currently hygienic....)
1825-
let name = self.type_self_name;
1820+
let name = special_names::type_self;
18261821
self_type_rib.bindings.insert(name, DlDef(DefSelfTy(item.id)));
18271822
self.type_ribs.push(self_type_rib);
18281823

@@ -2047,8 +2042,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
20472042

20482043
fn with_optional_trait_ref<T, F>(&mut self,
20492044
opt_trait_ref: Option<&TraitRef>,
2050-
f: F) -> T where
2051-
F: FnOnce(&mut Resolver) -> T,
2045+
f: F)
2046+
-> T
2047+
where F: FnOnce(&mut Resolver) -> T,
20522048
{
20532049
let mut new_val = None;
20542050
if let Some(trait_ref) = opt_trait_ref {
@@ -2585,11 +2581,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
25852581
let span = path.span;
25862582
let segments = &path.segments[..path.segments.len()-path_depth];
25872583

2588-
let mk_res = |(def, lp)| PathResolution {
2589-
base_def: def,
2590-
last_private: lp,
2591-
depth: path_depth
2592-
};
2584+
let mk_res = |(def, lp)| PathResolution::new(def, lp, path_depth);
25932585

25942586
if path.global {
25952587
let def = self.resolve_crate_relative_path(span, segments, namespace);
@@ -2603,25 +2595,25 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
26032595
check_ribs,
26042596
span);
26052597

2606-
if segments.len() > 1 {
2607-
let def = self.resolve_module_relative_path(span, segments, namespace);
2608-
match (def, unqualified_def) {
2609-
(Some((ref d, _)), Some((ref ud, _))) if *d == *ud => {
2610-
self.session
2611-
.add_lint(lint::builtin::UNUSED_QUALIFICATIONS,
2612-
id, span,
2613-
"unnecessary qualification".to_string());
2614-
}
2615-
_ => ()
2616-
}
2598+
if segments.len() <= 1 {
2599+
return unqualified_def.map(mk_res);
2600+
}
26172601

2618-
def.map(mk_res)
2619-
} else {
2620-
unqualified_def.map(mk_res)
2602+
let def = self.resolve_module_relative_path(span, segments, namespace);
2603+
match (def, unqualified_def) {
2604+
(Some((ref d, _)), Some((ref ud, _))) if *d == *ud => {
2605+
self.session
2606+
.add_lint(lint::builtin::UNUSED_QUALIFICATIONS,
2607+
id, span,
2608+
"unnecessary qualification".to_string());
2609+
}
2610+
_ => {}
26212611
}
2612+
2613+
def.map(mk_res)
26222614
}
26232615

2624-
// resolve a single identifier (used as a varref)
2616+
// Resolve a single identifier.
26252617
fn resolve_identifier(&mut self,
26262618
identifier: Ident,
26272619
namespace: Namespace,
@@ -2662,8 +2654,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
26622654
match child_name_bindings.def_for_namespace(namespace) {
26632655
Some(def) => {
26642656
// Found it. Stop the search here.
2665-
let p = child_name_bindings.defined_in_public_namespace(
2666-
namespace);
2657+
let p = child_name_bindings.defined_in_public_namespace(namespace);
26672658
let lp = if p {LastMod(AllPublic)} else {
26682659
LastMod(DependsOn(def.def_id()))
26692660
};
@@ -2734,8 +2725,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
27342725

27352726
let containing_module;
27362727
let last_private;
2737-
let module = self.current_module.clone();
2738-
match self.resolve_module_path(module,
2728+
let current_module = self.current_module.clone();
2729+
match self.resolve_module_path(current_module,
27392730
&module_path[..],
27402731
UseLexicalScope,
27412732
span,
@@ -2858,8 +2849,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
28582849

28592850
match search_result {
28602851
Some(DlDef(def)) => {
2861-
debug!("(resolving path in local ribs) resolved `{}` to \
2862-
local: {:?}",
2852+
debug!("(resolving path in local ribs) resolved `{}` to local: {:?}",
28632853
token::get_ident(ident),
28642854
def);
28652855
Some(def)
@@ -2904,15 +2894,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
29042894
panic!("unexpected indeterminate result");
29052895
}
29062896
Failed(err) => {
2907-
match err {
2908-
Some((span, msg)) =>
2909-
self.resolve_error(span, &format!("failed to resolve. {}",
2910-
msg)),
2911-
None => ()
2912-
}
2913-
29142897
debug!("(resolving item path by identifier in lexical scope) \
29152898
failed to resolve {}", token::get_name(name));
2899+
2900+
if let Some((span, msg)) = err {
2901+
self.resolve_error(span, &format!("failed to resolve. {}", msg))
2902+
}
2903+
29162904
return None;
29172905
}
29182906
}
@@ -2964,10 +2952,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
29642952
}
29652953
} else {
29662954
match this.resolve_module_path(root,
2967-
&name_path[..],
2968-
UseLexicalScope,
2969-
span,
2970-
PathSearch) {
2955+
&name_path[..],
2956+
UseLexicalScope,
2957+
span,
2958+
PathSearch) {
29712959
Success((module, _)) => Some(module),
29722960
_ => None
29732961
}
@@ -3203,8 +3191,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
32033191
false // Stop advancing
32043192
});
32053193

3206-
if method_scope && &token::get_name(self.self_name)[..]
3207-
== path_name {
3194+
if method_scope &&
3195+
&token::get_name(special_names::self_)[..] == path_name {
32083196
self.resolve_error(
32093197
expr.span,
32103198
"`self` is not available \

0 commit comments

Comments
 (0)