Commit Graph

2893 Commits

Author SHA1 Message Date
Vadim Petrochenkov f60d96a477 Support custom attributes when macro modularization is enabled 2018-08-06 23:21:18 +03:00
Vadim Petrochenkov c84562e019 Avoid modifying invocations in place for derive helper attributes 2018-08-06 23:20:05 +03:00
bors 40e4b6ee3d Auto merge of #52841 - petrochenkov:premacro, r=alexcrichton
resolve: Implement prelude search for macro paths, implement tool attributes

When identifier is macro path is resolved in scopes (i.e. the first path segment - `foo` in `foo::mac!()` or `foo!()`), scopes are searched in the same order as for non-macro paths - items in modules, extern prelude, tool prelude (see later), standard library prelude, language prelude, but with some extra shadowing restrictions (names from globs and macro expansions cannot shadow names from outer scopes). See the comment in `fn resolve_lexical_macro_path_segment` for more details.

"Tool prelude" currently contains two "tool modules" `rustfmt` and `clippy`, and is searched immediately after extern prelude.
This makes the [possible long-term solution](https://github.com/rust-lang/rfcs/blob/master/text/2103-tool-attributes.md#long-term-solution) for tool attributes exactly equivalent to the existing extern prelude scheme, except that `--extern=my_crate` making crate names available in scope is replaced with something like `--tool=my_tool` making tool names available in scope.

The `tool_attributes` feature is still unstable and `#![feature(tool_attributes)]` now implicitly enables `#![feature(use_extern_macros)]`. `use_extern_macros` is a prerequisite for `tool_attributes`, so their stabilization will happen in the same order.
If `use_extern_macros` is not enabled, then tool attributes are treated as custom attributes (this is temporary, anyway).

Fixes https://github.com/rust-lang/rust/issues/52576
Fixes https://github.com/rust-lang/rust/issues/52512
Fixes https://github.com/rust-lang/rust/issues/51277
cc https://github.com/rust-lang/rust/issues/52269
2018-08-02 21:39:14 +00:00
bors 02a369a5c8 Auto merge of #52890 - djrenren:test-visibility, r=petrochenkov
Reexport tests without polluting namespaces

This should fix issue #52557.

Basically now we gensym a new name for the test function and reexport that.
That way the test function's reexport name can't conflict because it was impossible for the test author to write it down.
We then use a `use` statement to expose the original name using the original visibility.
2018-08-02 08:24:14 +00:00
John Renner 77f9aca2a3 Use the correct allow 2018-08-01 12:33:10 -07:00
John Renner af7ae2f278 Allow test imports to go unused 2018-08-01 11:28:08 -07:00
Vadim Petrochenkov c3e54217e8 resolve: Implement prelude search for macro paths
resolve/expansion: Implement tool attributes
2018-08-01 12:08:41 +03:00
John Renner 549f0fd9f7 Address code review 2018-07-31 15:00:45 -07:00
John Renner 7947c58d2d Allow unnameable tests 2018-07-31 13:17:44 -07:00
John Renner f76049cd6a Reexport tests without polluting namespaces 2018-07-30 19:23:24 -07:00
ljedrz 57a5a9b054 Prefer to_string() to format!() 2018-07-27 11:11:18 +02:00
mark b206aedb1b make it a migration lint 2018-07-23 21:55:51 -05:00
mark 5d872727e0 Fix test and errors 2018-07-23 21:54:43 -05:00
mark 8eb4941e30 Implement 2015 vs 2018 ? kleene op + test 2018-07-23 21:54:43 -05:00
bors 3d51086303 Auto merge of #52394 - estebank:println, r=oli-obk
Improve suggestion for missing fmt str in println

Avoid using `concat!(fmt, "\n")` to improve the diagnostics being
emitted when the first `println!()` argument isn't a formatting string
literal.

Fix #52347.
2018-07-22 06:52:48 +00:00
Esteban Küber 00d500052c Gate format_args_nll behind feature flag 2018-07-21 15:50:46 -07:00
Esteban Küber f53c145ef1 Improve suggestion for missing fmt str in println
Avoid using `concat!(fmt, "\n")` to improve the diagnostics being
emitted when the first `println!()` argument isn't a formatting string
literal.
2018-07-19 23:18:07 -07:00
Alex Crichton f2f7ab9da8 rustc: Fix two custom attributes with custom derive
This commit fixes an issue where multiple custom attributes could not be fed
into a custom derive in some situations with the `use_extern_macros` feature
enabled. The problem was that the macro expander didn't consider that it was
making progress when we were deducing that attributes should be lumped in with
custom derive invocations.

The fix applied here was to track in the expander if our attribute is changing
(getting stashed away elsewhere and replaced with a new invocation). If it is
swapped then it's considered progress, otherwise behavior should remain the
same.

Closes #52525
2018-07-19 07:46:44 -07:00
bors 4f3c7a472b Auto merge of #52145 - ExpHP:drop-it-like-its-eof, r=nikomatsakis
Fix macro parser quadratic complexity in small repeating groups

Observed in #51754, and more easily demonstrated with the following:

```rust
macro_rules! stress {
    ($($t:tt)+) => { };
}

fn main() {
    stress!{
        a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
        a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
        a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
        a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
        //    ... 65536 copies of "a" total ...
        a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
        a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
        a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
        a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
    }
}
```
which takes 50 seconds to compile prior to the fix and <1s after.

I hope this has a visible impact on the compile times for real code.  (I think it is most likely to affect incremental TT munchers that deal with large inputs, though it depends on how they are written)

For a fuller description of the performance issue:  https://github.com/rust-lang/rust/issues/51754#issuecomment-403242159

---

There is no test (yet) because I'm not sure how easily to measure this for regressions.
2018-07-17 19:28:23 +00:00
Michael Lamparski 0467ae0cf5 cleanup unnecessary else 2018-07-16 16:15:34 -04:00
Alex Crichton 65f3007fa8 rustc: Stabilize much of the proc_macro feature
This commit stabilizes some of the `proc_macro` language feature as well as a
number of APIs in the `proc_macro` crate as [previously discussed][1]. This
means that on stable Rust you can now define custom procedural macros which
operate as attributes attached to items or `macro_rules!`-like bang-style
invocations. This extends the suite of currently stable procedural macros,
custom derives, with custom attributes and custom bang macros.

Note though that despite the stabilization in this commit procedural macros are
still not usable on stable Rust. To stabilize that we'll need to stabilize at
least part of the `use_extern_macros` feature. Currently you can define a
procedural macro attribute but you can't import it to call it!

A summary of the changes made in this PR (as well as the various consequences)
is:

* The `proc_macro` language and library features are now stable.
* Other APIs not stabilized in the `proc_macro` crate are now named under a
  different feature, such as `proc_macro_diagnostic` or `proc_macro_span`.
* A few checks in resolution for `proc_macro` being enabled have switched over
  to `use_extern_macros` being enabled. This means that code using
  `#![feature(proc_macro)]` today will likely need to move to
  `#![feature(use_extern_macros)]`.

It's intended that this PR, once landed, will be followed up with an attempt to
stabilize a small slice of `use_extern_macros` just for procedural macros to
make this feature 100% usable on stable.

[1]: https://internals.rust-lang.org/t/help-stabilize-a-subset-of-macros-2-0/7252
2018-07-16 07:58:06 -07:00
bors 82e5c9c8e2 Auto merge of #52383 - petrochenkov:pmns, r=alexcrichton
resolve: Functions introducing procedural macros reserve a slot in the macro namespace as well

Similarly to https://github.com/rust-lang/rust/pull/52234, this gives us symmetry between internal and external views of a crate, but in this case it's always an error to call a procedural macro in the same crate in which it's defined.

Closes https://github.com/rust-lang/rust/issues/52225
2018-07-15 19:35:06 +00:00
Vadim Petrochenkov 431aefb2d4 Functions introducing procedural macros reserve a slot in the macro namespace as well 2018-07-14 20:10:07 +03:00
Vadim Petrochenkov 5987fe8f75 Remove most of Hash impls from AST and HIR structures 2018-07-14 14:57:14 +03:00
Vadim Petrochenkov 4d1a30c92b Remove most of PartialEq impls from AST and HIR structures 2018-07-14 14:56:57 +03:00
Mark Rousskov 2d49909f45 Rollup merge of #52224 - ljedrz:dyn_libsyntax, r=oli-obk
Deny bare trait objects in in src/libsyntax

Enforce `#![deny(bare_trait_objects)]` in `src/libsyntax`.
2018-07-11 12:38:39 -06:00
ljedrz 84dadb6139 Pacify tidy 2018-07-10 21:58:16 +02:00
ljedrz e28e4877a8 Deny bare trait objects in in src/libsyntax 2018-07-10 21:06:26 +02:00
Vadim Petrochenkov 94ef9f57f5 hygiene: Decouple transparencies from expansion IDs 2018-07-08 16:17:37 +03:00
Michael Lamparski 191e76c5b8 fix perf issue in macro parser
For a fuller description of the performance issue fixed by this:

https://github.com/rust-lang/rust/issues/51754#issuecomment-403242159
2018-07-07 17:13:21 -04:00
Vadim Petrochenkov 9f92fce77c Fortify dummy span checking 2018-06-30 01:53:32 +03:00
Vadim Petrochenkov 99ecdb3f5f hygiene: Implement transparent marks 2018-06-30 01:53:32 +03:00
Vadim Petrochenkov 09856c85b7 expansion: Give names to some fields of SyntaxExtension 2018-06-30 01:53:32 +03:00
bors 9f79d2f86a Auto merge of #50997 - michaelwoerister:pre-analyze-filemaps, r=Mark-Simulacrum
Make FileMap::{lines, multibyte_chars, non_narrow_chars} non-mutable.

This PR removes most of the interior mutability from `FileMap`, which should be beneficial, especially in a multithreaded setting. This is achieved by initializing the state in question when the filemap is constructed instead of during lexing. Hopefully this doesn't degrade performance.

cc @wesleywiser
2018-06-28 11:20:41 +00:00
Michael Woerister 095a339bec Remove the now redundant CodeMap::new_filemap_with_lines() method. 2018-06-27 14:00:34 +02:00
Vadim Petrochenkov d347270e0c Implement #[macro_export(local_inner_macros)] 2018-06-27 13:10:16 +03:00
Vadim Petrochenkov 20ce91076a hygiene: Merge NameAndSpan into ExpnInfo 2018-06-23 21:53:24 +03:00
Vadim Petrochenkov c00f5af4d6 hygiene: Do not reset expansion info for quote! 2018-06-23 20:40:25 +03:00
Vadim Petrochenkov 296955a6e1 expansion: Add some comments 2018-06-23 20:09:21 +03:00
Vadim Petrochenkov 399da7bc35 expansion: Improve searchability for AstFragments methods 2018-06-23 20:09:21 +03:00
Vadim Petrochenkov a12726460e expansion: Rename Expansion to AstFragment 2018-06-23 20:09:21 +03:00
Vadim Petrochenkov 17f20bec22 expansion: Remove unnecessary override from impl Folder for Marker 2018-06-23 20:09:21 +03:00
Taylor Cramer cf844b547d async await desugaring and tests 2018-06-21 22:36:36 -07:00
Without Boats 18ff7d091a Parse async fn header.
This is gated on edition 2018 & the `async_await` feature gate.

The parser will accept `async fn` and `async unsafe fn` as fn
items. Along the same lines as `const fn`, only `async unsafe fn`
is permitted, not `unsafe async fn`.The parser will not accept
`async` functions as trait methods.

To do a little code clean up, four fields of the function type
struct have been merged into the new `FnHeader` struct: constness,
asyncness, unsafety, and ABI.

Also, a small bug in HIR printing is fixed: it previously printed
`const unsafe fn` as `unsafe const fn`, which is grammatically
incorrect.
2018-06-21 22:29:47 -07:00
varkor 37204027b6 Rename ty_param_bound to trait_bound 2018-06-20 12:23:46 +01:00
varkor 95f1866a4d Make GenericBound explicit 2018-06-20 12:23:46 +01:00
varkor c5f16e0e18 Rename ParamBound(s) to GenericBound(s) 2018-06-20 12:23:46 +01:00
varkor 7de6ed06a5 Rename TraitTyParamBound to ParamBound::Trait 2018-06-20 12:23:23 +01:00
varkor 6015edf9af Remove name from GenericParamKind::Lifetime 2018-06-20 12:23:08 +01:00
varkor aed530a457 Lift bounds into GenericParam 2018-06-20 12:22:46 +01:00