Commit Graph

641 Commits

Author SHA1 Message Date
Luqman Aden
26e547af5d libsyntax: Remove all uses of {:?}. 2014-10-16 11:15:34 -04:00
Alex Crichton
412f4d1fc7 rollup merge of #17927 : alexcrichton/more-const 2014-10-13 15:09:25 -07:00
bors
c7e0724274 auto merge of #17733 : jgallagher/rust/while-let, r=alexcrichton
This is *heavily* based on `if let` (#17634) by @jakub- and @kballard

This should close #17687
2014-10-13 19:37:40 +00:00
Alex Crichton
18e41299f9 rustc: Warn about dead constants
A few catch-all blocks ended up not having this case for constants.

Closes #17925
2014-10-12 12:15:22 -07:00
Jakub Wieczorek
403cd40e6a Remove virtual structs from the language 2014-10-11 19:42:26 +02:00
John Gallagher
b003f10449 Desugar while let into loop { match { ... } } 2014-10-10 20:30:32 -04:00
John Gallagher
0c2c8116a3 Teach libsyntax about while let 2014-10-10 20:30:31 -04:00
Alex Crichton
edf8841642 syntax: Convert statics to constants 2014-10-09 09:44:51 -07:00
Alex Crichton
90d03d7926 rustc: Add const globals to the language
This change is an implementation of [RFC 69][rfc] which adds a third kind of
global to the language, `const`. This global is most similar to what the old
`static` was, and if you're unsure about what to use then you should use a
`const`.

The semantics of these three kinds of globals are:

* A `const` does not represent a memory location, but only a value. Constants
  are translated as rvalues, which means that their values are directly inlined
  at usage location (similar to a #define in C/C++). Constant values are, well,
  constant, and can not be modified. Any "modification" is actually a
  modification to a local value on the stack rather than the actual constant
  itself.

  Almost all values are allowed inside constants, whether they have interior
  mutability or not. There are a few minor restrictions listed in the RFC, but
  they should in general not come up too often.

* A `static` now always represents a memory location (unconditionally). Any
  references to the same `static` are actually a reference to the same memory
  location. Only values whose types ascribe to `Sync` are allowed in a `static`.
  This restriction is in place because many threads may access a `static`
  concurrently. Lifting this restriction (and allowing unsafe access) is a
  future extension not implemented at this time.

* A `static mut` continues to always represent a memory location. All references
  to a `static mut` continue to be `unsafe`.

This is a large breaking change, and many programs will need to be updated
accordingly. A summary of the breaking changes is:

* Statics may no longer be used in patterns. Statics now always represent a
  memory location, which can sometimes be modified. To fix code, repurpose the
  matched-on-`static` to a `const`.

      static FOO: uint = 4;
      match n {
          FOO => { /* ... */ }
          _ => { /* ... */ }
      }

  change this code to:

      const FOO: uint = 4;
      match n {
          FOO => { /* ... */ }
          _ => { /* ... */ }
      }

* Statics may no longer refer to other statics by value. Due to statics being
  able to change at runtime, allowing them to reference one another could
  possibly lead to confusing semantics. If you are in this situation, use a
  constant initializer instead. Note, however, that statics may reference other
  statics by address, however.

* Statics may no longer be used in constant expressions, such as array lengths.
  This is due to the same restrictions as listed above. Use a `const` instead.

[breaking-change]

[rfc]: https://github.com/rust-lang/rfcs/pull/246
2014-10-09 09:44:50 -07:00
Eduard Burtescu
d1a57e479c syntax: ast: remove TyBox and UnBox. 2014-10-02 16:36:01 +03:00
Kevin Ballard
976438f78f Produce a better error for irrefutable if let patterns
Modify ast::ExprMatch to include a new value of type ast::MatchSource,
making it easy to tell whether the match was written literally or
produced via desugaring. This allows us to customize error messages
appropriately.
2014-09-30 18:54:02 +02:00
Kevin Ballard
5d8cfd53b5 Teach libsyntax about if let 2014-09-30 18:54:02 +02:00
Keegan McAllister
8826fdfe37 Keep ExpnId abstract by providing conversions 2014-09-28 09:25:48 -07:00
Keegan McAllister
9d60de93e2 Translate inline assembly errors back to source locations
Fixes #17552.
2014-09-27 11:10:37 -07:00
Jakub Wieczorek
3530e4a647 Use more descriptive names in dead code messages 2014-09-24 21:03:55 +02:00
Patrick Walton
5376b1c798 librustc: Parse and resolve higher-rank lifetimes in traits.
They will ICE during typechecking if used, because they depend on trait
reform.

This is part of unboxed closures.
2014-09-22 21:14:58 -07:00
Alex Crichton
81ee3586b5 rollup merge of #17318 : nick29581/slice 2014-09-19 10:00:24 -07:00
Alex Crichton
b94075c9ce rollup merge of #17314 : eddyb/span-no-gc 2014-09-19 10:00:21 -07:00
Patrick Walton
7c00d77e8b librustc: Implement the syntax in the RFC for unboxed closure sugar.
Part of issue #16640. I am leaving this issue open to handle parsing of
higher-rank lifetimes in traits.

This change breaks code that used unboxed closures:

* Instead of `F:|&: int| -> int`, write `F:Fn(int) -> int`.

* Instead of `F:|&mut: int| -> int`, write `F:FnMut(int) -> int`.

* Instead of `F:|: int| -> int`, write `F:FnOnce(int) -> int`.

[breaking-change]
2014-09-18 16:31:58 -07:00
Nick Cameron
31a7e38759 Implement slicing syntax.
`expr[]`, `expr[expr..]`, `expr[..expr]`,`expr[expr..expr]`

Uses the Slice and SliceMut traits.

Allows ... as well as .. in range patterns.
2014-09-19 11:15:49 +12:00
Eduard Burtescu
f1a8f53cf1 Fix fallout in tests from removing the use of Gc in ExpnInfo. 2014-09-18 14:36:18 +03:00
Patrick Walton
78a841810e librustc: Implement associated types behind a feature gate.
The implementation essentially desugars during type collection and AST
type conversion time into the parameter scheme we have now. Only fully
qualified names--e.g. `<T as Foo>::Bar`--are supported.
2014-09-17 16:38:57 -07:00
Eduard Burtescu
d6fb338d01 syntax: ast_map: use borrowed references into the AST. 2014-09-14 03:39:36 +03:00
Eduard Burtescu
cccb6f84a3 syntax: ast: replace Gc<T> (previously @T) with P<T>. 2014-09-14 03:39:35 +03:00
Eduard Burtescu
1872c4c6b5 syntax: add a custom owned smart pointer in ptr::P. 2014-09-14 03:39:35 +03:00
P1start
bf274bc18b Implement tuple and tuple struct indexing
This allows code to access the fields of tuples and tuple structs:

    let x = (1i, 2i);
    assert_eq!(x.1, 2);

    struct Point(int, int);
    let origin = Point(0, 0);
    assert_eq!(origin.0, 0);
    assert_eq!(origin.1, 0);
2014-09-10 10:25:12 +12:00
Pythoner6
373b9d6243 Add support for labeled while loops. 2014-08-29 23:43:55 -04:00
P1start
de7abd8824 Unify non-snake-case lints and non-uppercase statics lints
This unifies the `non_snake_case_functions` and `uppercase_variables` lints
into one lint, `non_snake_case`. It also now checks for non-snake-case modules.
This also extends the non-camel-case types lint to check type parameters, and
merges the `non_uppercase_pattern_statics` lint into the
`non_uppercase_statics` lint.

Because the `uppercase_variables` lint is now part of the `non_snake_case`
lint, all non-snake-case variables that start with lowercase characters (such
as `fooBar`) will now trigger the `non_snake_case` lint.

New code should be updated to use the new `non_snake_case` lint instead of the
previous `non_snake_case_functions` and `uppercase_variables` lints. All use of
the `non_uppercase_pattern_statics` should be replaced with the
`non_uppercase_statics` lint. Any code that previously contained non-snake-case
module or variable names should be updated to use snake case names or disable
the `non_snake_case` lint. Any code with non-camel-case type parameters should
be changed to use camel case or disable the `non_camel_case_types` lint.

[breaking-change]
2014-08-30 09:10:05 +12:00
Niko Matsakis
1b487a8906 Implement generalized object and type parameter bounds (Fixes #16462) 2014-08-27 21:46:52 -04:00
Nick Cameron
3e626375d8 DST coercions and DST structs
[breaking-change]

1. The internal layout for traits has changed from (vtable, data) to (data, vtable). If you were relying on this in unsafe transmutes, you might get some very weird and apparently unrelated errors. You should not be doing this! Prefer not to do this at all, but if you must, you should use raw::TraitObject rather than hardcoding rustc's internal representation into your code.

2. The minimal type of reference-to-vec-literals (e.g., `&[1, 2, 3]`) is now a fixed size vec (e.g., `&[int, ..3]`) where it used to be an unsized vec (e.g., `&[int]`). If you want the unszied type, you must explicitly give the type (e.g., `let x: &[_] = &[1, 2, 3]`). Note in particular where multiple blocks must have the same type (e.g., if and else clauses, vec elements), the compiler will not coerce to the unsized type without a hint. E.g., `[&[1], &[1, 2]]` used to be a valid expression of type '[&[int]]'. It no longer type checks since the first element now has type `&[int, ..1]` and the second has type &[int, ..2]` which are incompatible.

3. The type of blocks (including functions) must be coercible to the expected type (used to be a subtype). Mostly this makes things more flexible and not less (in particular, in the case of coercing function bodies to the return type). However, in some rare cases, this is less flexible. TBH, I'm not exactly sure of the exact effects. I think the change causes us to resolve inferred type variables slightly earlier which might make us slightly more restrictive. Possibly it only affects blocks with unreachable code. E.g., `if ... { fail!(); "Hello" }` used to type check, it no longer does. The fix is to add a semicolon after the string.
2014-08-26 12:38:51 +12:00
Piotr Czarnecki
4155643428 Fix double evaluation of read+write operands
Stop read+write expressions from expanding into two occurences
in the AST. Add a bool to indicate whether an operand in output
position if read+write or not.

Fixes #14936
2014-08-19 20:39:26 +01:00
bors
36db3866c0 auto merge of #16424 : pcwalton/rust/where-clauses, r=nikomatsakis
These `where` clauses are accepted everywhere generics are currently
accepted and desugar during type collection to the type parameter bounds
we have today.

A new keyword, `where`, has been added. Therefore, this is a breaking
change. Change uses of `where` to other identifiers.

[breaking-change]

r? @nikomatsakis (or whoever)
2014-08-15 06:26:23 +00:00
Patrick Walton
604af3f6c0 librustc: Implement simple where clauses.
These `where` clauses are accepted everywhere generics are currently
accepted and desugar during type collection to the type parameter bounds
we have today.

A new keyword, `where`, has been added. Therefore, this is a breaking
change. Change uses of `where` to other identifiers.

[breaking-change]
2014-08-14 14:14:26 -07:00
bors
f8e0ede921 auto merge of #16468 : pcwalton/rust/as-renaming-import, r=alexcrichton
The old syntax will be removed after a snapshot.

RFC #47.

Issue #16461.

r? @brson
2014-08-14 21:01:19 +00:00
Patrick Walton
1c16accfc2 libsyntax: Accept use foo as bar; in lieu of use bar as foo;
The old syntax will be removed after a snapshot.

RFC #47.

Issue #16461.
2014-08-14 13:24:50 -07:00
Patrick Walton
9907fa4acc librustc: Stop assuming that implementations and traits only contain
methods.

This paves the way to associated items by introducing an extra level of
abstraction ("impl-or-trait item") between traits/implementations and
methods. This new abstraction is encoded in the metadata and used
throughout the compiler where appropriate.

There are no functional changes; this is purely a refactoring.
2014-08-14 11:40:22 -07:00
Patrick Walton
8d27232141 librustc: Tie up loose ends in unboxed closures.
This patch primarily does two things: (1) it prevents lifetimes from
leaking out of unboxed closures; (2) it allows unboxed closure type
notation, call notation, and construction notation to construct closures
matching any of the three traits.

This breaks code that looked like:

    let mut f;
    {
        let x = &5i;
        f = |&mut:| *x + 10;
    }

Change this code to avoid having a reference escape. For example:

    {
        let x = &5i;
        let mut f; // <-- move here to avoid dangling reference
        f = |&mut:| *x + 10;
    }

I believe this is enough to consider unboxed closures essentially
implemented. Further issues (for example, higher-rank lifetimes) should
be filed as followups.

Closes #14449.

[breaking-change]
2014-08-14 08:53:25 -07:00
bors
9d45d63d0d auto merge of #15929 : pcwalton/rust/by-ref-closures, r=alexcrichton
by-reference upvars.

This partially implements RFC 38. A snapshot will be needed to turn this
on, because stage0 cannot yet parse the keyword.

Part of #12831.

r? @alexcrichton
2014-08-14 03:46:22 +00:00
Patrick Walton
a63003fe1a librustc: Parse, but do not fully turn on, the ref keyword for
by-reference upvars.

This partially implements RFC 38. A snapshot will be needed to turn this
on, because stage0 cannot yet parse the keyword.

Part of #12381.
2014-08-13 18:09:14 -07:00
Felix S. Klock II
c3ce245ba6 quote_expr macro: embed Ident using special encoding that preserves hygiene.
This adds support to `quote_expr!` and friends for round-trip hygienic
preservation of Ident.

Here are the pieces of the puzzle:

* adding a method for encoding Ident for re-reading into token tree.

* Support for reading such encoded Idents in the lexer.  Note that one
  must peek ahead for MOD_SEP after scan_embedded_hygienic_ident.

* To ensure that encoded Idents are only read when we are in the midst
  of expanding a `quote_expr` or similar, added a
  `read_embedded_ident` flag on `StringReader`.

* pprust support for encoding Ident's as (uint,uint) pairs (for hygiene).
2014-08-13 17:40:15 +02:00
bors
aae7901a78 auto merge of #16285 : alexcrichton/rust/rename-share, r=huonw
This leaves the `Share` trait at `std::kinds` via a `#[deprecated]` `pub use`
statement, but the `NoShare` struct is no longer part of `std::kinds::marker`
due to #12660 (the build cannot bootstrap otherwise).

All code referencing the `Share` trait should now reference the `Sync` trait,
and all code referencing the `NoShare` type should now reference the `NoSync`
type. The functionality and meaning of this trait have not changed, only the
naming.

Closes #16281
[breaking-change]
2014-08-08 03:51:15 +00:00
Alex Crichton
1f760d5d1a Rename Share to Sync
This leaves the `Share` trait at `std::kinds` via a `#[deprecated]` `pub use`
statement, but the `NoShare` struct is no longer part of `std::kinds::marker`
due to #12660 (the build cannot bootstrap otherwise).

All code referencing the `Share` trait should now reference the `Sync` trait,
and all code referencing the `NoShare` type should now reference the `NoSync`
type. The functionality and meaning of this trait have not changed, only the
naming.

Closes #16281
[breaking-change]
2014-08-07 08:54:38 -07:00
Niko Matsakis
fcab98038c Temporary bootstrapping hack: introduce syntax for r egion bounds like 'b:'a,
meaning `'b outlives 'a`. Syntax currently does nothing but is needed for full
fix to #5763. To use this syntax, the issue_5763_bootstrap feature guard is
required.
2014-08-07 07:23:59 -04:00
Felix S. Klock II
d3202354f5 AST refactoring: merge PatWild and PatWildMulti into one variant with a flag. 2014-08-06 17:04:44 +02:00
Falco Hirschenberger
0dc215741b Fixes missing overflow lint for i64 #14269
The `type_overflow` lint, doesn't catch the overflow for `i64` because
the overflow happens earlier in the parse phase when the `u64` as biggest
possible int gets casted to `i64` , without checking the for overflows.
We can't lint in the parse phase, so a refactoring of the `LitInt` type
was necessary.

The types `LitInt`, `LitUint` and `LitIntUnsuffixed` where merged to one
type `LitInt` which stores it's value as `u64`. An additional parameter was
added which indicate the signedness of the type and the sign of the value.
2014-08-05 09:59:03 +02:00
bors
8c00357f9d auto merge of #15999 : Kimundi/rust/fix_folder, r=nikomatsakis
Note: This PR is motivated by an attempt to write an custom syntax extension that tried to use `syntax::fold`, and that could only do so by fixing bugs in it and copying out private functions.

---

Refactored `syntax::fold`

Prior to this, the code there had a few issues:

- Default implementations inconsistenly either had the prefix `noop_` or
  not.
- Some default methods where implemented in terms of a public noop function
  for user code to call, others where implemented directly on the trait
  and did not allow users of the trait to reuse the code.
- Some of the default implementations where private, and thus not reusable
  for other implementors.
- There where some bugs where default implemntations called other default
  implementations directly, rather than to the underlying Folder, with the
  result of some ast nodes never being visted even if the user implemented that
  method. (For example, the current Folder never folded struct fields)

This commit solves this situation somewhat radically by making __all__
`fold_...` functions in the module into Folder methods, and implementing
them all in terms of public `noop_...` functions for other implementors to
call out to.

Some public functions had to be renamed to fit the new system, so this is a
breaking change.

---

Also added a few trait implementations to `ast` types
2014-07-31 16:41:36 +00:00
Erick Tryzelaar
a46463d179 syntax: promote a comment on PatEnum into a docstring 2014-07-29 15:51:03 -07:00
Marvin Löbel
da6070dbef Add a few more derivings to AST types 2014-07-29 12:32:32 +02:00
Marvin Löbel
26a39f23ce Refactored syntax::fold.
Prior to this, the code there had a few issues:

- Default implementations inconsistently either had the prefix `noop_` or
  not.
- Some default methods where implemented in terms of a public noop function
  for user code to call, others where implemented directly on the trait
  and did not allow users of the trait to reuse the code.
- Some of the default implementations where private, and thus not reusable
  for other implementors.
- There where some bugs where default implementations called other default
  implementations directly, rather than to the underlying Folder, with the
  result of some AST nodes never being visited even if the user implemented that
  method. (For example, the current Folder never folded struct fields)

This commit solves this situation somewhat radically by making _all_
`fold_...` functions in the module into Folder methods, and implementing
them all in terms of public `noop_...` functions for other implementors to
call out to.

Some public functions had to be renamed to fit the new system, so this is a
breaking change.

[breaking-change]
2014-07-29 12:31:53 +02:00
Patrick Walton
bb165eb5c2 libsyntax: Remove ~self and mut ~self from the language.
This eliminates the last vestige of the `~` syntax.

Instead of `~self`, write `self: Box<TypeOfSelf>`; instead of `mut
~self`, write `mut self: Box<TypeOfSelf>`, replacing `TypeOfSelf` with
the self-type parameter as specified in the implementation.

Closes #13885.

[breaking-change]
2014-07-24 07:26:03 -07:00