Skip to content

Commit 60be621

Browse files
committed
Add temprary fix for complete tuple structs
By rust-lang/rust#49718, ExprKind::TupField was removed. This commit includes a temorary fix and a tests for this removal.
1 parent 9f0902b commit 60be621

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/racer/typeinf.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,27 @@ fn get_type_of_for_expr(m: &Match, msrc: Src, session: &Session) -> Option<core:
217217
}
218218

219219
pub fn get_struct_field_type(fieldname: &str, structmatch: &Match, session: &Session) -> Option<core::Ty> {
220-
assert!(structmatch.mtype == core::MatchType::Struct);
220+
// temporary fix for https://github.com/rust-lang-nursery/rls/issues/783
221+
if structmatch.mtype != core::MatchType::Struct {
222+
warn!("get_struct_filed_type is called for {:?}", structmatch.mtype);
223+
return None;
224+
}
225+
226+
debug!("[get_struct_filed_type]{}, {:?}", fieldname, structmatch);
221227

222228
let src = session.load_file(&structmatch.filepath);
223229

224230
let opoint = scopes::expect_stmt_start(src.as_src(), structmatch.point);
225231
let structsrc = scopes::end_of_next_scope(&src[opoint..]);
226232

233+
// HACK: if scopes::end_of_next_scope returns empty struct, it's maybe tuple struct
234+
// TODO: remove this hack
235+
let structsrc = if structsrc == "" {
236+
(*get_first_stmt(src.as_src().from(opoint))).to_owned()
237+
} else {
238+
structsrc.to_owned()
239+
};
240+
227241
let fields = ast::parse_struct_fields(structsrc.to_owned(), Scope::from_match(structmatch));
228242
for (field, _, ty) in fields {
229243
if fieldname == field {

tests/system.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4256,3 +4256,20 @@ fn main {
42564256
assert_eq!(doc_str, got.docs);
42574257
})
42584258
}
4259+
4260+
#[test]
4261+
fn completes_methods_for_tuple_struct() {
4262+
let _lock = sync!();
4263+
let src = r"
4264+
fn main() {
4265+
struct A(i32, Vec<i32>);
4266+
let mut a = A(0, vec![3, 4]);
4267+
a.1.appen~
4268+
}
4269+
";
4270+
assert!(
4271+
get_all_completions(src, None)
4272+
.into_iter()
4273+
.any(|ma| ma.matchstr == "append")
4274+
);
4275+
}

0 commit comments

Comments
 (0)