Skip to content

Commit 9db4755

Browse files
committed
Fix compilation error for assoc types in the Iterator traits
This error is the following: ``` $ make rustc -O -o bin/racer src/main.rs src/racer/codeiter.rs:22:10: 22:32 error: wrong number of type arguments: expected 0, found 1 src/racer/codeiter.rs:22 impl<'a> Iterator<(uint, uint)> for StmtIndicesIter<'a> { ^~~~~~~~~~~~~~~~~~~~~~ ``` This is caused by rust-lang/rust#20441
1 parent 389d84c commit 9db4755

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![feature(macro_rules)]
22
#![feature(phase)]
3+
#![feature(associated_types)]
34
#[phase(plugin, link)] extern crate log;
45

56
extern crate syntax;

src/racer/codecleaner.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ pub fn rejustify(src: &str) -> String {
55
let mut sb = String::new();
66
for l in s.lines() {
77
let tabless = l.slice_from(4);
8-
sb.push_str(tabless);
9-
if tabless.len() != 0 {
8+
sb.push_str(tabless);
9+
if tabless.len() != 0 {
1010
sb.push_str("\n");
1111
}
1212
}
@@ -35,7 +35,9 @@ pub struct CodeIndicesIter<'a> {
3535
state: State
3636
}
3737

38-
impl<'a> Iterator<(uint, uint)> for CodeIndicesIter<'a> {
38+
impl<'a> Iterator for CodeIndicesIter<'a> {
39+
type Item = (uint, uint);
40+
3941
#[inline]
4042
fn next(&mut self) -> Option<(uint, uint)> {
4143
return match self.state {

src/racer/codeiter.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ pub struct StmtIndicesIter<'a> {
1919
enddelim: u8
2020
}
2121

22-
impl<'a> Iterator<(uint, uint)> for StmtIndicesIter<'a> {
22+
impl<'a> Iterator for StmtIndicesIter<'a> {
23+
type Item = (uint, uint);
24+
2325
#[inline]
2426
fn next(&mut self) -> Option<(uint, uint)> {
2527
let semicolon: u8 = ";".as_bytes()[0];
@@ -78,10 +80,10 @@ impl<'a> Iterator<(uint, uint)> for StmtIndicesIter<'a> {
7880
self.start = self.pos;
7981
}
8082

81-
83+
8284
// if the statement starts with 'macro_rules!' then we're in a macro
8385
// We need to know this because a closeparen can terminate a macro
84-
if (self.end - self.pos) > 12 &&
86+
if (self.end - self.pos) > 12 &&
8587
self.src.slice(self.pos, self.pos+12) == "macro_rules!" {
8688
self.is_macro = true;
8789
}
@@ -92,14 +94,14 @@ impl<'a> Iterator<(uint, uint)> for StmtIndicesIter<'a> {
9294

9395
// macros can be terminated by closeparen if opened by one
9496
if self.is_macro &&
95-
self.bracelevel == 0 &&
97+
self.bracelevel == 0 &&
9698
self.parenlevel == 0 {
9799
self.enddelim = closeparen;
98100
}
99-
101+
100102
// also macro invocations can too
101103
if self.pos > 0 && src_bytes[self.pos-1] == bang &&
102-
self.bracelevel == 0 &&
104+
self.bracelevel == 0 &&
103105
self.parenlevel == 0 {
104106
self.enddelim = closeparen;
105107
}
@@ -110,9 +112,9 @@ impl<'a> Iterator<(uint, uint)> for StmtIndicesIter<'a> {
110112
self.parenlevel -= 1;
111113

112114
} else if src_bytes[self.pos] == openbrace {
113-
// if we are top level and stmt is not a 'use' then
115+
// if we are top level and stmt is not a 'use' then
114116
// closebrace finishes the stmt
115-
if self.bracelevel == 0 &&
117+
if self.bracelevel == 0 &&
116118
self.parenlevel == 0 &&
117119
!(is_a_use_stmt(self.src, self.start, self.pos)) {
118120
self.enddelim = closebrace;
@@ -128,12 +130,12 @@ impl<'a> Iterator<(uint, uint)> for StmtIndicesIter<'a> {
128130
}
129131

130132
// attribute #[foo = bar]
131-
if self.bracelevel == 0 && self.start == self.pos &&
133+
if self.bracelevel == 0 && self.start == self.pos &&
132134
src_bytes[self.pos] == hash {
133135
self.enddelim = closesqbrace;
134136
}
135137

136-
if self.bracelevel == 0 && self.parenlevel == 0 &&
138+
if self.bracelevel == 0 && self.parenlevel == 0 &&
137139
src_bytes[self.pos] == self.enddelim {
138140
let start = self.start;
139141
self.start = self.pos+1;
@@ -145,24 +147,24 @@ impl<'a> Iterator<(uint, uint)> for StmtIndicesIter<'a> {
145147

146148
self.pos += 1;
147149
}
148-
150+
149151
}
150152
}
151153
}
152154

153155
fn is_a_use_stmt(src: &str, start: uint, pos: uint) -> bool {
154156
let src_bytes = src.as_bytes();
155157
let whitespace = " {\t\r\n".as_bytes();
156-
(pos > 3 && src_bytes.slice(start, start+3) == "use".as_bytes() &&
157-
whitespace.contains(&src_bytes[start+3])) ||
158+
(pos > 3 && src_bytes.slice(start, start+3) == "use".as_bytes() &&
159+
whitespace.contains(&src_bytes[start+3])) ||
158160
(pos > 7 && src_bytes.slice(start, start+7) == "pub use".as_bytes() &&
159161
whitespace.contains(&src_bytes[start+7]))
160162
}
161163

162164
pub fn iter_stmts<'a>(src: &'a str) -> StmtIndicesIter<'a> {
163165
let semicolon: u8 = ";".as_bytes()[0];
164-
StmtIndicesIter{src: src, it: code_chunks(src),
165-
pos: 0, start: 0, end: 0, bracelevel: 0,
166+
StmtIndicesIter{src: src, it: code_chunks(src),
167+
pos: 0, start: 0, end: 0, bracelevel: 0,
166168
parenlevel: 0, enddelim: semicolon, is_macro: false}
167169
}
168170

0 commit comments

Comments
 (0)