Skip to content

Commit

Permalink
Rollup merge of rust-lang#48007 - nrc:rls-field-init, r=eddyb
Browse files Browse the repository at this point in the history
save-analysis: avoid implicit unwrap

When looking up a field defintion, since the name might be incorrect in the field init shorthand case.

cc rust-lang/rls#699

r? @eddyb
  • Loading branch information
kennytm committed Feb 5, 2018
2 parents e2f6e13 + 3c72a84 commit 0553dc8
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 0553dc8

Please sign in to comment.