about summary refs log tree commit diff
path: root/compiler/rustc_ast_lowering/src
AgeCommit message (Collapse)AuthorLines
2021-04-13Lower async fn in traits.Camille GILLOT-3/+11
An error is already created by AST validation.
2021-04-11Implement token-based handling of attributes during expansionAaron Hill-45/+7
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-08Rollup merge of #83980 - pierwill:fix-compiler-librustc-names, r=davidtwcoDylan DPC-1/+1
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-08Fix outdated crate names in compiler docspierwill-1/+1
Changes `librustc_X` to `rustc_X`, only in documentation comments. Plain code comments are left unchanged. Also fix incorrect file paths.
2021-04-07Rollup merge of #83935 - SNCPlay42:param-default-impl-trait, r=varkorDylan DPC-7/+1
forbid `impl Trait` in generic param defaults Fixes #83929 Forbid using `impl Trait` in the default types of generic parameters, e.g. `struct Foo<T = impl Trait>`. I assume this was never supposed to be allowed - it seems no UI test used it. Note that using `impl Trait` in this position did not hit a feature gate error; however, this *shouldn't* be a breaking change as any attempt to use it should have hit the ICE in #83929 and/or failed to provide a defining use of the `impl Trait`.
2021-04-07Rollup merge of #83916 - Amanieu:asm_anonconst, r=petrochenkovDylan DPC-3/+3
Use AnonConst for asm! constants This replaces the old system which used explicit promotion. See #83169 for more background. The syntax for `const` operands is still the same as before: `const <expr>`. Fixes #83169 Because the implementation is heavily based on inline consts, we suffer from the same issues: - We lose the ability to use expressions derived from generics. See the deleted tests in `src/test/ui/asm/const.rs`. - We are hitting the same ICEs as inline consts, for example #78174. It is unlikely that we will be able to stabilize this before inline consts are stabilized.
2021-04-06forbid `impl Trait` in generic param defaultsSNCPlay42-7/+1
2021-04-06Use AnonConst for asm! constantsAmanieu d'Antras-3/+3
2021-04-04Allow clobbering unsupported registers in asm!Amanieu d'Antras-32/+50
Previously registers could only be marked as clobbered if the target feature for that register was enabled. This restriction is now removed.
2021-03-30Remove hir::CrateItem.Camille GILLOT-1/+1
2021-03-26Use iter::zip in compiler/Josh Stone-2/+4
2021-03-25Auto merge of #83424 - cjgillot:noparam, r=lcnrbors-12/+4
GenericParam does not need to be a HIR owner. The special case is not required. Universal impl traits design to regular generic parameters, and their content is owned by the enclosing item. Existential (and opaque) impl traits generate their own enclosing item, and are collected through it.
2021-03-23GenericParam does not need to be a HIR owner.Camille GILLOT-12/+4
2021-03-23Add has_default to GenericParamDefKind::Constkadmin-1/+0
This currently creates a field which is always false on GenericParamDefKind for future use when consts are permitted to have defaults Update const_generics:default locations Previously just ignored them, now actually do something about them. Fix using type check instead of value Add parsing This adds all the necessary changes to lower const-generics defaults from parsing. Change P<Expr> to AnonConst This matches the arguments passed to instantiations of const generics, and makes it specific to just anonymous constants. Attempt to fix lowering bugs
2021-03-19stabilize or_patternsmark-1/+1
2021-03-18hir: Preserve used syntax in `TyKind::TraitObject`Vadim Petrochenkov-1/+2
2021-03-17Auto merge of #83188 - petrochenkov:field, r=lcnrbors-22/+28
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-17Rollup merge of #83124 - cjgillot:iiib, r=petrochenkovYuki Okushi-63/+15
Do not insert impl_trait_in_bindings opaque definitions twice. The reference to the item already appears inside the `OpaqueDef`. It does not need to be repeated as a statement.
2021-03-17Rollup merge of #83092 - petrochenkov:qspan, r=estebankYuki Okushi-5/+8
More precise spans for HIR paths `Ty::assoc_item` is lowered to `<Ty>::assoc_item` in HIR, but `Ty` got span from the whole path. This PR fixes that, and adjusts some diagnostic code that relied on `Ty` having the whole path span. This is a pre-requisite for https://github.com/rust-lang/rust/pull/82868 (we cannot report suggestions like `Tr::assoc` -> `<dyn Tr>::assoc` with the current imprecise spans). r? ````@estebank````
2021-03-16Auto merge of #82838 - Amanieu:rustdoc_asm, r=nagisabors-45/+44
Allow rustdoc to handle asm! of foreign architectures This allows rustdoc to process code containing `asm!` for architectures other than the current one. Since this never reaches codegen, we just replace target-specific registers and register classes with a dummy one. Fixes #82869
2021-03-16ast: Reduce size of `ExprKind` by boxing fields of `ExprKind::Struct`Vadim Petrochenkov-8/+9
2021-03-16ast/hir: Rename field-related structuresVadim Petrochenkov-15/+20
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-15More precise spans for HIR pathsVadim Petrochenkov-5/+8
2021-03-15Special case type aliases from impl trait in const/static typesOli Scherer-2/+2
2021-03-14Remove dead code.Camille GILLOT-25/+0
2021-03-14Do not insert impl_trait_in_bindings opaque definitions twice.Camille GILLOT-38/+15
2021-03-13Always lower asm! to valid HIRAmanieu d'Antras-45/+44
2021-03-13Auto merge of #82891 - cjgillot:monoparent, r=petrochenkovbors-21/+28
Make def_key and HIR parenting consistent. r? `@petrochenkov`
2021-03-13Rollup merge of #82984 - camsteffen:lower-block, r=cjgillotYuki Okushi-20/+6
Simplify ast block lowering
2021-03-12Make def_key and HIR parenting consistent.Camille GILLOT-21/+28
2021-03-10Simplify lower ast blockCameron Steffen-20/+6
2021-03-10Auto merge of #76570 - cratelyn:implement-rfc-2945-c-unwind-abi, r=Amanieubors-4/+4
Implement RFC 2945: "C-unwind" ABI ## Implement RFC 2945: "C-unwind" ABI This branch implements [RFC 2945]. The tracking issue for this RFC is #74990. The feature gate for the issue is `#![feature(c_unwind)]`. This RFC was created as part of the ffi-unwind project group tracked at rust-lang/lang-team#19. ### Changes Further details will be provided in commit messages, but a high-level overview of the changes follows: * A boolean `unwind` payload is added to the `C`, `System`, `Stdcall`, and `Thiscall` variants, marking whether unwinding across FFI boundaries is acceptable. The cases where each of these variants' `unwind` member is true correspond with the `C-unwind`, `system-unwind`, `stdcall-unwind`, and `thiscall-unwind` ABI strings introduced in RFC 2945 [3]. * This commit adds a `c_unwind` feature gate for the new ABI strings. Tests for this feature gate are included in `src/test/ui/c-unwind/`, which ensure that this feature gate works correctly for each of the new ABIs. A new language features entry in the unstable book is added as well. * We adjust the `rustc_middle::ty::layout::fn_can_unwind` function, used to compute whether or not a `FnAbi` object represents a function that should be able to unwind when `panic=unwind` is in use. * Changes are also made to `rustc_mir_build::build::should_abort_on_panic` so that the function ABI is used to determind whether it should abort, assuming that the `panic=unwind` strategy is being used, and no explicit unwind attribute was provided. [RFC 2945]: https://github.com/rust-lang/rfcs/blob/master/text/2945-c-unwind-abi.md
2021-03-09rustc_target: add "unwind" payloads to `Abi`katelyn a. martin-4/+4
### Overview This commit begins the implementation work for RFC 2945. For more information, see the rendered RFC [1] and tracking issue [2]. A boolean `unwind` payload is added to the `C`, `System`, `Stdcall`, and `Thiscall` variants, marking whether unwinding across FFI boundaries is acceptable. The cases where each of these variants' `unwind` member is true correspond with the `C-unwind`, `system-unwind`, `stdcall-unwind`, and `thiscall-unwind` ABI strings introduced in RFC 2945 [3]. ### Feature Gate and Unstable Book This commit adds a `c_unwind` feature gate for the new ABI strings. Tests for this feature gate are included in `src/test/ui/c-unwind/`, which ensure that this feature gate works correctly for each of the new ABIs. A new language features entry in the unstable book is added as well. ### Further Work To Be Done This commit does not proceed to implement the new unwinding ABIs, and is intentionally scoped specifically to *defining* the ABIs and their feature flag. ### One Note on Test Churn This will lead to some test churn, in re-blessing hash tests, as the deleted comment in `src/librustc_target/spec/abi.rs` mentioned, because we can no longer guarantee the ordering of the `Abi` variants. While this is a downside, this decision was made bearing in mind that RFC 2945 states the following, in the "Other `unwind` Strings" section [3]: > More unwind variants of existing ABI strings may be introduced, > with the same semantics, without an additional RFC. Adding a new variant for each of these cases, rather than specifying a payload for a given ABI, would quickly become untenable, and make working with the `Abi` enum prone to mistakes. This approach encodes the unwinding information *into* a given ABI, to account for the future possibility of other `-unwind` ABI strings. ### Ignore Directives `ignore-*` directives are used in two of our `*-unwind` ABI test cases. Specifically, the `stdcall-unwind` and `thiscall-unwind` test cases ignore architectures that do not support `stdcall` and `thiscall`, respectively. These directives are cribbed from `src/test/ui/c-variadic/variadic-ffi-1.rs` for `stdcall`, and `src/test/ui/extern/extern-thiscall.rs` for `thiscall`. This would otherwise fail on some targets, see: https://github.com/rust-lang-ci/rust/commit/fcf697f90206e9c87b39d494f94ab35d976bfc60 ### Footnotes [1]: https://github.com/rust-lang/rfcs/blob/master/text/2945-c-unwind-abi.md [2]: https://github.com/rust-lang/rust/issues/74990 [3]: https://github.com/rust-lang/rfcs/blob/master/text/2945-c-unwind-abi.md#other-unwind-abi-strings
2021-03-09Use BTreeMap to store attributes.Camille GILLOT-30/+60
2021-03-09Alias attributes of hir::Stmt.Camille GILLOT-5/+17
The attributes for statements and those of the statements' content.
2021-03-09Remove hir::Expr::attrs.Camille GILLOT-24/+16
2021-03-09Remove hir::Item::attrs.Camille GILLOT-4/+1
2021-03-09Remove hir::ImplItem::attrs.Camille GILLOT-1/+1
2021-03-09Remove hir::TraitItem::attrs.Camille GILLOT-8/+2
2021-03-09Remove hir::ForeignItem::attrs.Camille GILLOT-1/+1
2021-03-09Remove hir::StructField::attrs.Camille GILLOT-1/+1
2021-03-09Remove hir::Variant::attrs.Camille GILLOT-1/+1
2021-03-09Remove hir::Param::attrs.Camille GILLOT-3/+2
2021-03-09Remove hir::Arm::attrs.Camille GILLOT-16/+3
2021-03-09Remove hir::Crate::attrs.Camille GILLOT-2/+2
2021-03-09Remove hir::MacroDef::attrs.Camille GILLOT-2/+1
2021-03-09Remove hir::GenericParam::attrs.Camille GILLOT-4/+1
2021-03-09Remove hir::Local::attrs.Camille GILLOT-12/+2
2021-03-09Take a slice in stmt_let_pat.Camille GILLOT-9/+16
2021-03-09Collect attributes during HIR lowering.Camille GILLOT-53/+89