Skip to content

Commit be13211

Browse files
committed
Rollup merge of rust-lang#21626 - Ms2ger:various-cleanup, r=eddyb
2 parents ee0be3b + 7aa2735 commit be13211

File tree

10 files changed

+36
-61
lines changed

10 files changed

+36
-61
lines changed

src/librustc/metadata/csearch.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010

1111
// Searching for information from the cstore
1212

13-
#![allow(non_camel_case_types)]
14-
15-
pub use self::found_ast::*;
16-
1713
use metadata::common::*;
1814
use metadata::cstore;
1915
use metadata::decoder;
@@ -101,18 +97,18 @@ pub fn get_item_path(tcx: &ty::ctxt, def: ast::DefId) -> Vec<ast_map::PathElem>
10197
r
10298
}
10399

104-
pub enum found_ast<'ast> {
105-
found(&'ast ast::InlinedItem),
106-
found_parent(ast::DefId, &'ast ast::InlinedItem),
107-
not_found,
100+
pub enum FoundAst<'ast> {
101+
Found(&'ast ast::InlinedItem),
102+
FoundParent(ast::DefId, &'ast ast::InlinedItem),
103+
NotFound,
108104
}
109105

110106
// Finds the AST for this item in the crate metadata, if any. If the item was
111107
// not marked for inlining, then the AST will not be present and hence none
112108
// will be returned.
113109
pub fn maybe_get_item_ast<'tcx>(tcx: &ty::ctxt<'tcx>, def: ast::DefId,
114110
decode_inlined_item: decoder::DecodeInlinedItem)
115-
-> found_ast<'tcx> {
111+
-> FoundAst<'tcx> {
116112
let cstore = &tcx.sess.cstore;
117113
let cdata = cstore.get_crate_data(def.krate);
118114
decoder::maybe_get_item_ast(&*cdata, tcx, def.node, decode_inlined_item)

src/librustc/metadata/decoder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -693,23 +693,23 @@ pub type DecodeInlinedItem<'a> =
693693

694694
pub fn maybe_get_item_ast<'tcx>(cdata: Cmd, tcx: &ty::ctxt<'tcx>, id: ast::NodeId,
695695
mut decode_inlined_item: DecodeInlinedItem)
696-
-> csearch::found_ast<'tcx> {
696+
-> csearch::FoundAst<'tcx> {
697697
debug!("Looking up item: {}", id);
698698
let item_doc = lookup_item(id, cdata.data());
699699
let path = item_path(item_doc).init().to_vec();
700700
match decode_inlined_item(cdata, tcx, path, item_doc) {
701-
Ok(ii) => csearch::found(ii),
701+
Ok(ii) => csearch::FoundAst::Found(ii),
702702
Err(path) => {
703703
match item_parent_item(item_doc) {
704704
Some(did) => {
705705
let did = translate_def_id(cdata, did);
706706
let parent_item = lookup_item(did.node, cdata.data());
707707
match decode_inlined_item(cdata, tcx, path, parent_item) {
708-
Ok(ii) => csearch::found_parent(did, ii),
709-
Err(_) => csearch::not_found
708+
Ok(ii) => csearch::FoundAst::FoundParent(did, ii),
709+
Err(_) => csearch::FoundAst::NotFound
710710
}
711711
}
712-
None => csearch::not_found
712+
None => csearch::FoundAst::NotFound
713713
}
714714
}
715715
}

src/librustc/metadata/encoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,7 +1577,7 @@ fn encode_info_for_items(ecx: &EncodeContext,
15771577
&krate.module,
15781578
&[],
15791579
ast::CRATE_NODE_ID,
1580-
ast_map::Values([].iter()).chain(None),
1580+
[].iter().cloned().chain(None),
15811581
syntax::parse::token::special_idents::invalid,
15821582
ast::Public);
15831583

@@ -1949,7 +1949,7 @@ fn encode_misc_info(ecx: &EncodeContext,
19491949
}
19501950

19511951
// Encode reexports for the root module.
1952-
encode_reexports(ecx, rbml_w, 0, ast_map::Values([].iter()).chain(None));
1952+
encode_reexports(ecx, rbml_w, 0, [].iter().cloned().chain(None));
19531953

19541954
rbml_w.end_tag();
19551955
rbml_w.end_tag();

src/librustc/middle/astencode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub fn decode_inlined_item<'tcx>(cdata: &cstore::crate_metadata,
130130
debug!("> Decoding inlined fn: {:?}::?",
131131
{
132132
// Do an Option dance to use the path after it is moved below.
133-
let s = ast_map::path_to_string(ast_map::Values(path.iter()));
133+
let s = ast_map::path_to_string(path.iter().cloned());
134134
path_as_str = Some(s);
135135
path_as_str.as_ref().map(|x| &x[])
136136
});

src/librustc/middle/const_eval.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ fn lookup_variant_by_id<'a>(tcx: &'a ty::ctxt,
133133
}
134134
let expr_id = match csearch::maybe_get_item_ast(tcx, enum_def,
135135
box |a, b, c, d| astencode::decode_inlined_item(a, b, c, d)) {
136-
csearch::found(&ast::IIItem(ref item)) => match item.node {
136+
csearch::FoundAst::Found(&ast::IIItem(ref item)) => match item.node {
137137
ast::ItemEnum(ast::EnumDef { ref variants }, _) => {
138138
// NOTE this doesn't do the right thing, it compares inlined
139139
// NodeId's to the original variant_def's NodeId, but they
@@ -173,7 +173,7 @@ pub fn lookup_const_by_id<'a>(tcx: &'a ty::ctxt, def_id: ast::DefId)
173173
}
174174
let expr_id = match csearch::maybe_get_item_ast(tcx, def_id,
175175
box |a, b, c, d| astencode::decode_inlined_item(a, b, c, d)) {
176-
csearch::found(&ast::IIItem(ref item)) => match item.node {
176+
csearch::FoundAst::Found(&ast::IIItem(ref item)) => match item.node {
177177
ast::ItemConst(_, ref const_expr) => Some(const_expr.id),
178178
_ => None
179179
},

src/librustc/middle/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5264,7 +5264,7 @@ pub fn with_path<T, F>(cx: &ctxt, id: ast::DefId, f: F) -> T where
52645264
if id.krate == ast::LOCAL_CRATE {
52655265
cx.map.with_path(id.node, f)
52665266
} else {
5267-
f(ast_map::Values(csearch::get_item_path(cx, id).iter()).chain(None))
5267+
f(csearch::get_item_path(cx, id).iter().cloned().chain(None))
52685268
}
52695269
}
52705270

src/librustc_trans/back/link.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ use flate;
3737
use serialize::hex::ToHex;
3838
use syntax::ast;
3939
use syntax::ast_map::{PathElem, PathElems, PathName};
40-
use syntax::ast_map;
4140
use syntax::attr::AttrMetaMethods;
4241
use syntax::codemap::Span;
4342
use syntax::parse::token;
@@ -339,7 +338,7 @@ pub fn mangle_internal_name_by_type_and_seq<'a, 'tcx>(ccx: &CrateContext<'a, 'tc
339338
let path = [PathName(token::intern(&s[])),
340339
gensym_name(name)];
341340
let hash = get_symbol_hash(ccx, t);
342-
mangle(ast_map::Values(path.iter()), Some(&hash[]))
341+
mangle(path.iter().cloned(), Some(&hash[]))
343342
}
344343

345344
pub fn mangle_internal_name_by_path_and_seq(path: PathElems, flav: &str) -> String {

src/librustc_trans/trans/inline.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ fn instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
4343
box |a,b,c,d| astencode::decode_inlined_item(a, b, c, d));
4444

4545
let inline_def = match csearch_result {
46-
csearch::not_found => {
46+
csearch::FoundAst::NotFound => {
4747
ccx.external().borrow_mut().insert(fn_id, None);
4848
return None;
4949
}
50-
csearch::found(&ast::IIItem(ref item)) => {
50+
csearch::FoundAst::Found(&ast::IIItem(ref item)) => {
5151
ccx.external().borrow_mut().insert(fn_id, Some(item.id));
5252
ccx.external_srcs().borrow_mut().insert(item.id, fn_id);
5353

@@ -90,12 +90,12 @@ fn instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
9090

9191
local_def(item.id)
9292
}
93-
csearch::found(&ast::IIForeign(ref item)) => {
93+
csearch::FoundAst::Found(&ast::IIForeign(ref item)) => {
9494
ccx.external().borrow_mut().insert(fn_id, Some(item.id));
9595
ccx.external_srcs().borrow_mut().insert(item.id, fn_id);
9696
local_def(item.id)
9797
}
98-
csearch::found_parent(parent_id, &ast::IIItem(ref item)) => {
98+
csearch::FoundAst::FoundParent(parent_id, &ast::IIItem(ref item)) => {
9999
ccx.external().borrow_mut().insert(parent_id, Some(item.id));
100100
ccx.external_srcs().borrow_mut().insert(item.id, parent_id);
101101

@@ -124,11 +124,11 @@ fn instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
124124
trans_item(ccx, &**item);
125125
local_def(my_id)
126126
}
127-
csearch::found_parent(_, _) => {
128-
ccx.sess().bug("maybe_get_item_ast returned a found_parent \
127+
csearch::FoundAst::FoundParent(_, _) => {
128+
ccx.sess().bug("maybe_get_item_ast returned a FoundParent \
129129
with a non-item parent");
130130
}
131-
csearch::found(&ast::IITraitItem(_, ref trait_item)) => {
131+
csearch::FoundAst::Found(&ast::IITraitItem(_, ref trait_item)) => {
132132
match *trait_item {
133133
ast::RequiredMethod(_) => ccx.sess().bug("found RequiredMethod IITraitItem"),
134134
ast::ProvidedMethod(ref mth) => {
@@ -147,7 +147,7 @@ fn instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
147147
}
148148
}
149149
}
150-
csearch::found(&ast::IIImplItem(impl_did, ref impl_item)) => {
150+
csearch::FoundAst::Found(&ast::IIImplItem(impl_did, ref impl_item)) => {
151151
match *impl_item {
152152
ast::MethodImplItem(ref mth) => {
153153
ccx.external().borrow_mut().insert(fn_id, Some(mth.id));

src/libsyntax/ast_map/mod.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,8 @@ impl<'a> Iterator for LinkedPath<'a> {
7575
}
7676
}
7777

78-
// HACK(eddyb) move this into libstd (value wrapper for slice::Iter).
79-
#[derive(Clone)]
80-
pub struct Values<'a, T:'a>(pub slice::Iter<'a, T>);
81-
82-
impl<'a, T: Copy> Iterator for Values<'a, T> {
83-
type Item = T;
84-
85-
fn next(&mut self) -> Option<T> {
86-
let &mut Values(ref mut items) = self;
87-
items.next().map(|&x| x)
88-
}
89-
}
90-
9178
/// The type of the iterator used by with_path.
92-
pub type PathElems<'a, 'b> = iter::Chain<Values<'a, PathElem>, LinkedPath<'b>>;
79+
pub type PathElems<'a, 'b> = iter::Chain<iter::Cloned<slice::Iter<'a, PathElem>>, LinkedPath<'b>>;
9380

9481
pub fn path_to_string<PI: Iterator<Item=PathElem>>(path: PI) -> String {
9582
let itr = token::get_ident_interner();
@@ -101,7 +88,7 @@ pub fn path_to_string<PI: Iterator<Item=PathElem>>(path: PI) -> String {
10188
}
10289
s.push_str(&e[]);
10390
s
104-
}).to_string()
91+
})
10592
}
10693

10794
#[derive(Copy, Show)]
@@ -458,9 +445,9 @@ impl<'ast> Map<'ast> {
458445
if parent == id {
459446
match self.find_entry(id) {
460447
Some(RootInlinedParent(data)) => {
461-
f(Values(data.path.iter()).chain(next))
448+
f(data.path.iter().cloned().chain(next))
462449
}
463-
_ => f(Values([].iter()).chain(next))
450+
_ => f([].iter().cloned().chain(next))
464451
}
465452
} else {
466453
self.with_path_next(parent, Some(&LinkedPathNode {

src/libsyntax/ast_util.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -670,20 +670,13 @@ pub fn path_name_eq(a : &ast::Path, b : &ast::Path) -> bool {
670670

671671
// are two arrays of segments equal when compared unhygienically?
672672
pub fn segments_name_eq(a : &[ast::PathSegment], b : &[ast::PathSegment]) -> bool {
673-
if a.len() != b.len() {
674-
false
675-
} else {
676-
for (idx,seg) in a.iter().enumerate() {
677-
if seg.identifier.name != b[idx].identifier.name
678-
// FIXME #7743: ident -> name problems in lifetime comparison?
679-
// can types contain idents?
680-
|| seg.parameters != b[idx].parameters
681-
{
682-
return false;
683-
}
684-
}
685-
true
686-
}
673+
a.len() == b.len() &&
674+
a.iter().zip(b.iter()).all(|(s, t)| {
675+
s.identifier.name == t.identifier.name &&
676+
// FIXME #7743: ident -> name problems in lifetime comparison?
677+
// can types contain idents?
678+
s.parameters == t.parameters
679+
})
687680
}
688681

689682
/// Returns true if this literal is a string and false otherwise.

0 commit comments

Comments
 (0)