Commit Graph

36 Commits

Author SHA1 Message Date
bors 2ab5d8ac44 Auto merge of #57651 - JohnTitor:give-char-type, r=estebank
Implement new literal type `Err`

Fixes #57384

I removed `return Ok`, otherwise, two errors occur. Any solutions?

r? @estebank
2019-01-20 08:26:12 +00:00
Yuki Okushi a4ff1dcc53 Mark incorrect recovered char literals as TyErr to avoid type errors 2019-01-20 14:51:54 +09:00
Mazdak Farrokhzad 349c9eeb35 Rollup merge of #57486 - nnethercote:simplify-TokenStream-more, r=petrochenkov
Simplify `TokenStream` some more

These commits simplify `TokenStream`, remove `ThinTokenStream`, and avoid some clones. The end result is simpler code and a slight perf win on some benchmarks.

r? @petrochenkov
2019-01-19 14:21:17 +01:00
bors ceb2512144 Auto merge of #57321 - petrochenkov:atokens, r=nikomatsakis
Implement basic input validation for built-in attributes

Correct top-level shape (`#[attr]` vs `#[attr(...)]` vs `#[attr = ...]`) is enforced for built-in attributes, built-in attributes must also fit into the "meta-item" syntax (aka the "classic attribute syntax").

For some subset of attributes (found by crater run), errors are lowered to deprecation warnings.

NOTE: This PR previously included https://github.com/rust-lang/rust/pull/57367 as well.
2019-01-16 15:01:20 +00:00
Nicholas Nethercote ce0d9949b8 Remove ThinTokenStream.
`TokenStream` is now almost identical to `ThinTokenStream`. This commit
removes the latter, replacing it with the former.
2019-01-14 09:10:26 +11:00
Vadim Petrochenkov 41c65992c5 Implement basic input validation for built-in attributes 2019-01-13 14:17:19 +03:00
Nicholas Nethercote e80a93040f Make TokenStream less recursive.
`TokenStream` is currently recursive in *two* ways:

- the `TokenTree` variant contains a `ThinTokenStream`, which can
  contain a `TokenStream`;

- the `TokenStream` variant contains a `Vec<TokenStream>`.

The latter is not necessary and causes significant complexity. This
commit replaces it with the simpler `Vec<(TokenTree, IsJoint)>`.

This reduces complexity significantly. In particular, `StreamCursor` is
eliminated, and `Cursor` becomes much simpler, consisting now of just a
`TokenStream` and an index.

The commit also removes the `Extend` impl for `TokenStream`, because it
is only used in tests. (The commit also removes those tests.)

Overall, the commit reduces the number of lines of code by almost 200.
2019-01-08 15:08:46 +11:00
Mark Rousskov 2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
Nicholas Nethercote e80c7ddb05 Rename TokenStream::concat and remove TokenStream::concat_rc_vec.
`TokenStream::new` is a better name for the former, and the latter is
now just equivalent to `TokenStream::Stream`.
2018-12-12 20:36:00 +11:00
Nicholas Nethercote 1fe2c03240 Remove tokenstream::Delimited.
Because it's an extra type layer that doesn't really help; in a couple
of places it actively gets in the way, and overall removing it makes the
code nicer. It does, however, move `tokenstream::TokenTree` further away
from the `TokenTree` in `quote.rs`.

More importantly, this change reduces the size of `TokenStream` from 48
bytes to 40 bytes on x86-64, which is enough to slightly reduce
instruction counts on numerous benchmarks, the best by 1.5%.

Note that `open_tt` and `close_tt` have gone from being methods on
`Delimited` to associated methods of `TokenTree`.
2018-12-10 12:10:10 +11:00
Alexander Regueiro ee89c088b0 Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
Matthew Russo 88130f1796 updates all Filename variants to take a fingerprint 2018-12-04 17:24:12 -05:00
Cameron Hart d22ae75c9d Fix feature gate only being checked on first repr attr. 2018-10-31 03:28:06 +11:00
csmoe a76690f6a4 optimize unsupported literal diag message 2018-10-22 20:28:37 +08:00
csmoe fb7c76bad5 update meta item checking test 2018-10-20 11:11:31 +08:00
csmoe d3b018ccdb suggest to trim prefix in nested meta items 2018-10-20 11:11:31 +08:00
csmoe 30c6698193 handle errors based on parse_sess 2018-10-20 11:11:31 +08:00
csmoe 2ed2d1a7e6 suggest to remove prefix b in lint string 2018-10-20 11:11:31 +08:00
Oliver Schneider ec74d3533a Stabilize min_const_fn 2018-10-05 10:36:14 +02:00
Oliver Schneider 1f943849b1 Update error id to an unused one 2018-10-03 10:07:05 +02:00
Oliver Schneider 9e46c0b689 Only promote calls to #[rustc_promotable] const fns 2018-10-03 10:07:05 +02:00
bors 40fc8ba5f9 Auto merge of #53902 - dtolnay:group, r=petrochenkov
proc_macro::Group::span_open and span_close

Before this addition, every delimited group like `(`...`)` `[`...`]` `{`...`}` has only a single Span that covers the full source location from opening delimiter to closing delimiter. This makes it impossible for a procedural macro to trigger an error pointing to just the opening or closing delimiter. The Rust compiler does not seem to have the same limitation:

```rust
mod m {
    type T =
}
```

```console
error: expected type, found `}`
 --> src/main.rs:3:1
  |
3 | }
  | ^
```

On that same input, a procedural macro would be forced to trigger the error on the last token inside the block, on the entire block, or on the next token after the block, none of which is really what you want for an error like above.

This commit adds `group.span_open()` and `group.span_close()` which access the Span associated with just the opening delimiter and just the closing delimiter of the group. Relevant to Syn as we implement real error messages for when parsing fails in a procedural macro: https://github.com/dtolnay/syn/issues/476.

```diff
  impl Group {
      fn span(&self) -> Span;
+     fn span_open(&self) -> Span;
+     fn span_close(&self) -> Span;
  }
```

Fixes #48187
r? @alexcrichton
2018-09-09 13:27:44 +00:00
David Tolnay a1dd39e724 Track distinct spans for open and close delimiter 2018-09-08 19:01:48 -07:00
Vadim Petrochenkov b0a05c5981 Validate syntax of cfg attributes 2018-09-06 01:18:30 +03:00
Oliver Schneider 472ca71598 Implement the min_const_fn feature gate 2018-08-31 08:39:59 +02:00
Donato Sciarra 82607d2cf3 mv (mod) codemap source_map 2018-08-19 23:01:00 +02:00
Vadim Petrochenkov 097c40cf6e syntax: Enforce attribute grammar in the parser 2018-08-15 00:05:55 +03:00
ljedrz e5e6375352 Move SmallVec and ThinVec out of libsyntax 2018-08-13 22:11:57 +02: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
Mark Rousskov 1d64b241cd Switch syntax attribute tracking to BitVector 2018-08-01 06:48:42 -06:00
Vadim Petrochenkov c3e54217e8 resolve: Implement prelude search for macro paths
resolve/expansion: Implement tool attributes
2018-08-01 12:08:41 +03:00
Pietro Albini 71276c6abc Add the -Zcrate-attr=foo nightly rustc flag to inject crate attributes 2018-07-27 19:51:21 +02:00
flip1995 c3949009ad Improving span of unknown lint tool error message 2018-07-04 14:28:44 +02:00
flip1995 dddb8d2eba Implementation of tool lints 2018-07-04 12:16:46 +02:00
Andy Russell 5468e12ca0 add label to unknown meta item error 2018-06-30 21:38:18 -04:00
Andy Russell 011eaed59d factor built-in attribute parsing into submodule 2018-06-30 20:44:20 -04:00