summary refs log tree commit diff
path: root/compiler/rustc_expand/src
AgeCommit message (Collapse)AuthorLines
2022-01-05ast: Always keep a `NodeId` in `ast::Crate`Vadim Petrochenkov-5/+8
This makes it more uniform with other expanded nodes
2021-12-30Rollup merge of #91519 - petrochenkov:cratexp2, r=Aaron1011Matthias Krüger-9/+11
ast: Avoid aborts on fatal errors thrown from mutable AST visitor Set the node to some dummy value and rethrow the error instead. When using the old aborting `visit_clobber` in `InvocationCollector::visit_crate` the next tests abort due to fatal errors: ``` ui\modules\path-invalid-form.rs ui\modules\path-macro.rs ui\modules\path-no-file-name.rs ui\parser\issues\issue-5806.rs ui\parser\mod_file_with_path_attr.rs ``` Follow up to https://github.com/rust-lang/rust/pull/91313.
2021-12-19Auto merge of #91957 - nnethercote:rm-SymbolStr, r=oli-obkbors-9/+11
Remove `SymbolStr` This was originally proposed in https://github.com/rust-lang/rust/pull/74554#discussion_r466203544. As well as removing the icky `SymbolStr` type, it allows the removal of a lot of `&` and `*` occurrences. Best reviewed one commit at a time. r? `@oli-obk`
2021-12-15Rollup merge of #90521 - jhpratt:stabilize-destructuring_assignment, ↵Matthias Krüger-1/+1
r=jackh726,pnkfelix Stabilize `destructuring_assignment` Closes #71126 - [Stabilization report](https://github.com/rust-lang/rust/issues/71126#issuecomment-941148058) - [Completed FCP](https://github.com/rust-lang/rust/issues/71126#issuecomment-954914819) `@rustbot` label +F-destructuring-assignment +T-lang Also needs +relnotes but I don't have permission to add that tag.
2021-12-15Remove unnecessary sigils around `Ident::as_str()` calls.Nicholas Nethercote-2/+2
2021-12-15Remove unnecessary sigils around `Symbol::as_str()` calls.Nicholas Nethercote-3/+3
2021-12-14Stabilize `destructuring_assignment`Jacob Pratt-1/+1
2021-12-15Remove `SymbolStr`.Nicholas Nethercote-4/+6
By changing `as_str()` to take `&self` instead of `self`, we can just return `&str`. We're still lying about lifetimes, but it's a smaller lie than before, where `SymbolStr` contained a (fake) `&'static str`!
2021-12-14Stabilize iter::zip.PFPoitras-1/+0
2021-12-09Remove redundant [..]sest31-7/+7
2021-12-07Future compatibility warning on cfg_attr on crate_type and crate_namebjorn3-1/+18
2021-12-04Use IntoIterator for array impl everywhere.Mara Bos-3/+2
2021-12-04ast: Avoid aborts on fatal errors thrown from mutable AST visitorVadim Petrochenkov-9/+11
Set the node to some dummy value and rethwor the error instead.
2021-12-04Rollup merge of #91385 - ecstatic-morse:pat-param-spec-suggest, r=estebankMatthias Krüger-0/+18
Suggest the `pat_param` specifier before `|` on 2021 edition Ran into this today after writing some Rust for the first time in a while. r? `@estebank`
2021-12-02Rollup merge of #91394 - Mark-Simulacrum:bump-stage0, r=pietroalbiniMatthias Krüger-14/+20
Bump stage0 compiler r? `@pietroalbini` (or anyone else)
2021-11-30re-format with new rustfmtMark Rousskov-13/+20
2021-11-30Apply cfg-bootstrap switchMark Rousskov-1/+0
2021-11-29Suggest the `pat_param` specifier before `|` on 2021 editionDylan MacKenzie-0/+18
We have a migration warning but no lint for users who have enabled the new edition.
2021-11-28expand: Turn `ast::Crate` into a first class expansion targetVadim Petrochenkov-76/+95
And stop creating a fake `mod` item for the crate root when expanding a crate.
2021-11-15Stabilize format_args_captureJosh Triplett-1/+1
Works as expected, and there are widespread reports of success with it, as well as interest in it.
2021-11-12proc_macro: Add an expand_expr method to TokenStreamNika Layzell-68/+122
This feature is aimed at giving proc macros access to powers similar to those used by builtin macros such as `format_args!` or `concat!`. These macros are able to accept macros in place of string literal parameters, such as the format string, as they perform recursive macro expansion while being expanded. This can be especially useful in many cases thanks to helper macros like `concat!`, `stringify!` and `include_str!` which are often used to construct string literals at compile-time in user code. For now, this method only allows expanding macros which produce literals, although more expresisons will be supported before the method is stabilized.
2021-11-08Don't abort compilation after giving a lint errorJoshua Nelson-1/+1
The only reason to use `abort_if_errors` is when the program is so broken that either: 1. later passes get confused and ICE 2. any diagnostics from later passes would be noise This is never the case for lints, because the compiler has to be able to deal with `allow`-ed lints. So it can continue to lint and compile even if there are lint errors.
2021-10-28Revert "Add rustc lint, warning when iterating over hashmaps"Mark Rousskov-1/+0
2021-10-24Rollup merge of #89558 - lcnr:query-stable-lint, r=estebankMatthias Krüger-0/+1
Add rustc lint, warning when iterating over hashmaps r? rust-lang/wg-incr-comp
2021-10-22Rollup merge of #89991 - petrochenkov:visitok2, r=jackh726Yuki Okushi-6/+3
rustc_ast: Turn `MutVisitor::token_visiting_enabled` into a constant It's a visitor property rather than something that needs to be determined at runtime
2021-10-19Auto merge of #89933 - est31:let_else, r=michaelwoeristerbors-10/+5
Adopt let_else across the compiler This performs a substitution of code following the pattern: ``` let <id> = if let <pat> = ... { identity } else { ... : ! }; ``` To simplify it to: ``` let <pat> = ... { identity } else { ... : ! }; ``` By adopting the `let_else` feature (cc #87335). The PR also updates the syn crate because the currently used version of the crate doesn't support `let_else` syntax yet. Note: Generally I'm the person who *removes* usages of unstable features from the compiler, not adds more usages of them, but in this instance I think it hopefully helps the feature get stabilized sooner and in a better state. I have written a [comment](https://github.com/rust-lang/rust/issues/87335#issuecomment-944846205) on the tracking issue about my experience and what I feel could be improved before stabilization of `let_else`.
2021-10-18rustc_ast: Turn `MutVisitor::token_visiting_enabled` into a constantVadim Petrochenkov-6/+3
It's a visitor property rather than something that needs to be determined at runtime
2021-10-17rustc_span: `Ident::invalid` -> `Ident::empty`Vadim Petrochenkov-5/+5
The equivalent for `Symbol`s was renamed some time ago (`kw::Invalid` -> `kw::Empty`), and it makes sense to do the same thing for `Ident`s.
2021-10-17Rollup merge of #89943 - matthiaskrgr:clpcompl, r=oli-obkYuki Okushi-1/+1
clippy::complexity fixes
2021-10-16clippy::complexity changesMatthias Krüger-1/+1
2021-10-16Adopt let_else across the compilerest31-10/+5
This performs a substitution of code following the pattern: let <id> = if let <pat> = ... { identity } else { ... : ! }; To simplify it to: let <pat> = ... { identity } else { ... : ! }; By adopting the let_else feature.
2021-10-15allow `potential_query_instability` everywherelcnr-0/+1
2021-10-15Remove trailing semicolon from macro call spanCameron Steffen-27/+19
2021-10-15Remove redundant matchingCameron Steffen-16/+10
2021-09-28Improve help for recursion limit errorsRoss MacArthur-2/+6
2021-09-25Check for macros in built-in attributes that don't support them.Eric Huss-1/+20
2021-09-22Remove Symbol::lenbjorn3-1/+1
It is used exactly once and can be replaced with the equally fast .as_str().len()
2021-09-19Rollup merge of #88996 - Aaron1011:trailing-macro-semi, r=petrochenkovYuki Okushi-6/+9
Fix linting when trailing macro expands to a trailing semi When a macro is used in the trailing expression position of a block (e.g. `fn foo() { my_macro!() }`), we currently parse it as an expression, rather than a statement. As a result, we ended up using the `NodeId` of the containing statement as our `lint_node_id`, even though we don't normally do this for macro calls. If such a macro expands to an expression with a `#[cfg]` attribute, then the trailing statement can get removed entirely. This lead to an ICE, since we were usng the `NodeId` of the expression to emit a lint. Ths commit makes us skip updating `lint_node_id` when handling a macro in trailing expression position. This will cause us to lint at the closest parent of the macro call.
2021-09-15Fix linting when trailing macro expands to a trailing semiAaron Hill-6/+9
When a macro is used in the trailing expression position of a block (e.g. `fn foo() { my_macro!() }`), we currently parse it as an expression, rather than a statement. As a result, we ended up using the `NodeId` of the containing statement as our `lint_node_id`, even though we don't normally do this for macro calls. If such a macro expands to an expression with a `#[cfg]` attribute, then the trailing statement can get removed entirely. This lead to an ICE, since we were usng the `NodeId` of the expression to emit a lint. Ths commit makes us skip updating `lint_node_id` when handling a macro in trailing expression position. This will cause us to lint at the closest parent of the macro call.
2021-09-15chore(rustc_expand): fix typo in commentMichael Howell-1/+1
2021-09-11Auto merge of #84373 - cjgillot:resolve-span, r=michaelwoerister,petrochenkovbors-3/+17
Encode spans relative to the enclosing item The aim of this PR is to avoid recomputing queries when code is moved without modification. MCP at https://github.com/rust-lang/compiler-team/issues/443 This is achieved by : 1. storing the HIR owner LocalDefId information inside the span; 2. encoding and decoding spans relative to the enclosing item in the incremental on-disk cache; 3. marking a dependency to the `source_span(LocalDefId)` query when we translate a span from the short (`Span`) representation to its explicit (`SpanData`) representation. Since all client code uses `Span`, step 3 ensures that all manipulations of span byte positions actually create the dependency edge between the caller and the `source_span(LocalDefId)`. This query return the actual absolute span of the parent item. As a consequence, any source code motion that changes the absolute byte position of a node will either: - modify the distance to the parent's beginning, so change the relative span's hash; - dirty `source_span`, and trigger the incremental recomputation of all code that depends on the span's absolute byte position. With this scheme, I believe the dependency tracking to be accurate. For the moment, the spans are marked during lowering. I'd rather do this during def-collection, but the AST MutVisitor is not practical enough just yet. The only difference is that we attach macro-expanded spans to their expansion point instead of the macro itself.
2021-09-10Record call_site parent for macros.Camille GILLOT-2/+16
2021-09-10Keep a parent LocalDefId in SpanData.Camille GILLOT-1/+1
2021-09-10Rollup merge of #87441 - ibraheemdev:i-86865, r=cjgillotManish Goregaokar-7/+22
Emit suggestion when passing byte literal to format macro Closes #86865
2021-09-10Rollup merge of #86165 - m-ou-se:proc-macro-span-shrink, r=dtolnayManish Goregaokar-0/+6
Add proc_macro::Span::{before, after}. This adds `proc_macro::Span::before()` and `proc_macro::Span::after()` to get a zero width span at the start or end of the span. These are equivalent to rustc's `Span::shrink_to_lo()` and `Span::shrink_to_hi()` but with a less cryptic name. They are useful when generating diagnostlics like "missing \<thing\> after \<thing\>". E.g. ```rust syn::Error::new(ident.span().after(), "missing `:` after field name").into_compile_error() ```
2021-09-08Bump stage0 compiler to 1.56Mark Rousskov-2/+0
2021-09-04Auto merge of #88598 - estebank:type-ascription-can-die-in-a-fire, r=wesleywiserbors-0/+1
Detect bare blocks with type ascription that were meant to be a `struct` literal Address part of #34255. Potential improvement: silence the other knock down errors in `issue-34255-1.rs`.
2021-09-03Auto merge of #88597 - cjgillot:lower-global, r=petrochenkovbors-0/+8
Move global analyses from lowering to resolution Split off https://github.com/rust-lang/rust/pull/87234 r? `@petrochenkov`
2021-09-03Detect bare blocks with type ascription that were meant to be a `struct` literalEsteban Kuber-0/+1
Address part of #34255. Potential improvement: silence the other knock down errors in `issue-34255-1.rs`.
2021-09-03Auto merge of #88428 - petrochenkov:stmtid, r=Aaron1011bors-54/+72
expand: Treat more macro calls as statement macro calls This PR implements the suggestion from https://github.com/rust-lang/rust/pull/87981#issuecomment-906641052 and treats fn-like macro calls inside `StmtKind::Item` and `StmtKind::Semi` as statement macro calls, which is consistent with treatment of attribute invocations in the same positions and with token-based macro expansion model in general. This also allows to remove a special case in `NodeId` assignment (previously tried in #87779), and to use statement `NodeId`s for linting (`assign_id!`). r? `@Aaron1011`