Repository navigation
Conversation
|
Thanks for your review. I think this is a kind of a quick solution which could solve the problem by only changing a parser. struct Defer {}
impl Drop for Defer {
fn finalize(&self) { io::println("destroyed"); }
}
fn main() {
let d = Defer{};
}I also think that decision should be made by core team, whether just make empty struct impossible, add parentheses to use empty struct in match, or whatever. Could you let me know when a decision is made? By the way, I just add another patch, which reverts merge failure. That's my mistake. If there is any other procedure to fix the merge failure problem (maybe submit a new pull request?), please let me know. |
|
Per this thread on the mailing list, I think the conclusion is that we will simply not parse empty structs like That said, I am inclined to take this patch and address the matter of empty struct literals separately. I don't think there were invasive changes to the parser to handle the ambiguity as you did. |
|
I just opened issue #5167, which covers structs with no fields |
|
@yjh0502 I see that this pull request can no longer be automatically merged. Can you rebase it (and perhaps squash together the commit that undoes the broken merge with the other commits)? Otherwise bors won't be able to land it, even if we mark it r+. |
|
I aggregate & clean up all commit, and make it to single commit. Sorry for late replay, I'm not yet familier with git & github, so it takes time. |
|
OK. One last thing: can you squash those two commits together (since one just undoes part of the other) and also revert back the tests which were changed:
Thanks. |
|
Done. |
The fix is straight-forward, but there are several changes
while fixing the issue.
1) disallow `mut` keyword when making a new struct
In code base, there are following code,
```rust
struct Foo { mut a: int };
let a = Foo { mut a: 1 };
```
This is because of structural record, which is
deprecated corrently (see issue #3089) In structural
record, `mut` keyword should be allowd to control
mutability. But without structural record, we don't
need to allow `mut` keyword while constructing struct.
2) disallow structural records in parser level
This is related to 1). With structural records, there
is an ambiguity between empty block and empty struct
To solve the problem, I change parser to stop parsing
structural records. I think this is not a problem,
because structural records are not compiled already.
Misc. issues
There is an ambiguity between empty struct vs. empty match stmt.
with following code,
```rust
match x{} {}
```
Two interpretation is possible, which is listed blow
```rust
match (x{}) {} // matching with newly-constructed empty struct
(match x{}) {} // matching with empty enum(or struct) x
// and then empty block
```
It seems that there is no such code in rust code base, but
there is one test which uses empty match statement:
https://github.com/mozilla/rust/blob/incoming/src/test/run-pass/issue-3037.rs
All other cases could be distinguished with look-ahead,
but this can't be. One possible solution is wrapping with
parentheses when matching with an uninhabited type.
```rust
enum what { }
fn match_with_empty(x: what) -> ~str {
match (x) { //use parentheses to remove the ambiguity
}
}
```
Prevent failing to restart setup-toolchain If `rustup-toolchain-install-master` fails to install master toolchain (in case `rustup update` executes at the same remove the tmp directory), `cargo search` (which use master toolchain after `rustup override` command) will fail. This leads to setup-toolchain fails too. changelog: none
5137: Make gotodef tests more data-driven r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
The fix is straight-forward, but there are several changes
while fixing the issue.
mutkeyword when making a new structIn code base, there are following code,
This is because of structural record, which is
deprecated corrently (see issue #3089) In structural
record,
mutkeyword should be allowd to controlmutability. But without structural record, we don't
need to allow
mutkeyword while constructing struct.This is related to 1). With structural records, there
is an ambiguity between empty block and empty struct
To solve the problem, I change parser to stop parsing
structural records. I think this is not a problem,
because structural records are not compiled already.
Misc. issues
There is an ambiguity between empty struct vs. empty match stmt.
with following code,
Two interpretation is possible, which is listed blow
It seems that there is no such code in rust code base, but
there is one test which uses empty match statement:
https://github.com/mozilla/rust/blob/incoming/src/test/run-pass/issue-3037.rs
All other cases could be distinguished with look-ahead,
but this can't be. One possible solution is wrapping with
parentheses when matching with an uninhabited type.