Skip to content

Commit

Permalink
Rollup merge of rust-lang#48778 - sinkuu:rls_crash_tuple_struct, r=nrc
Browse files Browse the repository at this point in the history
Fix save-analysis generation crash with invalid tuple access

Reproduction:

```rust
fn invalid_tuple_struct_accessing() {
    bar.0;
}
```
```
error[E0425]: cannot find value `bar` in this scope
 --> test.rs:2:5
  |
2 |     bar.0;
  |     ^^^ not found in this scope

error[E0601]: main function not found

error: internal compiler error: librustc_save_analysis/dump_visitor.rs:1678: Expected struct or tuple type, found TyError
 --> test.rs:2:5
  |
2 |     bar.0;
  |     ^^^^^

thread 'rustc' panicked at 'Box<Any>', librustc_errors/lib.rs:482:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.
```

This should fix a crash in RLS when editing such code. cc @nrc
  • Loading branch information
alexcrichton committed Mar 7, 2018
2 parents 584a28f + f5a3efe commit 0e6df53
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
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),
_ => {
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;
}

0 comments on commit 0e6df53

Please sign in to comment.