Skip to content

Commit f5a3efe

Browse files
committedMar 6, 2018
Do not panic on tuple struct access out of bounds
1 parent c92630a commit f5a3efe

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed
 

‎src/librustc_save_analysis/dump_visitor.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -1665,13 +1665,16 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
16651665
if !self.span.filter_generated(sub_span, ex.span) {
16661666
let span =
16671667
self.span_from_span(sub_span.expect("No span found for var ref"));
1668-
let ref_id =
1669-
::id_from_def_id(def.non_enum_variant().fields[idx.node].did);
1670-
self.dumper.dump_ref(Ref {
1671-
kind: RefKind::Variable,
1672-
span,
1673-
ref_id,
1674-
});
1668+
if let Some(field) = def.non_enum_variant().fields.get(idx.node) {
1669+
let ref_id = ::id_from_def_id(field.did);
1670+
self.dumper.dump_ref(Ref {
1671+
kind: RefKind::Variable,
1672+
span,
1673+
ref_id,
1674+
});
1675+
} else {
1676+
return;
1677+
}
16751678
}
16761679
}
16771680
ty::TyTuple(..) => {}

‎src/test/run-make/save-analysis-fail/foo.rs

+3
Original file line numberDiff line numberDiff line change
@@ -462,4 +462,7 @@ fn new(f: u32) -> Rls699 {
462462

463463
fn invalid_tuple_struct_access() {
464464
bar.0;
465+
466+
struct S;
467+
S.0;
465468
}

0 commit comments

Comments
 (0)