about summary refs log tree commit diff
path: root/src/librustc_parse/parser
AgeCommit message (Collapse)AuthorLines
2020-08-30mv compiler to compiler/mark-10401/+0
2020-08-22Use smaller def span for functionsAaron Hill-4/+14
Currently, the def span of a funtion encompasses the entire function signature and body. However, this is usually unnecessarily verbose - when we are pointing at an entire function in a diagnostic, we almost always want to point at the signature. The actual contents of the body tends to be irrelevant to the diagnostic we are emitting, and just takes up additional screen space. This commit changes the `def_span` of all function items (freestanding functions, `impl`-block methods, and `trait`-block methods) to be the span of the signature. For example, the function ```rust pub fn foo<T>(val: T) -> T { val } ``` now has a `def_span` corresponding to `pub fn foo<T>(val: T) -> T` (everything before the opening curly brace). Trait methods without a body have a `def_span` which includes the trailing semicolon. For example: ```rust trait Foo { fn bar(); }``` the function definition `Foo::bar` has a `def_span` of `fn bar();` This makes our diagnostic output much shorter, and emphasizes information that is relevant to whatever diagnostic we are reporting. We continue to use the full span (including the body) in a few of places: * MIR building uses the full span when building source scopes. * 'Outlives suggestions' use the full span to sort the diagnostics being emitted. * The `#[rustc_on_unimplemented(enclosing_scope="in this scope")]` attribute points the entire scope body. * The 'unconditional recursion' lint uses the full span to show additional context for the recursive call. All of these cases work only with local items, so we don't need to add anything extra to crate metadata.
2020-08-22Auto merge of #74566 - lzutao:guard, r=petrochenkovbors-1/+13
Gate if-let guard feature Enhanced on #74315. That PR is in crater queue so I don't want to push to it. Close #74232 cc #51114
2020-08-20Capture tokens for Pat used in macro_rules! argumentAaron Hill-4/+18
This extends PR #73293 to handle patterns (Pat). Unlike expressions, patterns do not support custom attributes, so we only need to capture tokens during macro_rules! argument parsing.
2020-08-19Rollup merge of #75658 - tgnottingham:issue-75599, r=estebankYuki Okushi-1/+1
Don't emit "is not a logical operator" error outside of associative expressions Avoid showing this error where it doesn't make sense by not assuming "and" and "or" were intended to mean "&&" and "||" until after we decide to continue parsing input as an associative expression. Note that the decision of whether or not to continue parsing input as an associative expression doesn't actually depend on this assumption. Fixes #75599 --- First time contributor! Let me know if there are any conventions or policies I should be following that I missed here. Thanks :)
2020-08-18Don't emit "is not a logical operator" error outside of associative expressionsTyson Nottingham-1/+1
Avoid showing this error where it doesn't make sense by not assuming "and" and "or" were intended to mean "&&" and "||" until after we decide to continue parsing input as an associative expression. Note that the decision of whether or not to continue parsing input as an associative expression doesn't actually depend on this assumption. Fixes #75599
2020-08-17rust_ast::ast => rustc_astUjjwal Sharma-32/+34
2020-08-15replaced log with tracingGurpreet Singh-6/+6
2020-08-14Rollup merge of #75513 - estebank:confused-parser, r=davidtwcoTyler Mandry-1/+1
Recover gracefully from `struct` parse errors Currently the parser tries to recover from finding a keyword where a field name was expected, but this causes extra knock down parse errors that are completely irrelevant. Instead, bail out early in the parsing of the field and consume the remaining tokens in the block. This can reduce output significantly. _Improvements based on the narrative in https://fasterthanli.me/articles/i-am-a-java-csharp-c-or-cplusplus-dev-time-to-do-some-rust_
2020-08-13Recover gracefully from `struct ` parse errorsEsteban Küber-1/+1
2020-08-13Rollup merge of #74650 - estebank:ambiguous-expr-binop, r=eddybTyler Mandry-2/+9
Correctly parse `{} && false` in tail expression Fix #74233, fix #54186.
2020-08-12Auto merge of #75321 - estebank:js-goes-gaga, r=davidtwcobors-0/+23
Detect JS-style `===` and `!==` and recover Fix #75312.
2020-08-10Detect JS-style `===` and `!==` and recoverEsteban Küber-0/+23
Fix #75312.
2020-08-10Rollup merge of #75320 - estebank:js-for-i-of-x, r=davidtwcoYuki Okushi-6/+13
Detect likely `for foo of bar` JS syntax Fix #75311.
2020-08-08Detect likely `for foo of bar` JS syntaxEsteban Küber-6/+13
Fix #75311.
2020-08-08Fallback to pase_expr because match guard accepts struct literalsLzu Tao-1/+1
2020-08-08Gate to if-let guard featureLzu Tao-1/+13
2020-08-08Auto merge of #75276 - JohnTitor:rollup-rz4hs0w, r=JohnTitorbors-0/+2
Rollup of 7 pull requests Successful merges: - #75224 (Don't call a function in function-arguments-naked.rs) - #75237 (Display elided lifetime for non-reference type in doc) - #75250 (make MaybeUninit::as_(mut_)ptr const) - #75253 (clean up const-hacks in int endianess conversion functions) - #75259 (Add missing backtick) - #75267 (Small cleanup) - #75270 (fix a couple of clippy findings) Failed merges: r? @ghost
2020-08-08Rollup merge of #75267 - estebank:cleanup, r=Dylan-DPCYuki Okushi-0/+2
Small cleanup * Add docstring to `Parser` field * Remove unnecessary `unwrap` * Remove unnecessary borrow * Fix indentation of some `teach`text output
2020-08-08Auto merge of #74877 - lcnr:min_const_generics, r=oli-obkbors-1/+1
Implement the `min_const_generics` feature gate Implements both https://github.com/rust-lang/lang-team/issues/37 and https://github.com/rust-lang/compiler-team/issues/332. Adds the new feature gate `#![feature(min_const_generics)]`. This feature gate adds the following limitations to using const generics: - generic parameters must only be used in types if they are trivial. (either `N` or `{ N }`) - generic parameters must be either integers, `bool` or `char`. We do allow arbitrary expressions in associated consts though, meaning that the following is allowed, even if `<[u8; 0] as Foo>::ASSOC` is not const evaluatable. ```rust trait Foo { const ASSOC: usize; } impl<const N: usize> Foo for [u8; N] { const ASSOC: usize = 64 / N; } ``` r? @varkor cc @eddyb @withoutboats
2020-08-07Small cleanupEsteban Küber-0/+2
* Add docstring to `Parser` field * Remove unnecessary `unwrap` * Remove unnecessary borrow * Fix indentation of some `teach`text output
2020-08-06rustc_expand: Don not beautify doc comments before passing them to macrosVadim Petrochenkov-11/+5
Beautify all doc strings in rustdoc instead, including those in `#[doc]` attributes
2020-08-06rustc_ast: Stop using "string typing" for doc comment tokensVadim Petrochenkov-18/+15
Explicitly store their kind and style retrieved during lexing in the token
2020-08-05impl reviewBastian Kauschke-1/+1
2020-08-02Auto merge of #74826 - matklad:mbe-fragment, r=petrochenkovbors-13/+177
Introduce NonterminalKind for more type-safe mbe parsing It encapsulate the (part of) the interface between the parser and macro by example (macro_rules) parser. The second bit is somewhat more general `parse_ast_fragment`, which is the reason why we keep some `parse_xxx` functions as public.
2020-08-02Formatting: don't mix mod and useAleksey Kladov-6/+5
Seems to be a fallout from rustfmt transition
2020-08-02Introduce NonterminalKindAleksey Kladov-8/+173
It encapsulate the (part of) the interface between the parser and macro by example (macro_rules) parser. The second bit is somewhat more general `parse_ast_fragment`, which is the reason why we keep some `parse_xxx` functions as public.
2020-07-31Reduce verbosity of some type ascription errorsEsteban Küber-0/+1
* Deduplicate type ascription LHS errors * Remove duplicated `:` -> `::` suggestion from parse error * Tweak wording to be more accurate * Modify `current_type_ascription` to reduce span wrangling * remove now unnecessary match arm * Add run-rustfix to appropriate tests
2020-07-23Account for trailing closing angle bracketsEsteban Küber-22/+35
2020-07-23Detect turbofish missing surrounding angle bracketsEsteban Küber-3/+44
2020-07-22Correctly parse `{} && false` in tail expressionEsteban Küber-2/+9
Fix #74233.
2020-07-15Rollup merge of #74337 - estebank:ty-parse-recovery, r=varkorManish Goregaokar-4/+10
Handle case of incomplete local ty more gracefully When encountering a local binding with a type that isn't completed, the parser will reach a `=` token. When this happen, consider the type "complete" as far as the parser is concerned to avoid further errors being emitted by parse recovery logic.
2020-07-14Handle case of incomplete local ty more gracefullyEsteban Küber-4/+10
When encountering a local binding with a type that isn't completed, the parser will reach a `=` token. When this happen, consider the type "complete" as far as the parser is concerned to avoid further errors being emitted by parse recovery logic.
2020-07-15Remove lots of `Symbol::as_str()` calls.Nicholas Nethercote-3/+3
In various ways, such as changing functions to take a `Symbol` instead of a `&str`.
2020-07-10Rollup merge of #74125 - ayazhafiz:i/74050, r=matthewjasperManish Goregaokar-1/+1
Correctly mark the ending span of a match arm Closes #74050 r? @matthewjasper
2020-07-10Rollup merge of #71322 - petrochenkov:tuple00, r=nikomatsakisManish Goregaokar-38/+81
Accept tuple.0.0 as tuple indexing (take 2) If we expect something identifier-like when parsing a field name after `.`, but encounter a float token, we break that float token into parts, similarly to how we break `&&` into `&` `&`, or `<<` into `<` `<`, etc. An alternative to https://github.com/rust-lang/rust/pull/70420.
2020-07-09Rollup merge of #74188 - estebank:tweak-ascription-typo-heuristic, ↵Manish Goregaokar-8/+13
r=petrochenkov Tweak `::` -> `:` typo heuristic and reduce verbosity Do not trigger on correct type ascription expressions with trailing operators and _do_ trigger on likely path typos where a turbofish is used. On likely path typos, remove note explaining type ascription. Clean up indentation. r? @petrochenkov
2020-07-09Tweak `::` -> `:` typo heuristic and reduce verbosityEsteban Küber-8/+13
Do not trigger on correct type ascription expressions with trailing operators and _do_ trigger on likely path typos where a turbofish is used. On likely path typos, remove note explaining type ascription.
2020-07-08Correctly mark the ending span of a match armAyaz Hafiz-1/+1
Closes #74050 r? @matthewjasper
2020-07-06Rollup merge of #73953 - JohnTitor:audit-hidden-sugg, r=estebankManish Goregaokar-3/+6
Audit hidden/short code suggestions Should fix #73641. Audit uses of `span_suggestion_short` and `tool_only_span_suggestion` (`span_suggestion_hidden` is already tested with `run-rustfix`). Leave some FIXMEs for futher improvements/fixes. r? @estebank
2020-07-02parser: Break float tokens into parts in tuple field positionsVadim Petrochenkov-38/+81
2020-07-02Audit uses of `span_suggestion_short`Yuki Okushi-3/+6
2020-07-01Rollup merge of #73803 - Aaron1011:feature/angle-field-recovery, r=matthewjasperManish Goregaokar-8/+44
Recover extra trailing angle brackets in struct definition This commit applies the existing 'extra angle bracket recovery' logic when parsing fields in struct definitions. This allows us to continue parsing the struct's fields, avoiding spurious 'missing field' errors in code that tries to use the struct.
2020-07-01Rollup merge of #73345 - petrochenkov:nointerp, r=Aaron1011Manish Goregaokar-8/+8
expand: Stop using nonterminals for passing tokens to attribute and derive macros Make one more step towards fully token-based expansion and fix issues described in https://github.com/rust-lang/rust/issues/72545#issuecomment-640276791. Now `struct S;` is passed to `foo!(struct S;)` and `#[foo] struct S;` in the same way - as a token stream `struct S ;`, rather than a single non-terminal token `NtItem` which is then broken into parts later. The cost is making pretty-printing of token streams less pretty. Some of the pretty-printing regressions will be recovered by keeping jointness with each token, which we will need to do anyway. Unfortunately, this is not exactly the same thing as https://github.com/rust-lang/rust/pull/73102. One more observable effect is how `$crate` is printed in the attribute input. Inside `NtItem` was printed as `crate` or `that_crate`, now as a part of a token stream it's printed as `$crate` (there are good reasons for these differences, see https://github.com/rust-lang/rust/pull/62393 and related PRs). This may break old proc macros (custom derives) written before the main portion of the proc macro API (macros 1.2) was stabilized, those macros did `input.to_string()` and reparsed the result, now that result can contain `$crate` which cannot be reparsed. So, I think we should do this regardless, but we need to run crater first. r? @Aaron1011
2020-07-01Remove `token::FlattenGroup`Vadim Petrochenkov-8/+8
2020-06-27Fix wording for anonymous parameter name helpJames Box-1/+1
2020-06-27Recover extra trailing angle brackets in struct definitionAaron Hill-8/+44
This commit applies the existing 'extra angle bracket recovery' logic when parsing fields in struct definitions. This allows us to continue parsing the struct's fields, avoiding spurious 'missing field' errors in code that tries to use the struct.
2020-06-26Rollup merge of #73597 - ayazhafiz:i/const-span, r=ecstatic-morseManish Goregaokar-3/+3
Record span of `const` kw in GenericParamKind Context: this is needed for a fix of https://github.com/rust-lang/rustfmt/issues/4263, which currently records the span of a const generic param incorrectly because the location of the `const` kw is not known. I am not sure how to add tests for this; any guidance in how to do so would be appreciated :slightly_smiling_face:
2020-06-26proc_macro: Stop flattening groups with dummy spansVadim Petrochenkov-8/+8
2020-06-24Auto merge of #73293 - Aaron1011:feature/macro-rules-arg-capture, r=petrochenkovbors-1/+1
Always capture tokens for `macro_rules!` arguments When we invoke a proc-macro, the `TokenStream` we pass to it may contain 'interpolated' AST fragments, represented by `rustc_ast::token::Nonterminal`. In order to correctly, pass a `Nonterminal` to a proc-macro, we need to have 'captured' its `TokenStream` at the time the AST was parsed. Currently, we perform this capturing when attributes are present on items and expressions, since we will end up using a `Nonterminal` to pass the item/expr to any proc-macro attributes it is annotated with. However, `Nonterminal`s are also introduced by the expansion of metavariables in `macro_rules!` macros. Since these metavariables may be passed to proc-macros, we need to have tokens available to avoid the need to pretty-print and reparse (see https://github.com/rust-lang/rust/issues/43081). This PR unconditionally performs token capturing for AST items and expressions that are passed to a `macro_rules!` invocation. We cannot know in advance if captured item/expr will be passed to proc-macro, so this is needed to ensure that tokens will always be available when they are needed. This ensures that proc-macros will receive tokens with proper `Spans` (both location and hygiene) in more cases. Like all work on https://github.com/rust-lang/rust/issues/43081, this will cause regressions in proc-macros that were relying on receiving tokens with dummy spans. In this case, Crater revealed only one regression: the [Pear](https://github.com/SergioBenitez/Pear) crate (a helper for [rocket](https://github.com/SergioBenitez/Rocket)), which was previously [fixed](https://github.com/SergioBenitez/Pear/pull/25) as part of https://github.com/rust-lang/rust/pull/73084. This regression manifests itself as the following error: ``` [INFO] [stdout] error: proc macro panicked [INFO] [stdout] --> /opt/rustwide/cargo-home/registry/src/github.com-1ecc6299db9ec823/rocket_http-0.4.5/src/parse/uri/parser.rs:119:34 [INFO] [stdout] | [INFO] [stdout] 119 | let path_and_query = pear_try!(path_and_query(is_pchar)); [INFO] [stdout] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: message: called `Option::unwrap()` on a `None` value [INFO] [stdout] = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) ``` It can be fixed by running `cargo update -p pear`, which updates your `Cargo.lock` to use the latest version of Pear (which includes a bugfix for the regression). Split out from https://github.com/rust-lang/rust/pull/73084/