Skip to content

Commit 3609333

Browse files
committed
syntax: Replace unstable .cloned() with manual iter
1 parent 1ab514c commit 3609333

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

src/librustc/metadata/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,7 @@ fn encode_info_for_items(ecx: &EncodeContext,
15131513
&krate.module,
15141514
&[],
15151515
ast::CRATE_NODE_ID,
1516-
[].iter().cloned().chain(LinkedPath::empty()),
1516+
PathElems::new(&[], LinkedPath::empty()),
15171517
syntax::parse::token::special_idents::invalid.name,
15181518
ast::Public);
15191519

@@ -1874,7 +1874,7 @@ fn encode_misc_info(ecx: &EncodeContext,
18741874
}
18751875

18761876
// Encode reexports for the root module.
1877-
encode_reexports(ecx, rbml_w, 0, [].iter().cloned().chain(LinkedPath::empty()));
1877+
encode_reexports(ecx, rbml_w, 0, PathElems::new(&[], LinkedPath::empty()));
18781878

18791879
rbml_w.end_tag();
18801880
rbml_w.end_tag();

src/librustc/middle/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5383,7 +5383,7 @@ pub fn with_path<T, F>(cx: &ctxt, id: ast::DefId, f: F) -> T where
53835383
if id.krate == ast::LOCAL_CRATE {
53845384
cx.map.with_path(id.node, f)
53855385
} else {
5386-
f(csearch::get_item_path(cx, id).iter().cloned().chain(LinkedPath::empty()))
5386+
f(ast_map::PathElems::new(&csearch::get_item_path(cx, id), LinkedPath::empty()))
53875387
}
53885388
}
53895389

src/libsyntax/ast_map/mod.rs

+28-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use arena::TypedArena;
2525
use std::cell::RefCell;
2626
use std::fmt;
2727
use std::io;
28-
use std::iter::{self, repeat};
28+
use std::iter::repeat;
2929
use std::mem;
3030
use std::slice;
3131

@@ -86,7 +86,31 @@ impl<'a> Iterator for LinkedPath<'a> {
8686
}
8787

8888
/// The type of the iterator used by with_path.
89-
pub type PathElems<'a, 'b> = iter::Chain<iter::Cloned<slice::Iter<'a, PathElem>>, LinkedPath<'b>>;
89+
#[derive(Clone)]
90+
pub struct PathElems<'a, 'b> {
91+
iter: slice::Iter<'a, PathElem>,
92+
next: LinkedPath<'b>,
93+
}
94+
95+
impl<'a, 'b> PathElems<'a, 'b> {
96+
pub fn new(elems: &'a [PathElem], next: LinkedPath<'b>) -> Self {
97+
PathElems {
98+
iter: elems.iter(),
99+
next: next,
100+
}
101+
}
102+
}
103+
104+
impl<'a, 'b> Iterator for PathElems<'a, 'b> {
105+
type Item = PathElem;
106+
107+
fn next(&mut self) -> Option<PathElem> {
108+
match self.iter.next() {
109+
Some(item) => Some(item.clone()),
110+
None => self.next.next(),
111+
}
112+
}
113+
}
90114

91115
pub fn path_to_string<PI: Iterator<Item=PathElem>>(path: PI) -> String {
92116
let itr = token::get_ident_interner();
@@ -427,10 +451,8 @@ impl<'ast> Map<'ast> {
427451
};
428452
if parent == id {
429453
match self.find_entry(id) {
430-
Some(RootInlinedParent(data)) => {
431-
f(data.path.iter().cloned().chain(next))
432-
}
433-
_ => f([].iter().cloned().chain(next))
454+
Some(RootInlinedParent(data)) => f(PathElems::new(&data.path, next)),
455+
_ => f(PathElems::new(&[], next)),
434456
}
435457
} else {
436458
self.with_path_next(parent, LinkedPath::from(&LinkedPathNode {

src/libsyntax/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
html_root_url = "http://doc.rust-lang.org/nightly/")]
2727

2828
#![feature(collections)]
29-
#![feature(core)]
3029
#![feature(libc)]
3130
#![feature(rustc_private)]
3231
#![feature(staged_api)]

0 commit comments

Comments
 (0)