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

Remove structural records #3089

Closed
brson opened this Issue Aug 2, 2012 · 4 comments

Comments

Projects
None yet
3 participants
@brson
Copy link
Contributor

brson commented Aug 2, 2012

No description provided.

@marijnh

This comment has been minimized.

Copy link
Contributor

marijnh commented Aug 2, 2012

Really? Why? Has it been decided to move to nominal for everything? Or does 'structural records' just not mean what I think it means in the context of this issue?

@brson

This comment has been minimized.

Copy link
Contributor Author

brson commented Aug 2, 2012

It has been decided. The primary reason is because they don't work well with the new impl coherence rules. In particular, I believe it's not possible to define anonymous impls (that don't fulfill explicit traits) for structural records because no module is responsible for defining the type.

yjh0502 added a commit to yjh0502/rust that referenced this issue Feb 27, 2013

Fix issue rust-lang#3212: Allow empty structure
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,

      struct Foo { mut a: int };
      let a = Foo { mut a: 1 };

      This is because of structural record, which is
      deprecated corrently (see issue rust-lang#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,

match x{} {}

Two interpretation is possible, which is listed blow

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.

enum what { }
fn match_with_empty(x: what) -> ~str {
    match (x) { //use parentheses to remove the ambiguity
    }
}

bors added a commit that referenced this issue Mar 2, 2013

auto merge of #5137 : yjh0502/rust/empty_struct, r=nikomatsakis
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
    }
}
```
@bstrie

This comment has been minimized.

Copy link
Contributor

bstrie commented Mar 7, 2013

I think this can be closed now.

@brson

This comment has been minimized.

Copy link
Contributor Author

brson commented Mar 7, 2013

Yay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.