From f5a3efee88b3a2bf2d69b74f2d5a7eb75049f5ef Mon Sep 17 00:00:00 2001 From: Shotaro Yamada Date: Wed, 7 Mar 2018 07:16:25 +0900 Subject: [PATCH] Do not panic on tuple struct access out of bounds --- src/librustc_save_analysis/dump_visitor.rs | 17 ++++++++++------- src/test/run-make/save-analysis-fail/foo.rs | 3 +++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index d4d76ff786fa0..d92025a6787d6 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -1665,13 +1665,16 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc if !self.span.filter_generated(sub_span, ex.span) { let span = self.span_from_span(sub_span.expect("No span found for var ref")); - let ref_id = - ::id_from_def_id(def.non_enum_variant().fields[idx.node].did); - self.dumper.dump_ref(Ref { - kind: RefKind::Variable, - span, - ref_id, - }); + if let Some(field) = def.non_enum_variant().fields.get(idx.node) { + let ref_id = ::id_from_def_id(field.did); + self.dumper.dump_ref(Ref { + kind: RefKind::Variable, + span, + ref_id, + }); + } else { + return; + } } } ty::TyTuple(..) => {} diff --git a/src/test/run-make/save-analysis-fail/foo.rs b/src/test/run-make/save-analysis-fail/foo.rs index f123c3a812d3f..b844f2e49e71e 100644 --- a/src/test/run-make/save-analysis-fail/foo.rs +++ b/src/test/run-make/save-analysis-fail/foo.rs @@ -462,4 +462,7 @@ fn new(f: u32) -> Rls699 { fn invalid_tuple_struct_access() { bar.0; + + struct S; + S.0; }