Skip to content

Commit

Permalink
Fix compilation error for assoc types in the Iterator traits
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kui committed Jan 5, 2015
1 parent 389d84c commit 9db4755
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![feature(macro_rules)]
#![feature(phase)]
#![feature(associated_types)]
#[phase(plugin, link)] extern crate log;

extern crate syntax;
Expand Down
8 changes: 5 additions & 3 deletions src/racer/codecleaner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ pub fn rejustify(src: &str) -> String {
let mut sb = String::new();
for l in s.lines() {
let tabless = l.slice_from(4);
sb.push_str(tabless);
if tabless.len() != 0 {
sb.push_str(tabless);
if tabless.len() != 0 {
sb.push_str("\n");
}
}
Expand Down Expand Up @@ -35,7 +35,9 @@ pub struct CodeIndicesIter<'a> {
state: State
}

impl<'a> Iterator<(uint, uint)> for CodeIndicesIter<'a> {
impl<'a> Iterator for CodeIndicesIter<'a> {
type Item = (uint, uint);

#[inline]
fn next(&mut self) -> Option<(uint, uint)> {
return match self.state {
Expand Down
32 changes: 17 additions & 15 deletions src/racer/codeiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ pub struct StmtIndicesIter<'a> {
enddelim: u8
}

impl<'a> Iterator<(uint, uint)> for StmtIndicesIter<'a> {
impl<'a> Iterator for StmtIndicesIter<'a> {
type Item = (uint, uint);

#[inline]
fn next(&mut self) -> Option<(uint, uint)> {
let semicolon: u8 = ";".as_bytes()[0];
Expand Down Expand Up @@ -78,10 +80,10 @@ impl<'a> Iterator<(uint, uint)> for StmtIndicesIter<'a> {
self.start = self.pos;
}


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

// macros can be terminated by closeparen if opened by one
if self.is_macro &&
self.bracelevel == 0 &&
self.bracelevel == 0 &&
self.parenlevel == 0 {
self.enddelim = closeparen;
}

// also macro invocations can too
if self.pos > 0 && src_bytes[self.pos-1] == bang &&
self.bracelevel == 0 &&
self.bracelevel == 0 &&
self.parenlevel == 0 {
self.enddelim = closeparen;
}
Expand All @@ -110,9 +112,9 @@ impl<'a> Iterator<(uint, uint)> for StmtIndicesIter<'a> {
self.parenlevel -= 1;

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

// attribute #[foo = bar]
if self.bracelevel == 0 && self.start == self.pos &&
if self.bracelevel == 0 && self.start == self.pos &&
src_bytes[self.pos] == hash {
self.enddelim = closesqbrace;
}

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

self.pos += 1;
}

}
}
}

fn is_a_use_stmt(src: &str, start: uint, pos: uint) -> bool {
let src_bytes = src.as_bytes();
let whitespace = " {\t\r\n".as_bytes();
(pos > 3 && src_bytes.slice(start, start+3) == "use".as_bytes() &&
whitespace.contains(&src_bytes[start+3])) ||
(pos > 3 && src_bytes.slice(start, start+3) == "use".as_bytes() &&
whitespace.contains(&src_bytes[start+3])) ||
(pos > 7 && src_bytes.slice(start, start+7) == "pub use".as_bytes() &&
whitespace.contains(&src_bytes[start+7]))
}

pub fn iter_stmts<'a>(src: &'a str) -> StmtIndicesIter<'a> {
let semicolon: u8 = ";".as_bytes()[0];
StmtIndicesIter{src: src, it: code_chunks(src),
pos: 0, start: 0, end: 0, bracelevel: 0,
StmtIndicesIter{src: src, it: code_chunks(src),
pos: 0, start: 0, end: 0, bracelevel: 0,
parenlevel: 0, enddelim: semicolon, is_macro: false}
}

Expand Down

0 comments on commit 9db4755

Please sign in to comment.