Skip to content

Commit

Permalink
save-analysis: avoid implicit unwrap
Browse files Browse the repository at this point in the history
When looking up a field defintion, since the name might be incorrect in the field init shorthand case.

cc rust-lang/rls#699
  • Loading branch information
nrc committed Feb 4, 2018
1 parent 0c6091f commit 3c72a84
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/librustc_save_analysis/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
field_ref: &ast::Field,
variant: &ty::VariantDef,
) -> Option<Ref> {
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);
Expand Down
8 changes: 8 additions & 0 deletions src/test/run-make/save-analysis-fail/foo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

0 comments on commit 3c72a84

Please sign in to comment.