Commit Graph

56 Commits

Author SHA1 Message Date
Felix S. Klock II
0d5bcb14ad Switched to Box::new in many places.
Many of the modifications putting in `Box::new` calls also include a
pointer to Issue 22405, which tracks going back to `box <expr>` if
possible in the future.

(Still tried to use `Box<_>` where it sufficed; thus some tests still
have `box_syntax` enabled, as they use a mix of `box` and `Box::new`.)

Precursor for overloaded-`box` and placement-`in`; see Issue 22181.
2015-03-03 21:05:55 +01:00
Alex Crichton
2d200c9c8b std: Move std::env to the new I/O APIs
This commit moves `std::env` away from the `std::old_io` error type as well as
the `std::old_path` module. Methods returning an error now return `io::Error`
and methods consuming or returning paths use `std::path` instead of
`std::old_path`. This commit does not yet mark these APIs as `#[stable]`.

This commit also migrates `std::old_io::TempDir` to `std::fs::TempDir` with
essentially the exact same API. This type was added to interoperate with the new
path API and has its own `tempdir` feature.

Finally, this commit reverts the deprecation of `std::os` APIs returning the old
path API types. This deprecation can come back once the entire `std::old_path`
module is deprecated.

[breaking-change]
2015-02-24 15:27:42 -08:00
Niko Matsakis
9ea84aeed4 Replace all uses of &foo[] with &foo[..] en masse. 2015-02-18 17:36:03 -05:00
Keegan McAllister
6864792df0 Separate macro and plugin loading
Now they just share a bit of code internal to creader.

Resolves #22198 to my satisfaction.
2015-02-12 12:44:31 -08:00
Keegan McAllister
6b784bacbf creader: Clean up macro/plugin API
Step towards #22198.
2015-02-12 12:32:40 -08:00
Keegan McAllister
d4288717c4 Forbid undefined names in macro use / macro reexport
Fixes #21062.
2015-02-10 19:36:31 -08:00
Keegan McAllister
1aedc45f85 Add a help message for deprecated #[plugin] extern crate 2015-02-09 14:25:47 -08:00
Keegan McAllister
93b642d974 Use a crate attribute to load plugins
#[plugin] #[no_link] extern crate bleh;

becomes a crate attribute

    #![plugin(bleh)]

The feature gate is still required.

It's almost never correct to link a plugin into the resulting library /
executable, because it will bring all of libsyntax and librustc with it.
However if you really want this behavior, you can get it with a separate
`extern crate` item in addition to the `plugin` attribute.

Fixes #21043.
Fixes #20769.

[breaking-change]
2015-02-09 13:27:27 -08:00
GuillaumeGomez
664c41b427 librustc has been updated 2015-02-06 11:59:10 +01:00
Jorge Aparicio
17bc7d8d5b cleanup: replace as[_mut]_slice() calls with deref coercions 2015-02-05 13:45:01 -05:00
Alex Crichton
7335c7dd63 rollup merge of #21830: japaric/for-cleanup
Conflicts:
	src/librustc/metadata/filesearch.rs
	src/librustc_back/target/mod.rs
	src/libstd/os.rs
	src/libstd/sys/windows/os.rs
	src/libsyntax/ext/tt/macro_parser.rs
	src/libsyntax/print/pprust.rs
	src/test/compile-fail/issue-2149.rs
2015-02-02 11:01:12 -08:00
Jorge Aparicio
fd702702ee for x in xs.into_iter() -> for x in xs
Also `for x in option.into_iter()` -> `if let Some(x) = option`
2015-02-02 13:40:18 -05:00
Jorge Aparicio
d5d7e6565a for x in xs.iter() -> for x in &xs 2015-02-02 13:40:18 -05:00
Alex Crichton
70ed3a48df std: Add a new env module
This is an implementation of [RFC 578][rfc] which adds a new `std::env` module
to replace most of the functionality in the current `std::os` module. More
details can be found in the RFC itself, but as a summary the following methods
have all been deprecated:

[rfc]: https://github.com/rust-lang/rfcs/pull/578

* `os::args_as_bytes`   => `env::args`
* `os::args`            => `env::args`
* `os::consts`          => `env::consts`
* `os::dll_filename`    => no replacement, use `env::consts` directly
* `os::page_size`       => `env::page_size`
* `os::make_absolute`   => use `env::current_dir` + `join` instead
* `os::getcwd`          => `env::current_dir`
* `os::change_dir`      => `env::set_current_dir`
* `os::homedir`         => `env::home_dir`
* `os::tmpdir`          => `env::temp_dir`
* `os::join_paths`      => `env::join_paths`
* `os::split_paths`     => `env::split_paths`
* `os::self_exe_name`   => `env::current_exe`
* `os::self_exe_path`   => use `env::current_exe` + `pop`
* `os::set_exit_status` => `env::set_exit_status`
* `os::get_exit_status` => `env::get_exit_status`
* `os::env`             => `env::vars`
* `os::env_as_bytes`    => `env::vars`
* `os::getenv`          => `env::var` or `env::var_string`
* `os::getenv_as_bytes` => `env::var`
* `os::setenv`          => `env::set_var`
* `os::unsetenv`        => `env::remove_var`

Many function signatures have also been tweaked for various purposes, but the
main changes were:

* `Vec`-returning APIs now all return iterators instead
* All APIs are now centered around `OsString` instead of `Vec<u8>` or `String`.
  There is currently on convenience API, `env::var_string`, which can be used to
  get the value of an environment variable as a unicode `String`.

All old APIs are `#[deprecated]` in-place and will remain for some time to allow
for migrations. The semantics of the APIs have been tweaked slightly with regard
to dealing with invalid unicode (panic instead of replacement).

The new `std::env` module is all contained within the `env` feature, so crates
must add the following to access the new APIs:

    #![feature(env)]

[breaking-change]
2015-02-01 11:08:15 -08:00
Eduard Burtescu
cfb63d5448 rustc: fix fallout of merging ast::ViewItem into ast::Item. 2015-01-21 16:27:26 +02:00
Nick Cameron
98d471120a Syntax extensions on trait and impl items.
Allows modifiers to be used on methods, associated types, etc.
2015-01-15 08:58:44 +13:00
Manish Goregaokar
c41cafb10c librustc_driver: Add support for loading plugins via command line (fixes #15446) 2015-01-08 13:40:50 +05:30
Manish Goregaokar
9f5f706f96 librustc::plugin : make PluginLoader usable for loading argument-specified plugins 2015-01-08 13:40:48 +05:30
Manish Goregaokar
efaf613497 librustc::metadata : Allow passing a string to read_plugin_metadata 2015-01-08 13:39:27 +05:30
Jorge Aparicio
517f1cc63c use slicing sugar 2015-01-07 17:35:56 -05:00
Nick Cameron
f7ff37e4c5 Replace full slice notation with index calls 2015-01-07 10:46:33 +13:00
Keegan McAllister
bbbb85a4ec Forbid '#[macro_use] extern crate' outside the crate root 2015-01-05 18:21:14 -08:00
Keegan McAllister
d0163d3311 Pass the #[plugin(...)] meta item to the registrar 2015-01-05 18:21:14 -08:00
Keegan McAllister
aa69cbde82 Allow selective macro import 2015-01-05 18:21:13 -08:00
Keegan McAllister
0816255c80 Move #[macro_reexport] to extern crate 2015-01-05 18:21:13 -08:00
Keegan McAllister
60be2f52d2 Replace #[phase] with #[plugin] / #[macro_use] / #[no_link] 2015-01-05 18:21:13 -08:00
Keegan McAllister
f314e2c4ea creader: Load parts of plugin metadata on demand 2015-01-05 18:21:13 -08:00
Keegan McAllister
677b7cad3d Reformat metadata for exported macros
Instead of copy-pasting the whole macro_rules! item from the original .rs file,
we serialize a separate name, attributes list, and body, the latter as
pretty-printed TTs.  The compilation of macro_rules! macros is decoupled
somewhat from the expansion of macros in item position.

This filters out comments, and facilitates selective imports.
2015-01-05 12:00:57 -08:00
Keegan McAllister
24aa7f0e38 creader: Use a single struct 2015-01-05 12:00:57 -08:00
Keegan McAllister
5e5924b799 Replace LetSyntaxTT with MacroRulesTT
The implementation of LetSyntaxTT was specialized to macro_rules! in various
ways. This gets rid of the false generality and simplifies the code.
2015-01-05 11:38:12 -08:00
Alex Crichton
082bfde412 Fallout of std::str stabilization 2014-12-21 23:31:42 -08:00
jfager
232ffa039d Replace some verbose match statements with their if let equivalent.
No semantic changes, no enabling `if let` where it wasn't already enabled.
2014-11-29 16:41:21 -05:00
Steve Klabnik
cd5c8235c5 /*! -> //!
Sister pull request of https://github.com/rust-lang/rust/pull/19288, but
for the other style of block doc comment.
2014-11-26 16:50:14 -08:00
Barosl Lee
6f422c4c05 Make os::getcwd() return IoResult<Path>
os::getcwd() panics if the current directory is not available. According
to getcwd(3), there are three cases:

- EACCES: Permission denied.
- ENOENT: The current working directory has been removed.
- ERANGE: The buffer size is less than the actual absolute path.

This commit makes os::getcwd() return IoResult<Path>, not just Path,
preventing it from panicking.

As os::make_absolute() depends on os::getcwd(), it is also modified to
return IoResult<Path>.

Fixes #16946.

[breaking-change]
2014-11-19 05:31:45 +09:00
Niko Matsakis
dc6e414e6f Move trans, back, driver, and back into a new crate, rustc_trans. Reduces memory usage significantly and opens opportunities for more parallel compilation. 2014-11-18 07:32:43 -05:00
Steve Klabnik
7828c3dd28 Rename fail! to panic!
https://github.com/rust-lang/rfcs/pull/221

The current terminology of "task failure" often causes problems when
writing or speaking about code. You often want to talk about the
possibility of an operation that returns a Result "failing", but cannot
because of the ambiguity with task failure. Instead, you have to speak
of "the failing case" or "when the operation does not succeed" or other
circumlocutions.

Likewise, we use a "Failure" header in rustdoc to describe when
operations may fail the task, but it would often be helpful to separate
out a section describing the "Err-producing" case.

We have been steadily moving away from task failure and toward Result as
an error-handling mechanism, so we should optimize our terminology
accordingly: Result-producing functions should be easy to describe.

To update your code, rename any call to `fail!` to `panic!` instead.
Assuming you have not created your own macro named `panic!`, this
will work on UNIX based systems:

    grep -lZR 'fail!' . | xargs -0 -l sed -i -e 's/fail!/panic!/g'

You can of course also do this by hand.

[breaking-change]
2014-10-29 11:43:07 -04:00
Alex Crichton
9d5d97b55d Remove a large amount of deprecated functionality
Spring cleaning is here! In the Fall! This commit removes quite a large amount
of deprecated functionality from the standard libraries. I tried to ensure that
only old deprecated functionality was removed.

This is removing lots and lots of deprecated features, so this is a breaking
change. Please consult the deprecation messages of the deleted code to see how
to migrate code forward if it still needs migration.

[breaking-change]
2014-10-19 12:59:40 -07:00
Keegan McAllister
61bf75bb5e Add a guide to compiler plugins
Fixes #16983.
2014-10-01 13:21:52 -07:00
Nick Cameron
ce0907e46e Add enum variants to the type namespace
Change to resolve and update compiler and libs for uses.

[breaking-change]

Enum variants are now in both the value and type namespaces. This means that
if you have a variant with the same name as a type in scope in a module, you
will get a name clash and thus an error. The solution is to either rename the
type or the variant.
2014-09-19 15:11:00 +12:00
Aaron Turon
fc525eeb4e Fallout from renaming 2014-09-16 14:37:48 -07:00
bors
a9cf19889a auto merge of #17162 : sfackler/rust/decorator-traits, r=huonw
The other extension types already worked this way and it can be useful to track some state along with the extension.

I also removed the `BasicMacroExpander` and `BasicIdentMacroExpander` since the span inside of them was never used. The expander function types now directly implement the relevant trait.
2014-09-13 05:25:57 +00:00
Eduard Burtescu
7ef6ff0669 Track the visited AST's lifetime throughout Visitor. 2014-09-12 14:24:45 +03:00
Eduard Burtescu
a09dbf28e6 Remove largely unused context from Visitor. 2014-09-12 14:24:45 +03:00
Steven Fackler
200a08fc21 Remove BasicMacroExpander and BasicIdentMacroExpander
The spans inside of these types were always None and never used. Pass
the expander function directly instead of wrapping it in one of these
types.

[breaking-change]
2014-09-10 21:02:39 -07:00
P1start
ed2aad8b43 Add lint groups; define built-in lint groups bad_style and unused
This adds support for lint groups to the compiler. Lint groups are a way of
grouping a number of lints together under one name. For example, this also
defines a default lint for naming conventions, named `bad_style`. Writing
`#[allow(bad_style)]` is equivalent to writing
`#[allow(non_camel_case_types, non_snake_case, non_uppercase_statics)]`. These
lint groups can also be defined as a compiler plugin using the new
`Registry::register_lint_group` method.

This also adds two built-in lint groups, `bad_style` and `unused`. The contents
of these groups can be seen by running `rustc -W help`.
2014-08-30 09:12:04 +12:00
Brian Anderson
c88bf10c37 rustc: Pass optional additional plugins to compile_input
This provides a way for clients of the rustc library to add
their own features to the pipeline.
2014-07-21 09:54:26 -07:00
bors
cdd6346f45 auto merge of #15601 : jbclements/rust/disable-default-macro-behavior, r=alexcrichton
Our AST definition can include macro invocations, which can expand into all kinds of things. Macro invocations are expanded away during expansion time, and the rest of the compiler doesn't have to deal with them. However, we have no way of enforcing this.

This patch adds two protective mechanisms.

First, it adds a (quick) explicit check that ensures there are no macro invocations remaining in the AST after expansion. Second, it updates the visit and fold mechanisms so that by default, they will not traverse macro invocations. It's easy enough to add this, if desired (it's documented in the source, and examples appear, e.g. in the IdentFinder.

Along the way, I also consulted with @sfackler to refactor the macro export mechanism so that it stores macro text spans in a side table, rather than leaving them in the AST.
2014-07-12 11:06:39 +00:00
John Clements
53642eed80 make walk/visit_mac opt-in only
macros can expand into arbitrary items, exprs, etc. This
means that using a default walker or folder on an AST before
macro expansion is complete will miss things (the things that
the macros expand into). As a partial fence against this, this
commit moves the default traversal of macros into a separate
procedure, and makes the default trait implementation signal
an error. This means that Folders and Visitors can traverse
macros if they want to, but they need to explicitly add an
impl that calls the walk_mac or fold_mac procedure

This should prevent problems down the road.
2014-07-11 10:32:41 -07:00
Alex Crichton
0c71e0c596 Register new snapshots
Closes #15544
2014-07-09 10:57:58 -07:00
John Clements
9ee9c49cb4 introducing let-syntax
The let-syntax expander is different in that it doesn't apply
a mark to its token trees before expansion. This is used
for macro_rules, and it's because macro_rules is essentially
MTWT's let-syntax. You don't want to mark before expand sees
let-syntax, because there's no "after" syntax to mark again.

In some sense, the cleaner approach might be to introduce a new
AST node that macro_rules expands into; this would make it clearer
that the expansion of a macro is distinct from the addition of a
new macro binding.

This should work for now, though...
2014-07-08 16:26:43 -07:00