Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix save-analysis generation crash with invalid tuple access #48778

Merged
merged 2 commits into from
Mar 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/librustc_save_analysis/dump_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1665,17 +1665,23 @@ 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(..) => {}
_ => span_bug!(ex.span, "Expected struct or tuple type, found {:?}", ty),
_ => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you're using the invalid tuple constructor is this ty:err or something similarly specific? Could we explicitly catch that case and return, and still span_bug ICE if it's something else? If we silently fail and cope then it's really hard to notice the omission until somebody reports a hard to discover bug against the RLS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that almost all type variants (all but TyInfer?) can be crafted.

fn foo<T>(x: T) {
    bar.0; // TyError
    (0).0; // TyError
    x.0; // TyParam
    static S: i32 = 0;
    (S).0; // TyInt
    [].0; // TyArray
    extern { type Externed; }
    (|| -> Externed { panic!() })().0; // TyForeign
    (|| -> ! { panic!() })().0; // TyNever
    ...
}

debug!("Expected struct or tuple type, found {:?}", ty);
return;
}
}
}
ast::ExprKind::Closure(_, _, ref decl, ref body, _fn_decl_span) => {
Expand Down
7 changes: 7 additions & 0 deletions src/test/run-make/save-analysis-fail/foo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,10 @@ struct Rls699 {
fn new(f: u32) -> Rls699 {
Rls699 { fs }
}

fn invalid_tuple_struct_access() {
bar.0;

struct S;
S.0;
}