Skip to content

Commit 9888114

Browse files
authored
Merge pull request #1144 from Xanewok/fix-regressed-vec
Fix regressed test due to rust-lang/rust#78461
2 parents 0736400 + a67ca96 commit 9888114

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/racer/ast.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,17 @@ impl<'c, 's, 'ast> visit::Visitor<'ast> for ExprTypeVisitor<'c, 's> {
527527
.and_then(|ty| path_to_match(ty, self.session))
528528
}
529529
MatchType::Method(ref gen) => {
530-
typeinf::get_return_type_of_function(&m, &m, self.session).and_then(
530+
let mut return_ty = typeinf::get_return_type_of_function(&m, &m, self.session);
531+
// Account for already resolved generics if the return type is Self
532+
// (in which case we return bare type as found in the `impl` header)
533+
if let (Some(Ty::Match(ref mut m)), Some(gen)) = (&mut return_ty, gen) {
534+
for (type_param, arg) in m.generics_mut().zip(gen.args()) {
535+
if let Some(resolved) = arg.resolved() {
536+
type_param.resolve(resolved.clone());
537+
}
538+
}
539+
}
540+
return_ty.and_then(
531541
|ty| {
532542
path_to_match_including_generics(
533543
ty,

src/racer/matchers.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,27 @@ fn match_mod_inner(
425425
}
426426

427427
fn find_generics_end(blob: &str) -> Option<BytePos> {
428+
// Naive version that attempts to skip over attributes
429+
let mut in_attr = false;
430+
let mut attr_level = 0;
431+
428432
let mut level = 0;
429433
for (i, b) in blob.as_bytes().into_iter().enumerate() {
434+
// Naively skip attributes `#[...]`
435+
if in_attr {
436+
match b {
437+
b'[' => attr_level += 1,
438+
b']' => {
439+
attr_level -=1;
440+
if attr_level == 0 {
441+
in_attr = false;
442+
continue;
443+
}
444+
},
445+
_ => continue,
446+
}
447+
}
448+
// ...otherwise just try to find the last `>`
430449
match b {
431450
b'{' | b'(' | b';' => return None,
432451
b'<' => level += 1,
@@ -436,6 +455,7 @@ fn find_generics_end(blob: &str) -> Option<BytePos> {
436455
return Some(i.into());
437456
}
438457
}
458+
b'#' if blob.bytes().nth(i + 1) == Some(b'[') => in_attr = true,
439459
_ => {}
440460
}
441461
}
@@ -871,3 +891,24 @@ pub fn match_impl(decl: String, context: &MatchCxt<'_, '_>, offset: BytePos) ->
871891
}
872892
Some(out)
873893
}
894+
895+
#[cfg(test)]
896+
mod tests {
897+
use super::*;
898+
#[test]
899+
fn find_generics_end() {
900+
use super::find_generics_end;
901+
assert_eq!(
902+
find_generics_end("Vec<T, #[unstable(feature = \"\", issue = \"\"] A: AllocRef = Global>"),
903+
Some(BytePos(64))
904+
);
905+
assert_eq!(
906+
find_generics_end("Vec<T, A: AllocRef = Global>"),
907+
Some(BytePos(27))
908+
);
909+
assert_eq!(
910+
find_generics_end("Result<Vec<String>, Option<&str>>"),
911+
Some(BytePos(32))
912+
);
913+
}
914+
}

0 commit comments

Comments
 (0)