about summary refs log tree commit diff
path: root/src/librustc_parse/parser/item.rs
AgeCommit message (Collapse)AuthorLines
2020-08-30mv compiler to compiler/mark-1843/+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-17rust_ast::ast => rustc_astUjjwal Sharma-7/+7
2020-08-15replaced log with tracingGurpreet Singh-1/+1
2020-08-13Recover gracefully from `struct ` parse errorsEsteban Küber-1/+1
2020-08-06rustc_ast: Stop using "string typing" for doc comment tokensVadim Petrochenkov-2/+2
Explicitly store their kind and style retrieved during lexing in the token
2020-07-01Rollup merge of #73803 - Aaron1011:feature/angle-field-recovery, r=matthewjasperManish Goregaokar-1/+28
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-01Remove `token::FlattenGroup`Vadim Petrochenkov-1/+1
2020-06-27Recover extra trailing angle brackets in struct definitionAaron Hill-1/+28
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-26proc_macro: Stop flattening groups with dummy spansVadim Petrochenkov-1/+1
2020-05-25Only capture tokens for items with outer attributesAaron Hill-5/+16
Suggested by @petrochenkov in https://github.com/rust-lang/rust/issues/43081#issuecomment-633389225
2020-05-08Remove ast::{Ident, Name} reexports.Camille GILLOT-4/+4
2020-05-05Detect errors caused by `async` block in 2015 editionEsteban Küber-1/+1
2020-04-22Rollup merge of #71256 - cuviper:must_use_replace, r=estebankDylan DPC-1/+1
Lint must_use on mem::replace This adds a hint on `mem::replace`, "if you don't need the old value, you can just assign the new value directly". This is in similar spirit to the `must_use` on `ManuallyDrop::take`.
2020-04-18remove build warningsTshepang Lekhonkhobe-2/+2
Code blocks that are not annotated are assumed to be Rust
2020-04-17Fix unused results from mem::replaceJosh Stone-1/+1
2020-04-02Rollup merge of #70421 - Centril:recover-const-async-fn-ptr, r=estebankMazdak Farrokhzad-2/+2
parse: recover on `const fn()` / `async fn()` Recover on `const fn()` and `async fn()` function pointers, suggesting to remove the qualifier. For example: ``` error: an `fn` pointer type cannot be `async` --> $DIR/recover-const-async-fn-ptr.rs:6:11 | LL | type T3 = async fn(); | -----^^^^^ | | | `async` because of this | help: remove the `async` qualifier ``` r? @estebank
2020-03-26error_bad_item_kind: add help textMazdak Farrokhzad-2/+4
2020-03-26parse: recover on `const fn()` / `async fn()`.Mazdak Farrokhzad-2/+2
2020-03-25Rename `def_span` to `guess_head_span`Esteban Küber-1/+1
2020-03-22Rollup merge of #70209 - Centril:recover-quant-closure, r=petrochenkovDylan DPC-1/+1
parser: recover on `for<'a> |...| body` closures When encountering `for` and `<` is 1 token ahead, interpret this as an explicitly quantified generic closure and recover, rather than attempting to parse a `for` loop. This provides both improved diagnostics as well as an insurance policy for the ability to use this as the syntax for generic closures in the future. As requested by r? @eddyb
2020-03-21recover on `for<'a> |...| body` closures.Mazdak Farrokhzad-1/+1
2020-03-21Rollup merge of #70187 - matthiaskrgr:cl2ppy, r=Mark-SimulacrumMazdak Farrokhzad-4/+4
more clippy fixes * remove redundant returns (clippy::needless_return) * remove redundant import (clippy::single_component_path_imports) * remove redundant format!() call (clippy::useless_format) * don't use ok() before calling expect() (clippy::ok_expect)
2020-03-20remove redundant returns (clippy::needless_return)Matthias Krüger-4/+4
2020-03-20can_begin_literal_maybe_minus: `true` on `"-"? lit` NTs.Mazdak Farrokhzad-1/+1
2020-03-18fix rebase falloutMazdak Farrokhzad-7/+4
2020-03-18tweak outline module parsing spansMazdak Farrokhzad-1/+1
2020-03-18parse: module parsing -> item.rsMazdak Farrokhzad-5/+64
2020-03-16Other `legacy` -> `macro_rules`Vadim Petrochenkov-1/+1
2020-03-16ast/hir: `MacroDef::legacy` -> `MacroDef::macro_rules`Vadim Petrochenkov-2/+2
2020-03-15Rollup merge of #69589 - petrochenkov:maccall, r=CentrilMazdak Farrokhzad-11/+7
ast: `Mac`/`Macro` -> `MacCall` It's now obvious that these refer to macro calls rather than to macro definitions. It's also a single name instead of two different names in different places. `rustc_expand` usually calls macro calls in a wide sense (including attributes and derives) "macro invocations", but structures and variants renamed in this PR are only relevant to fn-like macros, so it's simpler and clearer to just call them calls. cc https://github.com/rust-lang/rust/pull/63586#discussion_r314232513 r? @eddyb
2020-03-12ast: `Mac`/`Macro` -> `MacCall`Vadim Petrochenkov-11/+7
2020-03-12Rollup merge of #69722 - estebank:negative-impl-span-ast, r=CentrilMazdak Farrokhzad-7/+11
Tweak output for invalid negative impl AST errors Use more accurate spans for negative `impl` errors. r? @Centril
2020-03-11Rollup merge of #69760 - Centril:parse-expr-improve, r=estebankMazdak Farrokhzad-20/+24
Improve expression & attribute parsing This PR includes misc improvements to expression and attribute parsing. 1. Some code simplifications 2. Better recovery for various block forms, e.g. `loop statements }` (missing `{` after `loop`). (See e.g., `block-no-opening-brace.rs` among others for examples.) 3. Added recovery for e.g., `unsafe $b` where `$b` refers to a `block` macro fragment. (See `bad-interpolated-block.rs` for examples.) 4. ^--- These are done so that code sharing in block parsing is increased. 5. Added recovery for e.g., `'label: loop { ... }` (See `labeled-no-colon-expr.rs`.) 6. Added recovery for e.g., `&'lifetime expr` (See `regions-out-of-scope-slice.rs`.) 7. Added recovery for e.g., `fn foo() = expr;` (See `fn-body-eq-expr-semi.rs`.) 8. Simplified attribute parsing code & slightly improved diagnostics. 9. Added recovery for e.g., `Box<('a) + Trait>`. 10. Added recovery for e.g, `if true #[attr] {} else #[attr] {} else #[attr] if true {}`. r? @estebank
2020-03-10parse: Tweak the function parameter edition checkVadim Petrochenkov-3/+1
Move anon-params tests to ui/anon-params.
2020-03-10parse_if_expr: recover on attributesMazdak Farrokhzad-2/+1
2020-03-10use check_path moreMazdak Farrokhzad-1/+1
2020-03-10parse: recover on `fn foo() = expr;`Mazdak Farrokhzad-1/+16
2020-03-10parse: simplify parse_fn_bodyMazdak Farrokhzad-17/+7
2020-03-09Address review commentsVadim Petrochenkov-1/+1
2020-03-09Use `Token::uninterpolate` in couple more places matching on `(Nt)Ident`Vadim Petrochenkov-0/+2
2020-03-09rustc_ast: Introduce `Token::uninterpolate`Vadim Petrochenkov-2/+2
2020-03-09rustc_ast: Introduce `Token::uninterpolated_span`Vadim Petrochenkov-1/+1
2020-03-09rustc_parse: Use `Token::ident` where possibleVadim Petrochenkov-11/+8
2020-03-06Auto merge of #69586 - petrochenkov:unmerge, r=Centrilbors-20/+20
ast: Unmerge structures for associated items and foreign items Follow-up to https://github.com/rust-lang/rust/pull/69194. r? @Centril
2020-03-05review commentsEsteban Küber-7/+11
2020-03-04Tweak output for invalid negative impl AST errorsEsteban Küber-1/+1
2020-03-01ast: Implement `TryFrom<ItemKind>` for associated and foreign itemsVadim Petrochenkov-20/+20
2020-03-01Rollup merge of #69579 - petrochenkov:noprevspan, r=CentrilYuki Okushi-29/+32
parser: Remove `Parser::prev_span` Follow-up to https://github.com/rust-lang/rust/pull/69384. r? @Centril
2020-03-01Auto merge of #69592 - petrochenkov:nosyntax, r=Centrilbors-9/+13
Rename `libsyntax` to `librustc_ast` This was the last rustc crate that wasn't following the `rustc_*` naming convention. Follow-up to https://github.com/rust-lang/rust/pull/67763.