Skip to content

Fix regressed test due to rust-lang/rust#78461 #1144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/racer/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,17 @@ impl<'c, 's, 'ast> visit::Visitor<'ast> for ExprTypeVisitor<'c, 's> {
.and_then(|ty| path_to_match(ty, self.session))
}
MatchType::Method(ref gen) => {
typeinf::get_return_type_of_function(&m, &m, self.session).and_then(
let mut return_ty = typeinf::get_return_type_of_function(&m, &m, self.session);
// Account for already resolved generics if the return type is Self
// (in which case we return bare type as found in the `impl` header)
if let (Some(Ty::Match(ref mut m)), Some(gen)) = (&mut return_ty, gen) {
for (type_param, arg) in m.generics_mut().zip(gen.args()) {
if let Some(resolved) = arg.resolved() {
type_param.resolve(resolved.clone());
}
}
}
return_ty.and_then(
|ty| {
path_to_match_including_generics(
ty,
Expand Down
41 changes: 41 additions & 0 deletions src/racer/matchers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,27 @@ fn match_mod_inner(
}

fn find_generics_end(blob: &str) -> Option<BytePos> {
// Naive version that attempts to skip over attributes
let mut in_attr = false;
let mut attr_level = 0;

let mut level = 0;
for (i, b) in blob.as_bytes().into_iter().enumerate() {
// Naively skip attributes `#[...]`
if in_attr {
match b {
b'[' => attr_level += 1,
b']' => {
attr_level -=1;
if attr_level == 0 {
in_attr = false;
continue;
}
},
_ => continue,
}
}
// ...otherwise just try to find the last `>`
match b {
b'{' | b'(' | b';' => return None,
b'<' => level += 1,
Expand All @@ -436,6 +455,7 @@ fn find_generics_end(blob: &str) -> Option<BytePos> {
return Some(i.into());
}
}
b'#' if blob.bytes().nth(i + 1) == Some(b'[') => in_attr = true,
_ => {}
}
}
Expand Down Expand Up @@ -871,3 +891,24 @@ pub fn match_impl(decl: String, context: &MatchCxt<'_, '_>, offset: BytePos) ->
}
Some(out)
}

#[cfg(test)]
mod tests {
use super::*;
#[test]
fn find_generics_end() {
use super::find_generics_end;
assert_eq!(
find_generics_end("Vec<T, #[unstable(feature = \"\", issue = \"\"] A: AllocRef = Global>"),
Some(BytePos(64))
);
assert_eq!(
find_generics_end("Vec<T, A: AllocRef = Global>"),
Some(BytePos(27))
);
assert_eq!(
find_generics_end("Result<Vec<String>, Option<&str>>"),
Some(BytePos(32))
);
}
}