Skip to content

Commit e344dd1

Browse files
committed
Account for resolved generics for Self-returning methods
One concrete example is when we have a partially resolved generic type which calls a `Self`-returning method, e.g. `Vec<String, _>::new()`. Previously, the returned type for `Self`-returning methods would return the unresolved, generic type as encountered in the impl header (so `Vec<T, A: AllocRef = Global>` in this case). However, if the method match already carries some information about generics (T := String here), make sure to account for it.
1 parent fcf3432 commit e344dd1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/racer/ast.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,16 @@ 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+
let resolved = gen.args().filter_map(|tp| tp.resolved());
535+
for (l, r) in m.generics_mut().zip(resolved) {
536+
l.resolve(r.clone());
537+
}
538+
}
539+
return_ty.and_then(
531540
|ty| {
532541
path_to_match_including_generics(
533542
ty,

0 commit comments

Comments
 (0)