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

Conversation

sinkuu
Copy link
Contributor

@sinkuu sinkuu commented Mar 6, 2018

Reproduction:

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

@rust-highfive
Copy link
Collaborator

r? @estebank

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 6, 2018
@nrc
Copy link
Member

nrc commented Mar 6, 2018

r? @nrc

@@ -1675,7 +1675,10 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
}
}
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
    ...
}

@nrc nrc assigned nrc and unassigned estebank Mar 6, 2018
@nrc nrc added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 6, 2018
@sinkuu sinkuu changed the title Fix save-analysis generation crash with invalid tuple construction Fix save-analysis generation crash with invalid tuple access Mar 6, 2018
@nrc
Copy link
Member

nrc commented Mar 7, 2018

OK, makes sense. Second commit looks fine.

@bors: r+

@bors
Copy link
Contributor

bors commented Mar 7, 2018

📌 Commit f5a3efe has been approved by nrc

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 7, 2018
alexcrichton added a commit to alexcrichton/rust that referenced this pull request Mar 7, 2018
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
bors added a commit that referenced this pull request Mar 7, 2018
Rollup of 9 pull requests

- Successful merges: #48511, #48549, #48618, #48624, #48651, #48698, #48778, #48787, #48802
- Failed merges: #48669, #48710
alexcrichton added a commit to alexcrichton/rust that referenced this pull request Mar 7, 2018
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
bors added a commit that referenced this pull request Mar 7, 2018
Rollup of 9 pull requests

- Successful merges: #48511, #48549, #48618, #48624, #48651, #48698, #48778, #48787, #48802
- Failed merges: #48669, #48710
bors added a commit that referenced this pull request Mar 7, 2018
Rollup of 9 pull requests

- Successful merges: #48511, #48549, #48618, #48624, #48651, #48698, #48778, #48787, #48802
- Failed merges: #48669, #48710
@alexcrichton alexcrichton merged commit f5a3efe into rust-lang:master Mar 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants