Commit Graph

212 Commits

Author SHA1 Message Date
Eduard Burtescu
b2d30b72bf Removed @self and @Trait. 2014-02-07 00:38:33 +02:00
Jeff Olson
b8852e89ce pull extra::{serialize, ebml} into a separate libserialize crate
- `extra::json` didn't make the cut, because of `extra::json` required
   dep on `extra::TreeMap`. If/when `extra::TreeMap` moves out of `extra`,
   then `extra::json` could move into `serialize`
- `libextra`, `libsyntax` and `librustc` depend on the newly created
  `libserialize`
- The extensions to various `extra` types like `DList`, `RingBuf`, `TreeMap`
  and `TreeSet` for `Encodable`/`Decodable` were moved into the respective
  modules in `extra`
- There is some trickery, evident in `src/libextra/lib.rs` where a stub
  of `extra::serialize` is set up (in `src/libextra/serialize.rs`) for
  use in the stage0 build, where the snapshot rustc is still making
  deriving for `Encodable` and `Decodable` point at extra. Big props to
  @huonw for help working out the re-export solution for this

extra: inline extra::serialize stub

fix stuff clobbered in rebase + don't reexport serialize::serialize

no more globs in libserialize

syntax: fix import of libserialize traits

librustc: fix bad imports in encoder/decoder

add serialize dep to librustdoc

fix failing run-pass tests w/ serialize dep

adjust uuid dep

more rebase de-clobbering for libserialize

fixing tests, pushing libextra dep into cfg(test)

fix doc code in extra::json

adjust index.md links to serialize and uuid library
2014-02-05 10:38:22 -08:00
Patrick Walton
c5cbfe89f8 librustc: De-@str NameAndSpan 2014-02-02 01:44:48 +11:00
Patrick Walton
a4dd3fe2f2 librustc: Fix merge fallout. 2014-02-02 01:44:48 +11:00
Patrick Walton
8e52b85d5a libsyntax: De-@str literal strings in the AST 2014-02-02 01:44:48 +11:00
Patrick Walton
70c5a0fbf7 libsyntax: Introduce an InternedString type to reduce @str in the
compiler and use it for attributes
2014-02-02 01:44:47 +11:00
Virgile Andreani
b9a026afba Fix minor doc typos 2014-01-31 21:43:07 -08:00
Eduard Burtescu
7d967741c3 Implement default type parameters in generics. 2014-01-30 19:28:41 +02:00
bors
d21b18306c auto merge of #11826 : huonw/rust/7621-deriving-errors, r=alexcrichton
cc #7621.

See the commit message. I'm not sure if we should merge this now, or wait until we can write `Clone::clone(x)` which will directly solve the above issue with perfect error messages.
2014-01-27 20:26:35 -08:00
Huon Wilson
cb02a37042 syntax: make deriving have slightly less cryptic error messages.
This unfortunately changes an error like

    error: mismatched types: expected `&&NotClone` but found `&NotClone`

into

    error: type `NotClone` does not implement any method in scope named `clone`
2014-01-28 11:07:45 +11:00
Eduard Burtescu
15ba0c310a Demote self to an (almost) regular argument and remove the env param.
Fixes #10667 and closes #10259.
2014-01-27 14:31:24 +02:00
Huon Wilson
b079ebeb8d syntax: improve the spans of some #[deriving] traits.
This makes error messages about (e.g.) `#[deriving(Clone)] struct Foo {
x: Type }` point at `x: Type` rather than `Clone` in the header (while
still referring to the `#[deriving(Clone)]` in the expansion info).
2014-01-27 15:25:37 +11:00
Huon Wilson
0b7f823156 syntax: Fix a missing closing code tag in docs. 2014-01-26 23:39:32 +11:00
Simon Sapin
bada25e425 [std::vec] Rename .pop_opt() to .pop(), drop the old .pop() behavior 2014-01-21 15:48:47 -08:00
Simon Sapin
aa66b91767 [std::vec] Rename .last_opt() to .last(), drop the old .last() behavior 2014-01-21 15:48:46 -08:00
Huon Wilson
4be3262058 syntax::ext: replace span_fatal with span_err in many places.
This means that compilation continues for longer, and so we can see more
errors per compile. This is mildly more user-friendly because it stops
users having to run rustc n times to see n macro errors: just run it
once to see all of them.
2014-01-18 02:03:04 +11:00
Steven Fackler
328b47d837 Load macros from external modules 2014-01-16 15:01:48 -08:00
Eduard Burtescu
509fc92a9b Removed remnants of @mut and ~mut from comments and the type system. 2014-01-12 02:26:04 +02:00
Eduard Burtescu
6b221768cf libsyntax: Renamed types, traits and enum variants to CamelCase. 2014-01-09 22:25:28 +02:00
bors
430652c970 auto merge of #11370 : alexcrichton/rust/issue-10465, r=pwalton
Turned out to be a 2-line fix, but the compiler fallout was huge.
2014-01-08 10:06:45 -08:00
Alex Crichton
c4d36b85a0 Fix remaining cases of leaking imports 2014-01-07 23:51:38 -08:00
Brian Anderson
d323632669 'borrowed pointer' -> 'reference' 2014-01-07 18:49:13 -08:00
Patrick Walton
82a09b9a04 librustc: Remove @mut support from the parser 2014-01-03 14:02:01 -08:00
Steven Fackler
0607c138ca Stop using @ExtCtxt 2013-12-28 21:16:03 -07:00
Erik Price
5731ca3078 Make 'self lifetime illegal.
Also remove all instances of 'self within the codebase.

This fixes #10889.
2013-12-11 10:54:06 -08:00
Huon Wilson
0c0e73eed6 syntax::deriving: indicate from which trait type errors (etc) arise
using the expansion info.

Previously something like

    struct NotEq;

    #[deriving(Eq)]
    struct Error {
        foo: NotEq
    }

would just point to the `foo` field, with no mention of the
`deriving(Eq)`. With this patch, the compiler creates a note saying "in
expansion of #[deriving(Eq)]" pointing to the Eq.
2013-12-07 13:43:22 +11:00
Huon Wilson
09a879460c syntax::deriving: add the cx and span to the TraitDef to reduce duplication. 2013-12-07 11:57:44 +11:00
Eduard Burtescu
a9c4b18b18 Box Block, fn_decl, variant and Ty in the AST, as they were inflating critical enum sizes. 2013-12-01 00:00:39 +02:00
Alex Crichton
ab387a6838 Register new snapshots 2013-11-28 20:27:56 -08:00
Patrick Walton
efc512362b libsyntax: Remove all non-proc do syntax. 2013-11-26 08:24:18 -08:00
Patrick Walton
9e610573ba librustc: Remove remaining uses of &fn() in favor of ||. 2013-11-26 08:20:58 -08:00
Patrick Walton
492677ec1e libsyntax: Change all uses of &fn to ||. 2013-11-19 12:40:19 -08:00
Huon Wilson
df0f50381c Mark some derived methods as #[inline].
ToStr, Encodable and Decodable are not marked as such, since they're
already expensive, and lead to large methods, so inlining will bloat the
metadata & the binaries.

This means that something like

    #[deriving(Eq)]
    struct A { x: int }

creates an instance like

    #[doc = "Automatically derived."]
    impl ::std::cmp::Eq for A {
        #[inline]
        fn eq(&self, __arg_0: &A) -> ::bool {
            match *__arg_0 {
                A{x: ref __self_1_0} =>
                match *self {
                    A{x: ref __self_0_0} => true && __self_0_0.eq(__self_1_0)
                }
            }
        }
        #[inline]
        fn ne(&self, __arg_0: &A) -> ::bool {
            match *__arg_0 {
                A{x: ref __self_1_0} =>
                match *self {
                    A{x: ref __self_0_0} => false || __self_0_0.ne(__self_1_0)
                }
            }
        }
    }

(The change being the `#[inline]` attributes.)
2013-11-19 11:18:34 +11:00
Niko Matsakis
1f4faaee40 Generalize AST and ty::Generics to accept multiple lifetimes. 2013-11-08 19:42:46 -05:00
Huon Wilson
812ea9e169 syntax::ext: Make type errors in deriving point to the field itself.
This rearranges the deriving code so that #[deriving] a trait on a field
that doesn't implement that trait will point to the field in question,
e.g.

    struct NotEq; // doesn't implement Eq

    #[deriving(Eq)]
    struct Foo {
        ok: int,
        also_ok: ~str,
        bad: NotEq // error points here.
    }

Unfortunately, this means the error is disconnected from the `deriving`
itself but there's no current way to pass that information through to
rustc except via the spans, at the moment.

Fixes #7724.
2013-11-08 20:57:34 +11:00
Luqman Aden
12308db3d2 libsyntax/librustc: Allow mut qualifier in patterns. 2013-10-25 01:21:07 -04:00
Luqman Aden
af163579ed libsyntax/librustc: Allow specifying mut on ~self. 2013-10-22 21:22:19 -04:00
Luqman Aden
5754848f8c libsyntax/librustc: Allow specifying mut on by-value self. 2013-10-22 21:21:21 -04:00
Brian Anderson
3675e42334 std: Move sys::log_str to repr::repr_to_str. Further work on #2240. 2013-10-21 11:59:23 -07:00
Daniel Micay
6a90e80b62 option: rewrite the API to use composition 2013-10-09 09:17:29 -04:00
Benjamin Herr
9d7b130041 add new enum ast::StrStyle as field to ast::lit_str
For the benefit of the pretty printer we want to keep track of how
string literals in the ast were originally represented in the source
code.

This commit changes parser functions so they don't extract strings from
the token stream without at least also returning what style of string
literal it was. This is stored in the resulting ast node for string
literals, obviously, for the package id in `extern mod = r"package id"`
view items, for the inline asm in `asm!()` invocations.

For `asm!()`'s other arguments or for `extern "Rust" fn()` items, I just
the style of string, because it seemed disproportionally cumbersome to
thread that information through the string processing that happens with
those string literals, given the limited advantage raw string literals
would provide in these positions.

The other syntax extensions don't seem to store passed string literals
in the ast, so they also discard the style of strings they parse.
2013-10-08 03:43:28 +02:00
Erick Tryzelaar
9de7ad2d8c std: Swap {To,From}Primitive to use the 64bit as the unimplemented version
One downside with this current implementation is that since BigInt's
default is now 64 bit, we can convert larger BigInt's to a primitive,
however the current implementation on 32 bit architectures does not
take advantage of this fact.
2013-10-02 07:55:42 -07:00
Erick Tryzelaar
8f8cc061d9 syntax: swap from .span_fatal to .span_err in #[deriving(FromPrimitive)] 2013-10-02 07:55:41 -07:00
Erick Tryzelaar
0feaccf526 syntax: Add #[deriving(FromPrimitive)] syntax extension
Right now this only works for c-style enums.
2013-10-02 07:55:41 -07:00
Huon Wilson
8284df9e7c syntax: indicate an error when a macro ignores trailing tokens.
That is, only a single expression or item gets parsed, so if there are
any extra tokens (e.g. the start of another item/expression) the user
should be told, rather than silently dropping them.

An example:

    macro_rules! foo {
        () => {
            println("hi");
            println("bye);
        }
    }

would expand to just `println("hi")`, which is almost certainly not
what the programmer wanted.

Fixes #8012.
2013-10-02 14:43:15 +10:00
Alex Crichton
af3b132285 syntax: Remove usage of fmt! 2013-09-30 23:21:19 -07:00
Alex Crichton
3585c64d09 rustdoc: Change all code-blocks with a script
find src -name '*.rs' | xargs sed -i '' 's/~~~.*{\.rust}/```rust/g'
    find src -name '*.rs' | xargs sed -i '' 's/ ~~~$/ ```/g'
    find src -name '*.rs' | xargs sed -i '' 's/^~~~$/ ```/g'
2013-09-25 14:27:42 -07:00
Erick Tryzelaar
1a90f24bbd extra: minor cleanup of Zero and Default syntax extension 2013-09-17 21:02:17 -07:00
Erick Tryzelaar
a0e123eb6e syntax: add #[deriving(Default)] syntax extension 2013-09-12 18:54:13 -07:00
bors
753d8c226c auto merge of #9088 : nikomatsakis/rust/issue-6304-AST-tree-not-DAG, r=catamorphism
Ensures that each AST node has a unique id. Fixes numerous bugs in macro expansion and deriving. Add two
representative tests.

Fixes #7971
Fixes #6304
Fixes #8367
Fixes #8754
Fixes #8852
Fixes #2543
Fixes #7654
2013-09-10 03:10:59 -07:00
Niko Matsakis
a5ad4c3794 Delay assignment of node ids until after expansion. Ensures that each AST node
has a unique id. Fixes numerous bugs in macro expansion and deriving. Add two
representative tests.

Fixes #7971
Fixes #6304
Fixes #8367
Fixes #8754
Fixes #8852
Fixes #2543
Fixes #7654
2013-09-10 05:45:12 -04:00
blake2-ppc
c11ee0fb67 std::at_vec and vec: Unify build_sized, build_sized_opt into build
These functions have very few users since they are mostly replaced by
iterator-based constructions.

Convert a few remaining users in-tree, and reduce the number of
functions by basically renaming build_sized_opt to build, and removing
the other two. This for both the vec and the at_vec versions.
2013-09-10 05:50:11 +02:00
Marvin Löbel
7419085337 Modernized a few more types in syntax::ast 2013-09-03 14:45:06 +02:00
Marvin Löbel
857f867320 Renamed syntax::ast::ident -> Ident 2013-09-02 02:51:21 +02:00
Marvin Löbel
539f37925c Modernized a few type names in rustc and syntax 2013-09-01 14:43:26 +02:00
Patrick Walton
4f32a2d854 librustc: Fix merge fallout. 2013-08-27 18:47:57 -07:00
Patrick Walton
8693943676 librustc: Ensure that type parameters are in the right positions in paths.
This removes the stacking of type parameters that occurs when invoking
trait methods, and fixes all places in the standard library that were
relying on it. It is somewhat awkward in places; I think we'll probably
want something like the `Foo::<for T>::new()` syntax.
2013-08-27 18:47:57 -07:00
Alex Crichton
930885d5e5 Forbid pub/priv where it has no effect
Closes #5495
2013-08-12 23:20:46 -07:00
Erick Tryzelaar
68f40d215e std: Rename Iterator.transform -> .map
cc #5898
2013-08-10 07:33:21 -07:00
bors
4da1cfe923 auto merge of #8285 : huonw/rust/deriving+++, r=alexcrichton
Some general clean-up relating to deriving:
- `TotalOrd` was too eager, and evaluated the `.cmp` call for every field, even if it could short-circuit earlier.
- the pointer types didn't have impls for `TotalOrd` or `TotalEq`.
- the Makefiles didn't reach deep enough into libsyntax for dependencies.

(Split out from https://github.com/mozilla/rust/pull/8258.)
2013-08-07 00:56:18 -07:00
Marvin Löbel
0ac7a219f0 Updated std::Option, std::Either and std::Result
- Made naming schemes consistent between Option, Result and Either
- Changed Options Add implementation to work like the maybe monad (return None if any of the inputs is None)
- Removed duplicate Option::get and renamed all related functions to use the term `unwrap` instead
2013-08-05 22:42:21 +02:00
Huon Wilson
8407ec9fed syntax: make #[deriving(TotalOrd)] lazy.
Previously it would call:

  f(sf1.cmp(&of1), f(sf2.cmp(&of2), ...))

(where s/of1 = 'self/other field 1', and f was
std::cmp::lexical_ordering)

This meant that every .cmp subcall got evaluated when calling a derived
TotalOrd.cmp.

This corrects this to use

   let test = sf1.cmp(&of1);
   if test == Equal {
      let test = sf2.cmp(&of2);
      if test == Equal {
        // ...
      } else {
        test
      }
   } else {
     test
   }

This gives a lexical ordering by short-circuiting on the first comparison
that is not Equal.
2013-08-04 19:46:52 +10:00
Daniel Micay
1008945528 remove obsolete foreach keyword
this has been replaced by `for`
2013-08-03 22:48:02 -04:00
bors
2765811cb6 auto merge of #8206 : omasanori/rust/blk-to-block, r=graydon
Just for consistency.
2013-08-03 03:55:52 -07:00
Daniel Micay
234acad404 replace range with an external iterator 2013-08-02 00:51:14 -04:00
OGINO Masanori
09efc4e855 Replace 'blk' -> 'block' in AstBuilder.
I didn't rename variables because they are local and are not parts of
the public interfaces.

Signed-off-by: OGINO Masanori <masanori.ogino@gmail.com>
2013-08-02 09:12:05 +09:00
Daniel Micay
1fc4db2d08 migrate many for loops to foreach 2013-08-01 05:34:55 -04:00
Huon Wilson
cc760a647a syntax: modernise attribute handling in syntax::attr.
This does a number of things, but especially dramatically reduce the
number of allocations performed for operations involving attributes/
meta items:

- Converts ast::meta_item & ast::attribute and other associated enums
  to CamelCase.
- Converts several standalone functions in syntax::attr into methods,
  defined on two traits AttrMetaMethods & AttributeMethods. The former
  is common to both MetaItem and Attribute since the latter is a thin
  wrapper around the former.
- Deletes functions that are unnecessary due to iterators.
- Converts other standalone functions to use iterators and the generic
  AttrMetaMethods rather than allocating a lot of new vectors (e.g. the
  old code would have to allocate a new vector to use functions that
  operated on &[meta_item] on &[attribute].)
- Moves the core algorithm of the #[cfg] matching to syntax::attr,
  similar to find_inline_attr and find_linkage_metas.

This doesn't have much of an effect on the speed of #[cfg] stripping,
despite hugely reducing the number of allocations performed; presumably
most of the time is spent in the ast folder rather than doing attribute
checks.

Also fixes the Eq instance of MetaItem_ to correctly ignore spaces, so
that `rustc --cfg 'foo(bar)'` now works.
2013-07-20 01:06:16 +10:00
Patrick Walton
99b33f7219 librustc: Remove all uses of "copy". 2013-07-17 14:57:51 -07:00
Patrick Walton
b4e674f6e6 librustc: Add a lint mode for unnecessary copy and remove a bunch of them. 2013-07-17 14:56:42 -07:00
Niko Matsakis
0c6d02f391 Correct merge errors 2013-07-08 13:55:11 -04:00
Niko Matsakis
366a233dbd syntax: Patch up code that was using irrefutable patterns incorrectly 2013-07-08 13:53:44 -04:00
James Miller
47eca2113c De-share ast::Ty 2013-07-07 22:51:10 +12:00
James Miller
46a1f54666 De-manage OptVec<TyParamBounds> 2013-07-07 22:51:10 +12:00
James Miller
62c83bb17b De-manage Lifetime 2013-07-07 22:51:09 +12:00
James Miller
cd1b6c8979 De-managed ast::Path 2013-07-07 22:51:09 +12:00
Huon Wilson
c0a20d2929 Remove vec::{map, mapi, zip_map} and the methods, except for .map, since this
is very common, and the replacement (.iter().transform().collect()) is very
ugly.
2013-06-30 21:59:44 +10:00
Alex Crichton
3bad7129eb Remove mutability from unique boxes in the AST 2013-06-29 08:36:25 -07:00
Ben Blum
ff4ab9e147 'Borrow' stack closures rather than copying them (e.g., "|x|f(x)"), in prep for making them noncopyable. 2013-06-29 04:39:34 -04:00
Patrick Walton
1c0aa78481 librustc: Change "Owned" to "Send" everywhere 2013-06-28 10:44:15 -04:00
Philipp Brüschweiler
7295a6da92 Remove many shared pointers
Mostly just low-haning fruit, i.e. function arguments that were @ even
though & would work just as well.

Reduces librustc.so size by 200k when compiling without -O, by 100k when
compiling with -O.
2013-06-27 15:06:19 +02:00
Ben Blum
7b968783d7 Infer default static/Owned bounds for unbounded heap fns/traits (#7264) 2013-06-26 18:14:43 -04:00
bors
e9ac7194ff auto merge of #7365 : cmr/rust/syntax_cleanup, r=Aatch
Sets the stage for further cleanup (especially mass-slaughter of `@`)
2013-06-25 18:02:02 -07:00
Daniel Micay
5242e8d2ba remove the redundant each method from OptVec 2013-06-25 16:26:23 -04:00
Corey Richardson
0d471d310d great renaming propagation: syntax 2013-06-25 16:15:07 -04:00
Ben Blum
ce857e3d60 Parse and typecheck (not kindcheck) bounds on trait paths. 2013-06-23 14:40:14 -04:00
bors
3b126e4d6d auto merge of #7274 : thestinger/rust/size_hint, r=huonw
I ran into a weird lifetime bug blocking updating the `collect` method to use `FromIterator`, but everything here works fine.
2013-06-22 23:07:55 -07:00
Daniel Micay
d2e9912aea vec: remove BaseIter implementation
I removed the `static-method-test.rs` test because it was heavily based
on `BaseIter` and there are plenty of other more complex uses of static
methods anyway.
2013-06-23 02:05:20 -04:00
Alex Crichton
30d755957a Expand the deriving(ToStr) implementation 2013-06-22 09:53:17 -07:00
Daniel Micay
49c74524e2 vec: rm old_iter implementations, except BaseIter
The removed test for issue #2611 is well covered by the `std::iterator`
module itself.

This adds the `count` method to `IteratorUtil` to replace `EqIter`.
2013-06-21 03:20:22 -04:00
Graydon Hoare
d904c72af8 replace #[inline(always)] with #[inline]. r=burningtree. 2013-06-18 14:48:48 -07:00
bors
08c1155a22 auto merge of #7142 : alexcrichton/rust/deriving-zero, r=pcwalton
This allows mass-initialization of large structs without having to specify all the fields.

I'm a bit hesitant, but I wanted to get this out there. I don't really like using the `Zero` trait, because it doesn't really make sense for a type like `HashMap` to use `Zero` as the 'blank allocation' trait. In theory there'd be a new trait, but then that's adding cruft to the language which may not necessarily need to be there.

I do think that this can be useful, but I only implemented `Zero` on the basic types where I thought it made sense, so it may not be all that usable yet. (opinions?)
2013-06-16 01:52:09 -07:00
bors
c83bceddbb auto merge of #7121 : huonw/rust/rand-call, r=pnkfelix
r? @pnkfelix
2013-06-14 22:37:13 -07:00
Daniel Micay
585f5f7f79 add IteratorUtil to the prelude 2013-06-14 23:15:42 -04:00
Alex Crichton
07f5ab1009 Implement a deriving(Zero) attribute 2013-06-14 19:12:37 -07:00
Huon Wilson
e6c3e4a000 syntax: revert the uint -> u32 "fix"; make the names/comment match. 2013-06-14 11:12:06 +10:00
Huon Wilson
f93a974558 syntax: correct the Rand::rand call to select enum variants in #[deriving(Rand)].
Previously, this was not a global call, and so when `#[deriving(Rand)]`
was in any module other than the top-level one, it failed (unless there
was a `use std;` in scope).

Also, fix a minor inconsistency between uints and u32s for this piece
of code.
2013-06-14 11:12:06 +10:00
Huon Wilson
096f6f56a8 Use @str instead of @~str in libsyntax and librustc. Fixes #5048.
This almost removes the StringRef wrapper, since all strings are
Equiv-alent now. Removes a lot of `/* bad */ copy *`'s, and converts
several things to be &'static str (the lint table and the intrinsics
table).

There are many instances of .to_managed(), unfortunately.
2013-06-13 10:20:52 +10:00
Huon Wilson
513d2292e5 std: remove foldr and alli methods in vec 2013-06-09 02:22:23 +10:00
Huon Wilson
ed299af625 std: remove fold[lr] in favour of iterators 2013-06-09 02:22:23 +10:00