Commit graph

418 commits

Author SHA1 Message Date
Anton Golov
5d59b4412e Add warning when whitespace is not skipped after an escaped newline. 2021-07-30 16:26:39 +02:00
Jade
3cf820e17d rfc3052: Remove authors field from Cargo manifests
Since RFC 3052 soft deprecated the authors field anyway, hiding it from
crates.io, docs.rs, and making Cargo not add it by default, and it is
not generally up to date/useful information, we should remove it from
crates in this repo.
2021-07-29 14:56:05 -07:00
bors
998cfe5aad Auto merge of #85305 - MarcusDunn:master, r=pnkfelix
Stabilize bindings_after_at

attempting to stabilze bindings_after_at [#65490](https://github.com/rust-lang/rust/issues/65490), im pretty new to the whole thing so any pointers are greatly appreciated.
2021-07-27 05:53:31 +00:00
Matthias Krüger
053aedce2c clippy::filter_map_identity 2021-07-25 12:26:03 +02:00
Elliot Bobrow
e0995a5a8d fix code to suggest ; on parse error 2021-07-24 10:58:55 -07:00
bors
5a8a44196b Auto merge of #87242 - JohnTitor:rollup-t9rmwpo, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #86763 (Add a regression test for issue-63355)
 - #86814 (Recover from a misplaced inner doc comment)
 - #86843 (Check that const parameters of trait methods have compatible types)
 - #86889 (rustdoc: Cleanup ExternalCrate)
 - #87092 (Remove nondeterminism in multiple-definitions test)
 - #87170 (Add diagnostic items for Clippy)
 - #87183 (fix typo in compile_fail doctest)
 - #87205 (rustc_middle: remove redundant clone)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-07-18 08:15:17 +00:00
bors
3ab6b60337 Auto merge of #87071 - inquisitivecrystal:inclusive-range, r=estebank
Add diagnostics for mistyped inclusive range

Inclusive ranges are correctly typed as `..=`. However, it's quite easy to think of it as being like `==`, and type `..==` instead. This PR adds helpful diagnostics for this case.

Resolves #86395 (there are some other cases there, but I think those should probably have separate issues).

r? `@estebank`
2021-07-18 05:58:16 +00:00
Yuki Okushi
469935f7a4
Rollup merge of #86814 - Aaron1011:inner-doc-recover, r=estebank
Recover from a misplaced inner doc comment

Fixes #86781
2021-07-18 14:21:53 +09:00
Fabian Wolff
2362450425 Suggest a path separator if a stray colon is found in a match arm
Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>
2021-07-14 01:15:59 +02:00
Aris Merchant
fd406a8865 Give a helpful error for the mistake ..== 2021-07-11 16:51:32 -07:00
bors
0d76b73745 Auto merge of #83918 - workingjubilee:stable-rangefrom-pat, r=joshtriplett
Stabilize "RangeFrom" patterns in 1.55

Implements a partial stabilization of #67264 and #37854.
Reference PR: https://github.com/rust-lang/reference/pull/900

# Stabilization Report

This stabilizes the `X..` pattern, shown as such, offering an exhaustive match for unsigned integers:
```rust
match x as u32 {
      0 => println!("zero!"),
      1.. => println!("positive number!"),
}
```

Currently if a Rust author wants to write such a match on an integer, they must use `1..={integer}::MAX` . By allowing a "RangeFrom" style pattern, this simplifies the match to not require the MAX path and thus not require specifically repeating the type inside the match, allowing for easier refactoring. This is particularly useful for instances like the above case, where different behavior on "0" vs. "1 or any positive number" is desired, and the actual MAX is unimportant.

Notably, this excepts slice patterns which include half-open ranges from stabilization, as the wisdom of those is still subject to some debate.

## Practical Applications

Instances of this specific usage have appeared in the compiler:
16143d1067/compiler/rustc_middle/src/ty/inhabitedness/mod.rs (L219)
673d0db5e3/compiler/rustc_ty_utils/src/ty.rs (L524)

And I have noticed there are also a handful of "in the wild" users who have deployed it to similar effect, especially in the case of rejecting any value of a certain number or greater. It simply makes it much more ergonomic to write an irrefutable match, as done in Katholieke Universiteit Leuven's [SCALE and MAMBA project](05e5db00d5/WebAssembly/scale_std/src/fixed_point.rs (L685-L695)).

## Tests
There were already many tests in [src/test/ui/half-open-range/patterns](90a2e5e3fe/src/test/ui/half-open-range-patterns), as well as [generic pattern tests that test the `exclusive_range_pattern` feature](673d0db5e3/src/test/ui/pattern/usefulness/integer-ranges/reachability.rs), many dating back to the feature's introduction and remaining standing to this day. However, this stabilization comes with some additional tests to explore the... sometimes interesting behavior of interactions with other patterns. e.g. There is, at least, a mild diagnostic improvement in some edge cases, because before now, the pattern `0..=(5+1)` encounters the `half_open_range_patterns` feature gate and can thus emit the request to enable the feature flag, while also emitting the "inclusive range with no end" diagnostic. There is no intent to allow an `X..=` pattern that I am aware of, so removing the flag request is a strict improvement. The arrival of the `J | K` "or" pattern also enables some odd formations.

Some of the behavior tested for here is derived from experiments in this [Playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=58777b3c715c85165ac4a70d93efeefc) example, linked at https://github.com/rust-lang/rust/issues/67264#issuecomment-812770692, which may be useful to reference to observe the current behavior more closely.

In addition tests constituting an explanation of the "slicing range patterns" syntax issue are included in this PR.

## Desiderata

The exclusive range patterns and half-open range patterns are fairly strongly requested by many authors, as they make some patterns much more natural to write, but there is disagreement regarding the "closed" exclusive range pattern or the "RangeTo" pattern, especially where it creates "off by one" gaps in the presence of a "catch-all" wildcard case. Also, there are obviously no range analyses in place that will force diagnostics for e.g. highly overlapping matches. I believe these should be warned on, ideally, and I think it would be reasonable to consider such a blocker to stabilizing this feature, but there is no technical issue with the feature as-is from the purely syntactic perspective as such overlapping or missed matches can already be generated today with such a catch-all case. And part of the "point" of the feature, at least from my view, is to make it easier to omit wildcard matches: a pattern with such an "open" match produces an irrefutable match and does not need the wild card case, making it easier to benefit from exhaustiveness checking.

## History

- Implemented:
  - Partially via exclusive ranges: https://github.com/rust-lang/rust/pull/35712
  - Fully with half-open ranges: https://github.com/rust-lang/rust/pull/67258
- Unresolved Questions:
  - The precedence concerns of https://github.com/rust-lang/rust/pull/48501 were considered as likely requiring adjustment but probably wanting a uniform consistent change across all pattern styles, given https://github.com/rust-lang/rust/issues/67264#issuecomment-720711656, but it is still unknown what changes might be desired
  - How we want to handle slice patterns in ranges seems to be an open question still, as witnessed in the discussion of this PR!

I checked but I couldn't actually find an RFC for this, and given "approved provisionally by lang team without an RFC", I believe this might require an RFC before it can land? Unsure of procedure here, on account of this being stabilizing a subset of a feature of syntax.

r? `@scottmcm`
2021-07-11 06:31:42 +00:00
Yuki Okushi
463301aa5a
Rollup merge of #86932 - rylev:fix-ice-86895, r=estebank
Fix ICE when misplaced visibility cannot be properly parsed

Fixes #86895

The issue was that a failure to parse the visibility was causing the original error to be dropped before being emitted.

The resulting error isn't quite as nice as when the visibility is parsed properly, but I'm not sure which error to prioritize here. Displaying both errors might be too confusing.

r? ```@estebank```
2021-07-08 10:44:34 +09:00
Yuki Okushi
165b520b89
Rollup merge of #86812 - FabianWolff:recover-dyn-mut, r=petrochenkov
Recover from `&dyn mut ...` parse errors

Consider this example:
```rust
fn main() {
    let r: &dyn mut Trait;
}
```
This currently leads to:
```
error: expected one of `!`, `(`, `;`, `=`, `?`, `for`, lifetime, or path, found keyword `mut`
 --> src/main.rs:2:17
  |
2 |     let r: &dyn mut Trait;
  |                 ^^^ expected one of 8 possible tokens

error: aborting due to previous error
```
However, especially for beginners, I think it is easy to get `&dyn mut` and `&mut dyn` confused. With my changes, I get a help message, and the parser even recovers:
```
error: `mut` must precede `dyn`
 --> test.rs:2:12
  |
2 |     let r: &dyn mut Trait;
  |            ^^^^^^^^ help: place `mut` before `dyn`: `&mut dyn`

error[E0405]: cannot find trait `Trait` in this scope
 --> test.rs:2:21
  |
2 |     let r: &dyn mut Trait;
  |                     ^^^^^ not found in this scope

error: aborting due to 2 previous errors
```
2021-07-08 10:44:30 +09:00
Ryan Levick
04a9c10fc2 Fix ICE when misplaced visibility cannot be properly parsed 2021-07-07 15:02:20 +02:00
Ryan Levick
d4e384bc1d rename rust_2021_token_prefixes to rust_2021_prefixes_incompatible_syntax 2021-07-06 20:13:36 +02:00
Ryan Levick
81c11a212e rust_2021_token_prefixes 2021-07-06 20:13:16 +02:00
Ryan Levick
6c87772e3c Rename reserved_prefix lint to reserved_prefixes 2021-07-06 20:12:55 +02:00
Aaron Hill
5c9bd9c2b4
Recover from a misplaced inner doc comment
Fixes #86781
2021-07-02 11:47:26 -05:00
Fabian Wolff
c692896ba2 Recover from &dyn mut ... parse errors 2021-07-02 17:07:32 +02:00
bors
1034282bca Auto merge of #86617 - joshtriplett:prune-dependencies, r=Mark-Simulacrum
Remove unused dependencies from compiler crates

Various compiler crates have dependencies that they don't appear to use. I used some scripting to detect such dependencies, filtered them based on some manual review, and removed those that do indeed appear to be entirely unused.
2021-07-01 03:49:47 +00:00
Mara Bos
7490305e13 No reserved_prefix suggestion in proc macro call_site. 2021-06-26 23:11:14 +08:00
Mara Bos
0eeeebc990 Rename 'bad prefix' to 'unknown prefix'. 2021-06-26 23:11:14 +08:00
Mara Bos
d40be0fc64 Check the span's edition for the reserved prefixes. 2021-06-26 23:11:13 +08:00
Mara Bos
6adce70a58 Improve comments for reserved prefixes.
Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
2021-06-26 23:11:13 +08:00
Mara Bos
d837c00d10 Add migration lint for reserved prefixes. 2021-06-26 23:11:04 +08:00
Mara Bos
ce43fc9404 Fix note in reserved prefix error. 2021-06-26 23:09:43 +08:00
Mara Bos
c856e6fa53 Add machine applicable suggestion to unknown prefix error. 2021-06-26 23:09:43 +08:00
lrh2000
8dee9bc8fc Reserve prefixed identifiers and string literals (RFC 3101)
This commit denies any identifiers immediately followed by
one of three tokens `"`, `'` or `#`, which is stricter than
the requirements of RFC 3101 but may be necessary according
to the discussion at [Zulip].

[Zulip]: https://rust-lang.zulipchat.com/#narrow/stream/268952-edition-2021/topic/reserved.20prefixes/near/238470099
2021-06-26 23:09:43 +08:00
bors
481971978f Auto merge of #86586 - Smittyvb:https-everywhere, r=petrochenkov
Use HTTPS links where possible

While looking at #86583, I wondered how many other (insecure) HTTP links were in `rustc`. This changes most other `http` links to `https`. While most of the links are in comments or documentation, there are a few other HTTP links that are used by CI that are changed to HTTPS.

Notes:
- I didn't change any to or in licences
- Some links don't support HTTPS :(
- Some `http` links were dead, in those cases I upgraded them to their new places (all of which used HTTPS)
2021-06-26 08:24:31 +00:00
Josh Triplett
7d75cac8e6 rustc_parse: Remove unused dependency smallvec
Unused since commit 530a629635
("Remove pretty-print/reparse hack, and add derive-specific hack").
2021-06-25 01:12:59 -07:00
Smitty
bdfcb88e8b Use HTTPS links where possible 2021-06-23 16:26:46 -04:00
bors
6a758ea7e4 Auto merge of #85193 - pnkfelix:readd-support-for-inner-attrs-within-match, r=nikomatsakis
Re-add support for parsing (and pretty-printing) inner-attributes in match body

Re-add support for parsing (and pretty-printing) inner-attributes within body of a `match`.

In other words, we can do `match EXPR { #![inner_attr] ARM_1 ARM_2 ... }` again.

I believe this unbreaks the only four crates that crater flagged as broken by PR #83312.

(I am putting this up so that the lang-team can check it out and decide whether it changes their mind about what to do regarding PR #83312.)
2021-06-22 21:17:12 +00:00
Yuki Okushi
4f8e0ebcc5
Use AttrVec for Arm, FieldDef, and Variant 2021-06-17 08:04:54 +09:00
Ryan Levick
6936349233 Add support for using qualified paths with structs in expression and pattern
position.
2021-06-10 13:18:41 +02:00
Guillaume Gomez
1bef90fb25
Rollup merge of #86010 - FabianWolff:ICE-parser, r=varkor
Fix two ICEs in the parser

This pull request fixes #84104 and fixes #84148. The latter is caused by an invalid `assert_ne!()` in the parser, which I have simply removed because the error is then caught in another part of the parser.

#84104 is somewhat more subtle and has to do with a suggestion to remove extraneous `<` characters; for instance:
```rust
fn main() {
    foo::<Ty<<<i32>();
}
```
currently leads to
```
error: unmatched angle brackets
 --> unmatched-langle.rs:2:10
  |
2 |     foo::<Ty<<<i32>();
  |          ^^^ help: remove extra angle brackets
```
which is obviously wrong and stems from the fact that the code for issuing the above suggestion does not consider the possibility that there might be other tokens in between the opening angle brackets. In #84104, this has led to a span being generated that ends in the middle of a multi-byte character (because the code issuing the suggestion thought that it was only skipping over `<`, which are single-byte), causing an ICE.
2021-06-07 01:06:52 +02:00
Vadim Petrochenkov
cbdfa1edca parser: Ensure that all nonterminals have tokens after parsing 2021-06-06 14:21:12 +03:00
Fabian Wolff
6a6a605a61 Fix handling of unmatched angle brackets in parser 2021-06-05 00:31:28 +02:00
Fabian Wolff
4e219e6335 Remove incorrect assertion in type parsing code 2021-06-04 22:17:04 +02:00
marcusdunn
a11c8e7ff3 replaced feature-gate use with cfg_attr 2021-06-04 09:42:50 -07:00
Yuki Okushi
36f1ed6de2
Rollup merge of #85850 - bjorn3:less_feature_gates, r=jyn514
Remove unused feature gates

The first commit removes a usage of a feature gate, but I don't expect it to be controversial as the feature gate was only used to workaround a limitation of rust in the past. (closures never being `Clone`)

The second commit uses `#[allow_internal_unstable]` to avoid leaking the `trusted_step` feature gate usage from inside the index newtype macro. It didn't work for the `min_specialization` feature gate though.

The third commit removes (almost) all feature gates from the compiler that weren't used anyway.
2021-06-04 13:42:54 +09:00
bjorn3
312f964478 Remove unused feature gates 2021-05-31 13:55:43 +02:00
LeSeulArtichaut
b237f90ab9 Don't drop PResult without handling the error 2021-05-30 00:08:42 +02:00
Pietro Albini
9e22b844dd remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
Joshua Nelson
e48b6b4599 Stabilize extended_key_value_attributes
# Stabilization report

 ## Summary

This stabilizes using macro expansion in key-value attributes, like so:

 ```rust
 #[doc = include_str!("my_doc.md")]
 struct S;

 #[path = concat!(env!("OUT_DIR"), "/generated.rs")]
 mod m;
 ```

See the changes to the reference for details on what macros are allowed;
see Petrochenkov's excellent blog post [on internals](https://internals.rust-lang.org/t/macro-expansion-points-in-attributes/11455)
for alternatives that were considered and rejected ("why accept no more
and no less?")

This has been available on nightly since 1.50 with no major issues.

 ## Notes

 ### Accepted syntax

The parser accepts arbitrary Rust expressions in this position, but any expression other than a macro invocation will ultimately lead to an error because it is not expected by the built-in expression forms (e.g., `#[doc]`).  Note that decorators and the like may be able to observe other expression forms.

 ### Expansion ordering

Expansion of macro expressions in "inert" attributes occurs after decorators have executed, analogously to macro expressions appearing in the function body or other parts of decorator input.

There is currently no way for decorators to accept macros in key-value position if macro expansion must be performed before the decorator executes (if the macro can simply be copied into the output for later expansion, that can work).

 ## Test cases

 - https://github.com/rust-lang/rust/blob/master/src/test/ui/attributes/key-value-expansion-on-mac.rs
 - https://github.com/rust-lang/rust/blob/master/src/test/rustdoc/external-doc.rs

The feature has also been dogfooded extensively in the compiler and
standard library:

- https://github.com/rust-lang/rust/pull/83329
- https://github.com/rust-lang/rust/pull/83230
- https://github.com/rust-lang/rust/pull/82641
- https://github.com/rust-lang/rust/pull/80534

 ## Implementation history

- Initial proposal: https://github.com/rust-lang/rust/issues/55414#issuecomment-554005412
- Experiment to see how much code it would break: https://github.com/rust-lang/rust/pull/67121
- Preliminary work to restrict expansion that would conflict with this
feature: https://github.com/rust-lang/rust/pull/77271
- Initial implementation: https://github.com/rust-lang/rust/pull/78837
- Fix for an ICE: https://github.com/rust-lang/rust/pull/80563

 ## Unresolved Questions

~~https://github.com/rust-lang/rust/pull/83366#issuecomment-805180738 listed some concerns, but they have been resolved as of this final report.~~

 ## Additional Information

 There are two workarounds that have a similar effect for `#[doc]`
attributes on nightly. One is to emulate this behavior by using a limited version of this feature that was stabilized for historical reasons:

```rust
macro_rules! forward_inner_docs {
    ($e:expr => $i:item) => {
        #[doc = $e]
        $i
    };
}

forward_inner_docs!(include_str!("lib.rs") => struct S {});
```

This also works for other attributes (like `#[path = concat!(...)]`).
The other is to use `doc(include)`:

```rust
 #![feature(external_doc)]
 #[doc(include = "lib.rs")]
 struct S {}
```

The first works, but is non-trivial for people to discover, and
difficult to read and maintain. The second is a strange special-case for
a particular use of the macro. This generalizes it to work for any use
case, not just including files.

I plan to remove `doc(include)` when this is stabilized. The
`forward_inner_docs` workaround will still compile without warnings, but
I expect it to be used less once it's no longer necessary.
2021-05-18 01:01:36 -04:00
jedel1043
059b68dd67 Implement Anonymous{Struct, Union} in the AST
Add unnamed_fields feature gate and gate unnamed fields on parsing
2021-05-16 09:49:16 -05:00
Guillaume Gomez
94617802a1
Rollup merge of #84793 - estebank:parse-struct-field-default, r=davidtwco
Recover from invalid `struct` item syntax

Parse unsupported "default field const values":

```rust
struct S {
    field: Type = const_val,
}
```

Recover from small `:` typo and provide suggestion:

```rust
struct S {
    field; Type,
    field2= Type,
}
```
2021-05-12 17:19:25 +02:00
bors
e1ff91f439 Auto merge of #83813 - cbeuw:remap-std, r=michaelwoerister
Fix `--remap-path-prefix` not correctly remapping `rust-src` component paths and unify handling of path mapping with virtualized paths

This PR fixes #73167 ("Binaries end up containing path to the rust-src component despite `--remap-path-prefix`") by preventing real local filesystem paths from reaching compilation output if the path is supposed to be remapped.

`RealFileName::Named` introduced in #72767 is now renamed as `LocalPath`, because this variant wraps a (most likely) valid local filesystem path.

`RealFileName::Devirtualized` is renamed as `Remapped` to be used for remapped path from a real path via `--remap-path-prefix` argument, as well as real path inferred from a virtualized (during compiler bootstrapping) `/rustc/...` path. The `local_path` field is now an `Option<PathBuf>`, as it will be set to `None` before serialisation, so it never reaches any build output. Attempting to serialise a non-`None` `local_path` will cause an assertion faliure.

When a path is remapped, a `RealFileName::Remapped` variant is created. The original path is preserved in `local_path` field and the remapped path is saved in `virtual_name` field. Previously, the `local_path` is directly modified which goes against its purpose of "suitable for reading from the file system on the local host".

`rustc_span::SourceFile`'s fields `unmapped_path` (introduced by #44940) and `name_was_remapped` (introduced by #41508 when `--remap-path-prefix` feature originally added) are removed, as these two pieces of information can be inferred from the `name` field: if it's anything other than a `FileName::Real(_)`, or if it is a `FileName::Real(RealFileName::LocalPath(_))`, then clearly `name_was_remapped` would've been false and `unmapped_path` would've been `None`. If it is a `FileName::Real(RealFileName::Remapped{local_path, virtual_name})`, then `name_was_remapped` would've been true and `unmapped_path` would've been `Some(local_path)`.

cc `@eddyb` who implemented `/rustc/...` path devirtualisation
2021-05-12 11:05:56 +00:00
Esteban Küber
7697ce4560 Recover from invalid struct item syntax
Parse unsupported "default field const values":

```rust
struct S {
    field: Type = const_val,
}
```

Recover from small `:` typo and provide suggestion:

```rust
struct S {
    field; Type,
    field2= Type,
}
```
2021-05-11 18:48:57 -07:00
Felix S. Klock II
75d6293128 Re-add support for parsing (and pretty-printing) inner-attributes within body of a match.
In other words, we can do `match EXPR { #![inner_attr] ARM_1 ARM_2 ... }` again.

I believe this unbreaks the only four crates that crater flagged as broken by PR 83312.

(I am putting this up so that the lang-team can check it out and decide whether
it changes their mind about what to do regarding PR 83312.)
2021-05-11 15:18:09 -04:00
bors
2fb1dee14b Auto merge of #85104 - hi-rustin:rustin-patch-typo, r=jonas-schievink
Fix typo
2021-05-10 07:15:23 +00:00
hi-rustin
fc544abe03 Fix typo 2021-05-09 12:24:58 +08:00
Joshua Nelson
96509b4835 Make Diagnostic::span_fatal unconditionally raise an error
It had no callers which didn't immediately call `raise()`, and this
unifies the behavior with `Session`.
2021-05-08 23:12:04 -04:00
Joshua Nelson
e49f4471aa Remove some unnecessary uses of struct_span_fatal
All of them immediately called `emit()` then `raise()`, so they could
just call `span_fatal` directly.
2021-05-08 23:12:04 -04:00
Joshua Nelson
955fdaea4a Rename Parser::span_fatal_err -> Parser::span_err
The name was misleading, it wasn't actually a fatal error.
2021-05-08 23:11:59 -04:00
Dylan DPC
eb36bc666a
Rollup merge of #76808 - LeSeulArtichaut:diagnose-functions-struct, r=jackh726
Improve diagnostics for functions in `struct` definitions

Tries to implement #76421.
This is probably going to need unit tests, but I wanted to hear from review all the cases tests should cover.

I'd like to follow up with the "mechanically applicable suggestion here that adds an impl block" step, but I'd need guidance. My idea for now would be to try to parse a function, and if that succeeds, create a dummy `ast::Item` impl block to then format it using `pprust`. Would that be a viable approach? Is there a better alternative?

r? `@matklad` cc `@estebank`
2021-05-08 01:06:22 +02:00
LeSeulArtichaut
6717f81b96 Also take unions and enums into account 2021-05-07 22:49:47 +02:00
LeSeulArtichaut
cecb3be49a Improve diagnostics for functions in struct definitions 2021-05-07 21:44:10 +02:00
Dylan DPC
b44e56f968
Rollup merge of #84896 - estebank:issue-84772, r=jackh726
Handle incorrect placement of parentheses in trait bounds more gracefully

Fix #84772.

CC ``````@jonhoo``````
2021-05-07 00:38:42 +02:00
Andy Wang
5417b45c26
Use local and remapped paths where appropriate 2021-05-05 15:31:28 +01:00
Esteban Küber
6b64202d5e Handle incorrect placement of parentheses in trait bounds more gracefully
Fix #84772.
2021-05-03 23:48:56 -07:00
Vadim Petrochenkov
1443c7646d parser: Remove support for inner attributes on non-block expressions 2021-05-03 13:33:53 +03:00
bors
ca075d268d Auto merge of #83386 - mark-i-m:stabilize-pat2015, r=nikomatsakis
Stabilize `:pat_param` and remove `:pat2021`

Blocked on #83384

cc `@rust-lang/lang` #79278

If I understand `@nikomatsakis` in  https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/or.20patterns/near/231133873, another FCP is not needed.

r? `@nikomatsakis`
2021-04-28 20:35:17 +00:00
mark
2a9db919ff remove pat2021 2021-04-27 21:15:59 -05:00
Santiago Pastorino
0e4d2fd447
Revert "Rollup merge of #82296 - spastorino:pubrules, r=nikomatsakis"
This reverts commit e2561c58a4, reversing
changes made to 2982ba50fc.
2021-04-23 10:40:32 -03:00
klensy
f43ee8ebf6 fix few typos 2021-04-19 15:57:08 +03:00
mark
0566ccc72f rename pat2015 to pat_param 2021-04-15 13:52:09 -05:00
bors
16bf626a31 Auto merge of #84130 - Aaron1011:fix/none-delim-lookahead, r=petrochenkov
Fix lookahead with None-delimited group

Fixes https://github.com/rust-lang/rust/issues/84162, a regression introduced by https://github.com/rust-lang/rust/pull/82608.
2021-04-14 20:45:23 +00:00
Aaron Hill
c6d67f8317
Add fast path when None delimiters are not involved 2021-04-12 17:26:26 -04:00
b-naber
dd54459bfc don't bump in check_mistyped_turbofish_with_multiple_type_params 2021-04-12 21:09:04 +02:00
Aaron Hill
eb7b1a150f
Fix lookahead with None-delimited group 2021-04-12 11:50:16 -04:00
Aaron Hill
a93c4f05de
Implement token-based handling of attributes during expansion
This PR modifies the macro expansion infrastructure to handle attributes
in a fully token-based manner. As a result:

* Derives macros no longer lose spans when their input is modified
  by eager cfg-expansion. This is accomplished by performing eager
  cfg-expansion on the token stream that we pass to the derive
  proc-macro
* Inner attributes now preserve spans in all cases, including when we
  have multiple inner attributes in a row.

This is accomplished through the following changes:

* New structs `AttrAnnotatedTokenStream` and `AttrAnnotatedTokenTree` are introduced.
  These are very similar to a normal `TokenTree`, but they also track
  the position of attributes and attribute targets within the stream.
  They are built when we collect tokens during parsing.
  An `AttrAnnotatedTokenStream` is converted to a regular `TokenStream` when
  we invoke a macro.
* Token capturing and `LazyTokenStream` are modified to work with
  `AttrAnnotatedTokenStream`. A new `ReplaceRange` type is introduced, which
  is created during the parsing of a nested AST node to make the 'outer'
  AST node aware of the attributes and attribute target stored deeper in the token stream.
* When we need to perform eager cfg-expansion (either due to `#[derive]` or `#[cfg_eval]`),
we tokenize and reparse our target, capturing additional information about the locations of
`#[cfg]` and `#[cfg_attr]` attributes at any depth within the target.
This is a performance optimization, allowing us to perform less work
in the typical case where captured tokens never have eager cfg-expansion run.
2021-04-11 01:31:36 -04:00
bors
481598b26d Auto merge of #84024 - estebank:unclosed-brace-use, r=jackh726
Avoid `;` -> `,` recovery and unclosed `}` recovery from being too verbose

Those two recovery attempts have a very bad interaction that causes too
unnecessary output. Add a simple gate to avoid interpreting a `;` as a
`,` when there are unclosed braces.

Fix #83498.
2021-04-10 03:02:46 +00:00
Esteban Küber
0d7167698f Avoid ; -> , recovery and unclosed } recovery from being too verbose
Those two recovery attempts have a very bad interaction that causes too
unnecessary output. Add a simple gate to avoid interpreting a `;` as a
`,` when there are unclosed braces.
2021-04-09 10:22:41 -07:00
Dylan DPC
74b23f9d11
Rollup merge of #83980 - pierwill:fix-compiler-librustc-names, r=davidtwco
Fix outdated crate names in compiler docs

Changes `librustc_X` to `rustc_X`, only in documentation comments.
Plain code comments are left unchanged.
2021-04-08 20:29:58 +02:00
pierwill
0019ca9141 Fix outdated crate names in compiler docs
Changes `librustc_X` to `rustc_X`, only in documentation comments.
Plain code comments are left unchanged.

Also fix incorrect file paths.
2021-04-08 11:12:14 -05:00
Amanieu d'Antras
32be124e30 Use AnonConst for asm! constants 2021-04-06 12:35:41 +01:00
Jubilee Young
91bc117e53 Allow exclusive range-from patterns 2021-04-05 22:02:18 -07:00
Aaron Hill
f94360fd83
Always preserve None-delimited groups in a captured TokenStream
Previously, we would silently remove any `None`-delimiters when
capturing a `TokenStream`, 'flattenting' them to their inner tokens.
This was not normally visible, since we usually have
`TokenKind::Interpolated` (which gets converted to a `None`-delimited
group during macro invocation) instead of an actual `None`-delimited
group.

However, there are a couple of cases where this becomes visible to
proc-macros:
1. A cross-crate `macro_rules!` macro has a `None`-delimited group
   stored in its body (as a result of being produced by another
   `macro_rules!` macro). The cross-crate `macro_rules!` invocation
   can then expand to an attribute macro invocation, which needs
   to be able to see the `None`-delimited group.
2. A proc-macro can invoke an attribute proc-macro with its re-collected
   input. If there are any nonterminals present in the input, they will
   get re-collected to `None`-delimited groups, which will then get
   captured as part of the attribute macro invocation.

Both of these cases are incredibly obscure, so there hopefully won't be
any breakage. This change will allow more agressive 'flattenting' of
nonterminals in #82608 without losing `None`-delimited groups.
2021-03-26 23:32:18 -04:00
Aaron Hill
7504b9bb96
Avoid double-collection for expression nonterminals 2021-03-25 18:05:49 -04:00
Yuki Okushi
50d048f142
Rollup merge of #83384 - mark-i-m:rename-pat2018, r=joshtriplett
rename :pat2018 -> :pat2015

as requested by T-lang on zulip: https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/or.20patterns/near/231133873

No functional changes here... just renaming.

r? `@nikomatsakis`
2021-03-23 10:15:43 +09:00
mark
8c4b3dbb50 rename :pat2018 -> :pat215 2021-03-22 12:40:23 -05:00
mark
db5629adcb stabilize or_patterns 2021-03-19 19:45:32 -05:00
bors
81c1d7a150 Auto merge of #76447 - pickfire:async-pub, r=estebank
Detect async visibility wrong order, `async pub`

Partially address #76437.
2021-03-18 02:32:39 +00:00
bors
b4adc21c4f Auto merge of #83188 - petrochenkov:field, r=lcnr
ast/hir: Rename field-related structures

I always forget what `ast::Field` and `ast::StructField` mean despite working with AST for long time, so this PR changes the naming to less confusing and more consistent.

- `StructField` -> `FieldDef` ("field definition")
- `Field` -> `ExprField` ("expression field", not "field expression")
- `FieldPat` -> `PatField` ("pattern field", not "field pattern")

Various visiting and other methods working with the fields are renamed correspondingly too.

The second commit reduces the size of `ExprKind` by boxing fields of `ExprKind::Struct` in preparation for https://github.com/rust-lang/rust/pull/80080.
2021-03-17 16:49:46 +00:00
Ivan Tham
21c157442c Add pub as optional check_front_matter
async-pub check created a regression for default
2021-03-17 09:04:08 +08:00
Ivan Tham
9321efd8f7 Detect pub fn attr wrong order like async pub
Redirects `const? async? unsafe? pub` to `pub const? async? unsafe?`.

Fix #76437
2021-03-17 09:02:19 +08:00
Yuki Okushi
2d99e68940 Emit more pretty diagnostics for qualified paths 2021-03-17 09:57:58 +09:00
Yuki Okushi
8240f1a3d3 Fix bad diagnostics for anon params with qualified paths 2021-03-17 07:45:19 +09:00
Yuki Okushi
ea355bc6be Fix bad diagnostics for anon params with ref 2021-03-17 07:45:19 +09:00
Vadim Petrochenkov
d1522b39dd ast: Reduce size of ExprKind by boxing fields of ExprKind::Struct 2021-03-16 11:41:24 +03:00
Vadim Petrochenkov
b25d3ba781 ast/hir: Rename field-related structures
StructField -> FieldDef ("field definition")
Field -> ExprField ("expression field", not "field expression")
FieldPat -> PatField ("pattern field", not "field pattern")

Also rename visiting and other methods working on them.
2021-03-16 11:41:24 +03:00
bors
3963c3da02 Auto merge of #83074 - Aaron1011:new-sort-fix, r=jackh726
Avoid sorting predicates by `DefId`

Fixes issue #82920

Even if an item does not change between compilation sessions, it may end
up with a different `DefId`, since inserting/deleting an item affects
the `DefId`s of all subsequent items. Therefore, we use a `DefPathHash`
in the incremental compilation system, which is stable in the face of
changes to unrelated items.

In particular, the query system will consider the inputs to a query to
be unchanged if any `DefId`s in the inputs have their `DefPathHash`es
unchanged. Queries are pure functions, so the query result should be
unchanged if the query inputs are unchanged.

Unfortunately, it's possible to inadvertantly make a query result
incorrectly change across compilations, by relying on the specific value
of a `DefId`. Specifically, if the query result is a slice that gets
sorted by `DefId`, the precise order will depend on how the `DefId`s got
assigned in a particular compilation session. If some definitions end up
with different `DefId`s (but the same `DefPathHash`es) in a subsequent
compilation session, we will end up re-computing a *different* value for
the query, even though the query system expects the result to unchanged
due to the unchanged inputs.

It turns out that we have been sorting the predicates computed during
`astconv` by their `DefId`. These predicates make their way into the
`super_predicates_that_define_assoc_type`, which ends up getting used to
compute the vtables of trait objects. This, re-ordering these predicates
between compilation sessions can lead to undefined behavior at runtime -
the query system will re-use code built with a *differently ordered*
vtable, resulting in the wrong method being invoked at runtime.

This PR avoids sorting by `DefId` in `astconv`, fixing the
miscompilation. However, it's possible that other instances of this
issue exist - they could also be easily introduced in the future.

To fully fix this issue, we should
1. Turn on `-Z incremental-verify-ich` by default. This will cause the
   compiler to ICE whenver an 'unchanged' query result changes between
   compilation sessions, instead of causing a miscompilation.
2. Remove the `Ord` impls for `CrateNum` and `DefId`. This will make it
   difficult to introduce ICEs in the first place.
2021-03-15 06:20:24 +00:00
Aaron Hill
18f89790da
Bump recursion_limit in a few places
This is needed to get rustdoc to succeed on `dist-x86_64-linux-alt`
2021-03-14 23:02:01 -04:00
Yuki Okushi
0466b6ac6d Improve the wording for the can't reassign error 2021-03-13 06:06:54 +09:00
Mara Bos
0d97f9b22a
Rollup merge of #82048 - mark-i-m:or-pat-type-ascription, r=petrochenkov
or-patterns: disallow in `let` bindings

~~Blocked on https://github.com/rust-lang/rust/pull/81869~~

Disallows top-level or-patterns before type ascription. We want to reserve this syntactic space for possible future generalized type ascription.

r? ``@petrochenkov``
2021-03-09 09:05:20 +00:00
Vadim Petrochenkov
069e612e73 rustc_ast: Replace AstLike::finalize_tokens with a getter tokens_mut 2021-03-06 21:19:31 +03:00
mark
e64138c534 use pat<no_top_alt> for patterns in let bindings 2021-03-05 10:10:04 -06:00
Esteban Küber
ae494d147a Detect match arm body without braces
Fix #82524.
2021-03-03 12:17:26 -08:00
Yuki Okushi
906e535205
Rollup merge of #82579 - osa1:issue82566, r=estebank
Fix turbofish recovery with multiple generic args

This consists of two commits, each can be individually reviewed.

- First commit fixes the issue in [this comment](https://github.com/rust-lang/rust/issues/82566#issuecomment-786924466).
- Second commit fixes #82566

---

r? ````@estebank````
2021-03-02 21:23:17 +09:00
Dylan DPC
be3d1eb301
Rollup merge of #81856 - Smittyvb:utf16-warn, r=matthewjasper
Suggest character encoding is incorrect when encountering random null bytes

This adds a note whenever null bytes are seen at the start of a token unexpectedly, since those tend to come from UTF-16 encoded files without a [BOM](https://en.wikipedia.org/wiki/Byte_order_mark) (if a UTF-16 BOM appears it won't be valid UTF-8, but if there is no BOM it be both valid UTF-16 and valid but garbled UTF-8). This approach was suggested in https://github.com/rust-lang/rust/issues/73979#issuecomment-653976451.

Closes #73979.
2021-02-27 21:56:15 +01:00
Ömer Sinan Ağacan
992b914b6b Recover from X<Y,Z> when parsing const expr
This adds recovery when in array type syntax user writes

    [X; Y<Z, ...>]

instead of

    [X; Y::<Z, ...>]

Fixes #82566

Note that whenever we parse an expression and know that the next token
cannot be `,`, we should be calling
check_mistyped_turbofish_with_multiple_type_params for this recovery.
Previously we only did this for statement parsing (e.g. `let x = f<a,
b>;`). We now also do it when parsing the length field in array type
syntax.
2021-02-27 14:06:57 +03:00
Ömer Sinan Ağacan
fb631a55c2 Fix turbofish recovery with multiple generic args
check_mistyped_turbofish_with_multiple_type_params was previously
expecting type arguments between angle brackets, which is not right, as
we can also see const expressions. We now use generic argument parser
instead of type parser.

Test with one, two, and three generic arguments added to check
consistentcy between

1. check_no_chained_comparison: Called after parsing a nested binop
   application like `x < A > ...` where angle brackets are interpreted as
   binary operators and `A` is an expression.

2. check_mistyped_turbofish_with_multiple_type_params: called by
   `parse_full_stmt` when we expect to see a semicolon after parsing an
   expression but don't see it.

   (In `T2<1, 2>::C;`, the expression is `T2 < 1`)
2021-02-27 13:46:49 +03:00
Aaron Hill
fb5fec017b
Combine HasAttrs and HasTokens into AstLike
When token-based attribute handling is implemeneted in #80689,
we will need to access tokens from `HasAttrs` (to perform
cfg-stripping), and we will to access attributes from `HasTokens` (to
construct a `PreexpTokenStream`).

This PR merges the `HasAttrs` and `HasTokens` traits into a new
`AstLike` trait. The previous `HasAttrs` impls from `Vec<Attribute>` and `AttrVec`
are removed - they aren't attribute targets, so the impls never really
made sense.
2021-02-27 00:14:13 -05:00
Guillaume Gomez
039b1b62ac
Rollup merge of #82456 - klensy:or-else, r=estebank
Replaced some unwrap_or and map_or with lazy variants

Replaced some `unwrap_or` and `map_or` with `unwrap_or_else` and `map_or_else`.
2021-02-26 15:52:31 +01:00
Dylan DPC
20928e0cbf
Rollup merge of #82321 - bugadani:ast3, r=varkor
AST: Remove some unnecessary boxes
2021-02-25 14:34:03 +01:00
klensy
08b1e8004b fix review 2021-02-25 04:21:12 +03:00
klensy
c75c4a579b replaced some map_or with map_or_else 2021-02-24 02:43:35 +03:00
Dylan DPC
e2561c58a4
Rollup merge of #82296 - spastorino:pubrules, r=nikomatsakis
Support `pub` on `macro_rules`

This rebases and updates `since` version of #78166 from ``@petrochenkov``

r? ``@nikomatsakis``
2021-02-23 16:10:23 +01:00
Dylan DPC
8e51bd4315
Rollup merge of #81235 - reese:rw-tuple-diagnostics, r=estebank
Improve suggestion for tuple struct pattern matching errors.

Closes #80174

This change allows numbers to be parsed as field names when pattern matching on structs, which allows us to provide better error messages when tuple structs are matched using a struct pattern.

r? ``@estebank``
2021-02-23 02:51:44 +01:00
Matthias Krüger
85bd00fd85 parser: remove unneccessary wrapping of return value in parse_extern() 2021-02-21 13:25:12 +01:00
Matthias Krüger
00bc134e43 remove unneccessary wrapping of return value in mk_await_expr() 2021-02-21 13:01:01 +01:00
Matthias Krüger
12080dc3a3 rustc_parse: remove unneccessary wrapping of return value in fn mk_range() which would always return Ok(..) 2021-02-21 12:54:49 +01:00
Dániel Buga
10f234240d Remove some P-s 2021-02-20 10:51:26 +01:00
Vadim Petrochenkov
0fddc2f780
Support pub on macro_rules 2021-02-19 13:52:57 -03:00
Dylan DPC
30f39fee9d
Rollup merge of #82238 - petrochenkov:nocratemod, r=Aaron1011
ast: Keep expansion status for out-of-line module items

I.e. whether a module `mod foo;` is already loaded from a file or not.
This is a pre-requisite to correctly treating inner attributes on such modules (https://github.com/rust-lang/rust/issues/81661).

With this change AST structures for `mod` items diverge even more for AST structure for the crate root, which previously used `ast::Mod`.
Therefore this PR removes `ast::Mod` from `ast::Crate` in the first commit, these two things are sufficiently different from each other, at least at syntactic level.
Customization points for visiting a "`mod` item or crate root" were also removed from AST visitors (`fn visit_mod`).
`ast::Mod` itself was refactored away in the second commit in favor of `ItemKind::Mod(Unsafe, ModKind)`.
2021-02-19 02:49:08 +01:00
Dylan DPC
04df75a429
Rollup merge of #82236 - matthiaskrgr:useless_conv, r=jyn514
avoid converting types into themselves (clippy::useless_conversion)
2021-02-18 16:57:40 +01:00
Vadim Petrochenkov
4a88165124 ast: Keep expansion status for out-of-line module items
Also remove `ast::Mod` which is mostly redundant now
2021-02-18 13:07:49 +03:00
Vadim Petrochenkov
eb65f15c78 ast: Stop using Mod in Crate
Crate root is sufficiently different from `mod` items, at least at syntactic level.

Also remove customization point for "`mod` item or crate root" from AST visitors.
2021-02-18 13:07:49 +03:00
Matthias Krüger
ec50a2086a avoid converting types into themselves (clippy::useless_conversion) 2021-02-17 20:37:09 +01:00
mark
aee1e59e6f Simplify pattern grammar by allowing nested leading vert
Along the way, we also implement a handful of diagnostics improvements
and fixes, particularly with respect to the special handling of `||` in
place of `|` and when there are leading verts in function params, which
don't allow top-level or-patterns anyway.
2021-02-15 12:07:54 -06:00
bors
9503ea19ed Auto merge of #82103 - Dylan-DPC:rollup-5wv8rid, r=Dylan-DPC
Rollup of 11 pull requests

Successful merges:

 - #80523 (#[doc(inline)] sym_generated)
 - #80920 (Visit more targets when validating attributes)
 - #81720 (Updated smallvec version due to RUSTSEC-2021-0003)
 - #81891 ([rustdoc-json] Make `header` a vec of modifiers, and FunctionPointer consistent)
 - #81912 (Implement the precise analysis pass for lint `disjoint_capture_drop_reorder`)
 - #81914 (Fixing bad suggestion for `_` in `const` type when a function #81885)
 - #81919 (BTreeMap: fix internal comments)
 - #81927 (Add a regression test for #32498)
 - #81965 (Fix MIR pretty printer for non-local DefIds)
 - #82029 (Use debug log level for developer oriented logs)
 - #82056 (fix ice (#82032))

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-02-14 22:26:21 +00:00
klensy
93c8ebe022 bumped smallvec deps 2021-02-14 18:03:11 +03:00
Aaron Hill
3321d70161
Address review comments 2021-02-13 13:04:54 -05:00
Aaron Hill
0b411f56e1
Require passing an AttrWrapper to collect_tokens_trailing_token
This is a pure refactoring split out from #80689.
It represents the most invasive part of that PR, requiring changes in
every caller of `parse_outer_attributes`

In order to eagerly expand `#[cfg]` attributes while preserving the
original `TokenStream`, we need to know the range of tokens that
corresponds to every attribute target. This is accomplished by making
`parse_outer_attributes` return an opaque `AttrWrapper` struct. An
`AttrWrapper` must be converted to a plain `AttrVec` by passing it to
`collect_tokens_trailing_token`. This makes it difficult to accidentally
construct an AST node with attributes without calling `collect_tokens_trailing_token`,
since AST nodes store an `AttrVec`, not an `AttrWrapper`.

As a result, we now call `collect_tokens_trailing_token` for attribute
targets which only support inert attributes, such as generic arguments
and struct fields. Currently, the constructed `LazyTokenStream` is
simply discarded. Future PRs will record the token range corresponding
to the attribute target, allowing those tokens to be removed from an
enclosing `collect_tokens_trailing_token` call if necessary.
2021-02-13 12:07:15 -05:00
Ömer Sinan Ağacan
6eb1bd4c3e parser: Fix panic in 'const impl' recovery
The panic happens when in recovery parsing a full `impl`
(`parse_item_impl`) fails and we drop the `DiagnosticBuilder` for the
recovery suggestion and return the `parse_item_impl` error.

We now raise the original error "expected identifier found `impl`" when
parsing the `impl` fails.

Note that the regression test is slightly simplified version of the
original repro in #81806, to make the error output smaller and more
resilient to unrelated changes in parser error messages.

Fixes #81806
2021-02-08 10:46:19 +03:00
Vadim Petrochenkov
dbdbd30bf2 expand/resolve: Turn #[derive] into a regular macro attribute 2021-02-07 20:08:45 +03:00
Smitty
c6cb014ad6 Clarify error message wording 2021-02-07 11:02:53 -05:00
Smitty
651d289405 Add note about encoding when null bytes found 2021-02-06 19:17:14 -05:00
Mara Bos
8d49ca11a2
Rollup merge of #81307 - estebank:invalid-byte-str-span, r=petrochenkov
Handle `Span`s for byte and raw strings and add more detail

CC #81208.
2021-02-05 12:25:53 +01:00
Esteban Küber
3b5d018ebb Handle Spans for byte and raw strings and add more detail 2021-02-03 13:34:28 -08:00
bors
3182375e06 Auto merge of #81405 - bugadani:ast, r=cjgillot
Box the biggest ast::ItemKind variants

This PR is a different approach on https://github.com/rust-lang/rust/pull/81400, aiming to save memory in humongous ASTs.

The three affected item kind enums are:
 - `ast::ItemKind` (208 -> 112 bytes)
 - `ast::AssocItemKind` (176 -> 72 bytes)
 - `ast::ForeignItemKind` (176 -> 72 bytes)
2021-02-02 17:34:08 +00:00
bors
b81f5811f9 Auto merge of #80843 - Mark-Simulacrum:fmt-bump, r=petrochenkov
Bump rustfmt version
2021-02-02 14:52:53 +00:00
Mark Rousskov
d5b760ba62 Bump rustfmt version
Also switches on formatting of the mir build module
2021-02-02 09:09:52 -05:00
Jonas Schievink
255e0764c0
Rollup merge of #81608 - Aaron1011:macro-res-parse-err, r=davidtwco
Improve handling of spans around macro result parse errors

Fixes #81543

After we expand a macro, we try to parse the resulting tokens as a AST
node. This commit makes several improvements to how we handle spans when
an error occurs:

* Only ovewrite the original `Span` if it's a dummy span. This preserves
  a more-specific span if one is available.
* Use `self.prev_token` instead of `self.token` when emitting an error
  message after encountering EOF, since an EOF token always has a dummy
  span
* Make `SourceMap::next_point` leave dummy spans unused. A dummy span
  does not have a logical 'next point', since it's a zero-length span.
  Re-using the span span preserves its 'dummy-ness' for other checks
2021-02-02 12:15:02 +01:00
Dániel Buga
b87e1ecdf0 Box the biggest ast::ItemKind variants 2021-02-01 09:23:39 +01:00
Aaron Hill
6c14aad58e
Improve handling of spans around macro result parse errors
Fixes #81543

After we expand a macro, we try to parse the resulting tokens as a AST
node. This commit makes several improvements to how we handle spans when
an error occurs:

* Only ovewrite the original `Span` if it's a dummy span. This preserves
  a more-specific span if one is available.
* Use `self.prev_token` instead of `self.token` when emitting an error
  message after encountering EOF, since an EOF token always has a dummy
  span
* Make `SourceMap::next_point` leave dummy spans unused. A dummy span
  does not have a logical 'next point', since it's a zero-length span.
  Re-using the span span preserves its 'dummy-ness' for other checks
2021-01-31 15:24:34 -05:00
Jonas Schievink
3e8ae5dcba
Rollup merge of #81472 - Aaron1011:fix/revert-cursor-clone, r=petrochenkov
Clone entire `TokenCursor` when collecting tokens

Reverts PR #80830
Fixes taiki-e/pin-project#312

We can have an arbitrary number of `None`-delimited group frames pushed
on the stack due to proc-macro invocations, which can legally be exited.
Attempting to account for this would add a lot of complexity for a tiny
performance gain, so let's just use the original strategy.
2021-01-31 01:47:34 +01:00
Ikko Ashimine
718398ccaf
Fix typo in pat.rs
parentesized -> parenthesized
2021-01-29 23:30:55 +09:00
Aaron Hill
5d739180cd
Clone entire TokenCursor when collecting tokens
Reverts PR #80830
Fixes taiki-e/pin-project#312

We can have an arbitrary number of `None`-delimited group frames pushed
on the stack due to proc-macro invocations, which can legally be exited.
Attempting to account for this would add a lot of complexity for a tiny
performance gain, so let's just use the original strategy.
2021-01-28 09:47:59 -05:00
Esteban Küber
2e846d6f61 Point only at generic arguments when they are unexpected 2021-01-26 15:59:43 -08:00
Vadim Petrochenkov
bd07165690 parser: Collect tokens for values in key-value attributes 2021-01-24 17:11:56 +03:00
bors
1986b58c64 Auto merge of #80065 - b-naber:parse-angle-arg-diagnostics, r=petrochenkov
Improve diagnostics when parsing angle args

https://github.com/rust-lang/rust/pull/79266 introduced parsing of generic arguments in associated type constraints, this however resulted in possibly very confusing error messages in cases in which closing angle brackets were missing such as in `Vec<(u32, _, _) = vec![]`, which outputs an incorrectly parsed equality constraint error, as noted by `@cynecx.`

This PR tries to provide better error messages in such cases.

r? `@petrochenkov`
2021-01-23 06:27:21 +00:00
bors
693ed05bbd Auto merge of #81017 - Aaron1011:collect-trailing-token, r=petrochenkov
Refactor token collection to capture trailing token immediately

Split out from https://github.com/rust-lang/rust/pull/80689 - when we start capturing more information about attribute targets, we'll need to know in advance if we're capturing a trailing token or not.

r? `@ghost`
2021-01-23 00:42:37 +00:00
b-naber
728d257839 improve diagnostics for angle args 2021-01-22 17:07:27 +01:00
Esteban Küber
8c5dafdcb8 Parse loop labels missing a leading '
When encountering the following typo:

```rust
a: loop { break 'a; }
```

provide an appropriate suggestion.
2021-01-21 21:41:47 -08:00
Aaron Hill
ccfc292999
Refactor token collection to capture trailing token immediately 2021-01-22 00:33:03 -05:00
Reese Williams
8a83c8f64f Improve suggestion for tuple struct pattern matching errors.
Currently, when a user uses a struct pattern to pattern match on
a tuple struct, the errors we emit generally suggest adding fields
using their field names, which are numbers. However, numbers are
not valid identifiers, so the suggestions, which use the shorthand
notation, are not valid syntax. This commit changes those errors
to suggest using the actual tuple struct pattern syntax instead,
which is a more actionable suggestion.
2021-01-20 23:06:19 -05:00
Aaron Hill
11b1e37016
Force token collection to run when parsing nonterminals
Fixes #81007

Previously, we would fail to collect tokens in the proper place when
only builtin attributes were present. As a result, we would end up with
attribute tokens in the collected `TokenStream`, leading to duplication
when we attempted to prepend the attributes from the AST node.

We now explicitly track when token collection must be performed due to
nomterminal parsing.
2021-01-20 18:09:32 -05:00
Yuki Okushi
a584d87417
Rollup merge of #80944 - LingMan:map_or, r=nagisa
Use Option::map_or instead of `.map(..).unwrap_or(..)`

``@rustbot`` modify labels +C-cleanup +T-compiler
2021-01-15 18:26:14 +09:00
bors
dcf622eb70 Auto merge of #80993 - Aaron1011:collect-set-tokens, r=petrochenkov
Set tokens on AST node in `collect_tokens`

A new `HasTokens` trait is introduced, which is used to move logic from
the callers of `collect_tokens` into the body of `collect_tokens`.

In addition to reducing duplication, this paves the way for PR #80689,
which needs to perform additional logic during token collection.
2021-01-15 05:36:48 +00:00