From 3c72a848e9d4470d49969fa0ef0a0a8a0c24d681 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Mon, 5 Feb 2018 11:00:56 +1300 Subject: [PATCH] save-analysis: avoid implicit unwrap When looking up a field defintion, since the name might be incorrect in the field init shorthand case. cc https://github.com/rust-lang-nursery/rls/issues/699 --- src/librustc_save_analysis/lib.rs | 2 +- src/test/run-make/save-analysis-fail/foo.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 2e494fdfad8b8..7bd7d5cb15d8e 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -791,7 +791,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { field_ref: &ast::Field, variant: &ty::VariantDef, ) -> Option { - let f = variant.field_named(field_ref.ident.node.name); + let f = variant.find_field_named(field_ref.ident.node.name)?; // We don't really need a sub-span here, but no harm done let sub_span = self.span_utils.span_for_last_ident(field_ref.ident.span); filter!(self.span_utils, sub_span, field_ref.ident.span, None); diff --git a/src/test/run-make/save-analysis-fail/foo.rs b/src/test/run-make/save-analysis-fail/foo.rs index 8a1b579398946..07322d8bbc325 100644 --- a/src/test/run-make/save-analysis-fail/foo.rs +++ b/src/test/run-make/save-analysis-fail/foo.rs @@ -451,3 +451,11 @@ extern { static EXTERN_FOO: u8; fn extern_foo(a: u8, b: i32) -> String; } + +struct Rls699 { + f: u32, +} + +fn new(f: u32) -> Rls699 { + Rls699 { fs } +}