diff options
| author | bors <bors@rust-lang.org> | 2013-03-02 04:21:38 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-03-02 04:21:38 -0800 |
| commit | 5aca7d6aef2f5e18b640d918b243a71fc893a65b (patch) | |
| tree | 01f7955c31e98292ddb8b73bdea107a853806d31 /src/libcore | |
| parent | d3b94f6f341e935910aff59ea187af7b34055be8 (diff) | |
| parent | 95bc9ea26df56b29f74583317ab080fdc7b99757 (diff) | |
| download | rust-5aca7d6aef2f5e18b640d918b243a71fc893a65b.tar.gz rust-5aca7d6aef2f5e18b640d918b243a71fc893a65b.zip | |
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
}
}
```
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/dvec.rs | 8 | ||||
| -rw-r--r-- | src/libcore/os.rs | 18 | ||||
| -rw-r--r-- | src/libcore/ptr.rs | 6 |
3 files changed, 18 insertions, 14 deletions
diff --git a/src/libcore/dvec.rs b/src/libcore/dvec.rs index 1fef4ad42f1..7197de36404 100644 --- a/src/libcore/dvec.rs +++ b/src/libcore/dvec.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -62,17 +62,17 @@ pub struct DVec<A> { /// Creates a new, empty dvec pub pure fn DVec<A>() -> DVec<A> { - DVec {mut data: ~[]} + DVec {data: ~[]} } /// Creates a new dvec with a single element pub pure fn from_elem<A>(e: A) -> DVec<A> { - DVec {mut data: ~[e]} + DVec {data: ~[e]} } /// Creates a new dvec with the contents of a vector pub pure fn from_vec<A>(v: ~[A]) -> DVec<A> { - DVec {mut data: v} + DVec {data: v} } /// Consumes the vector and returns its contents diff --git a/src/libcore/os.rs b/src/libcore/os.rs index 5ede0c550ff..cf74ec6d77a 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -321,8 +321,8 @@ pub struct Pipe { mut in: c_int, mut out: c_int } #[cfg(unix)] pub fn pipe() -> Pipe { unsafe { - let mut fds = Pipe {mut in: 0 as c_int, - mut out: 0 as c_int }; + let mut fds = Pipe {in: 0 as c_int, + out: 0 as c_int }; assert (libc::pipe(&mut fds.in) == (0 as c_int)); return Pipe {in: fds.in, out: fds.out}; } @@ -338,8 +338,8 @@ pub fn pipe() -> Pipe { // fully understand. Here we explicitly make the pipe non-inheritable, // which means to pass it to a subprocess they need to be duplicated // first, as in rust_run_program. - let mut fds = Pipe { mut in: 0 as c_int, - mut out: 0 as c_int }; + let mut fds = Pipe {in: 0 as c_int, + out: 0 as c_int }; let res = libc::pipe(&mut fds.in, 1024 as c_uint, (libc::O_BINARY | libc::O_NOINHERIT) as c_int); assert (res == 0 as c_int); @@ -565,13 +565,17 @@ pub fn path_exists(p: &Path) -> bool { * * If the given path is relative, return it prepended with the current working * directory. If the given path is already an absolute path, return it - * as is. This is a shortcut for calling os::getcwd().unsafe_join(p) + * as is. */ // NB: this is here rather than in path because it is a form of environment // querying; what it does depends on the process working directory, not just // the input paths. pub fn make_absolute(p: &Path) -> Path { - getcwd().unsafe_join(p) + if p.is_absolute { + copy *p + } else { + getcwd().push_many(p.components) + } } diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 5a7b319e7ff..ecbce18e6da 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -300,7 +300,7 @@ impl<T:Ord> Ord for &const T { pub fn test() { unsafe { struct Pair {mut fst: int, mut snd: int}; - let mut p = Pair {mut fst: 10, mut snd: 20}; + let mut p = Pair {fst: 10, snd: 20}; let pptr: *mut Pair = &mut p; let iptr: *mut int = cast::reinterpret_cast(&pptr); assert (*iptr == 10);; @@ -308,7 +308,7 @@ pub fn test() { assert (*iptr == 30); assert (p.fst == 30);; - *pptr = Pair {mut fst: 50, mut snd: 60}; + *pptr = Pair {fst: 50, snd: 60}; assert (*iptr == 50); assert (p.fst == 50); assert (p.snd == 60); |
