Skip to content

Commit 40466f6

Browse files
committed
Update rustc-ap-syntax to 100.0
This update includes removal of ExprKind::TupField(rust-lang/rust#49718). With this change, I changed the logic of method completion for tuple struct and added a related test.
1 parent 7868111 commit 40466f6

File tree

5 files changed

+58
-59
lines changed

5 files changed

+58
-59
lines changed

Cargo.lock

Lines changed: 26 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ env_logger = "0.5"
2323
cargo = "0.26"
2424
clap = "2.31"
2525
lazy_static = "1.0"
26-
rustc-ap-rustc_errors = "89.0.0"
27-
rustc-ap-syntax = "89.0.0"
28-
rustc-ap-syntax_pos = "89.0.0"
26+
rustc-ap-rustc_errors = "100.0.0"
27+
rustc-ap-syntax = "100.0.0"
28+
rustc-ap-syntax_pos = "100.0.0"
2929

3030
[dependencies.clippy]
3131
version = "0.0.192"

src/racer/ast.rs

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ fn to_racer_path(path: &ast::Path) -> core::Path {
478478
let mut v = Vec::new();
479479
let mut global = false;
480480
for seg in &path.segments {
481-
let name = seg.identifier.name.to_string();
481+
let name = seg.ident.name.to_string();
482482
let mut types = Vec::new();
483483
// TODO: this is for backword compatibility & maybe we have to rewrite core::Path
484484
if name == "{{root}}" {
@@ -664,7 +664,7 @@ impl<'c, 's, 'ast> visit::Visitor<'ast> for ExprTypeVisitor<'c, 's> {
664664

665665
ExprKind::MethodCall(ref method_def, ref arguments) => {
666666
// spannedident.node is an ident I think
667-
let methodname = method_def.identifier.name.as_str();
667+
let methodname = method_def.ident.name.as_str();
668668
debug!("[method call] name: {}", methodname);
669669

670670
// arguments[0] is receiver(e.g. self)
@@ -702,11 +702,11 @@ impl<'c, 's, 'ast> visit::Visitor<'ast> for ExprTypeVisitor<'c, 's> {
702702
}
703703

704704
ExprKind::Field(ref subexpression, spannedident) => {
705-
let fieldname = spannedident.node.name.to_string();
705+
let fieldname = spannedident.name.to_string();
706706
debug!("exprfield {}", fieldname);
707707
self.visit_expr(subexpression);
708-
self.result = self.result.as_ref().and_then(|structm| match *structm {
709-
Ty::Match(ref structm) => {
708+
self.result = self.result.as_ref().and_then(|structm| match structm {
709+
Ty::Match(structm) => {
710710
typeinf::get_struct_field_type(&fieldname, structm, self.session).and_then(
711711
|fieldtypepath| {
712712
find_type_match_including_generics(
@@ -758,27 +758,6 @@ impl<'c, 's, 'ast> visit::Visitor<'ast> for ExprTypeVisitor<'c, 's> {
758758
};
759759
}
760760

761-
ExprKind::TupField(ref subexpression, ref spanned_index) => {
762-
let fieldnum = spanned_index.node;
763-
debug!("tupfield {:?}", fieldnum);
764-
self.visit_expr(subexpression);
765-
self.result = self.result.as_ref().and_then(|ty| match *ty {
766-
Ty::Match(ref structm) => {
767-
typeinf::get_tuplestruct_field_type(fieldnum, structm, &self.session)
768-
.and_then(|fieldtypepath| {
769-
find_type_match_including_generics(
770-
&fieldtypepath,
771-
&structm.filepath,
772-
structm.point,
773-
structm,
774-
self.session,
775-
)
776-
})
777-
}
778-
_ => None,
779-
});
780-
}
781-
782761
ExprKind::Try(ref expr) => {
783762
debug!("try expr");
784763
self.visit_expr(&expr);
@@ -1212,7 +1191,7 @@ impl GenericsList {
12121191
GenericParam::Lifetime(_) => None,
12131192
GenericParam::Type(ty_param) => {
12141193
let param_name = ty_param.ident.name.as_str().to_string();
1215-
let codemap::BytePos(point) = ty_param.span.lo();
1194+
let codemap::BytePos(point) = ty_param.ident.span.lo();
12161195
let bounds =
12171196
TraitBounds::from_ty_param_bounds(&ty_param.bounds, &file_path, offset);
12181197
Some(GenericsArg {
@@ -1265,7 +1244,7 @@ impl<'ast> visit::Visitor<'ast> for EnumVisitor {
12651244
for variant in &enum_definition.variants {
12661245
let codemap::BytePos(point) = variant.span.lo();
12671246
self.values
1268-
.push((variant.node.name.to_string(), point as usize));
1247+
.push((variant.node.ident.name.to_string(), point as usize));
12691248
}
12701249
}
12711250
}

src/racer/typeinf.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,16 @@ pub fn get_struct_field_type(
286286
session: &Session,
287287
) -> Option<core::Ty> {
288288
assert!(structmatch.mtype == core::MatchType::Struct);
289-
289+
debug!("[get_struct_filed_type]{}, {:?}", fieldname, structmatch);
290290
let src = session.load_file(&structmatch.filepath);
291291

292292
let opoint = scopes::expect_stmt_start(src.as_src(), structmatch.point);
293293
let structsrc = scopes::end_of_next_scope(&src[opoint..]);
294-
294+
let structsrc = if structsrc == "" {
295+
(*get_first_stmt(src.as_src().from(opoint))).to_owned()
296+
} else {
297+
structsrc.to_owned()
298+
};
295299
let fields = ast::parse_struct_fields(structsrc.to_owned(), Scope::from_match(structmatch));
296300
for (field, _, ty) in fields.into_iter() {
297301
if fieldname == field {

tests/system.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4057,6 +4057,22 @@ fn completes_methods_for_closure_arg() {
40574057
);
40584058
}
40594059

4060+
#[test]
4061+
fn completes_methods_for_tuple_struct() {
4062+
let src = r"
4063+
fn main() {
4064+
struct A(i32, Vec<i32>);
4065+
let mut a = A(0, vec![3, 4]);
4066+
a.1.appen~
4067+
}
4068+
";
4069+
assert!(
4070+
get_all_completions(src, None)
4071+
.into_iter()
4072+
.any(|ma| ma.matchstr == "append")
4073+
);
4074+
}
4075+
40604076
// issue 706
40614077
mod trait_bounds {
40624078
use super::*;

0 commit comments

Comments
 (0)