summary refs log tree commit diff
path: root/compiler/rustc_ast_lowering/src/lib.rs
AgeCommit message (Collapse)AuthorLines
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-06forbid `impl Trait` in generic param defaultsSNCPlay42-7/+1
2021-03-30Remove hir::CrateItem.Camille GILLOT-1/+1
2021-03-26Use iter::zip in compiler/Josh Stone-0/+1
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-3/+3
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-16ast/hir: Rename field-related structuresVadim Petrochenkov-3/+3
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-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-13Auto merge of #82891 - cjgillot:monoparent, r=petrochenkovbors-21/+28
Make def_key and HIR parenting consistent. r? `@petrochenkov`
2021-03-12Make def_key and HIR parenting consistent.Camille GILLOT-21/+28
2021-03-10Simplify lower ast blockCameron Steffen-20/+6
2021-03-09Use BTreeMap to store attributes.Camille GILLOT-13/+33
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-2/+2
2021-03-09Remove hir::Item::attrs.Camille GILLOT-1/+0
2021-03-09Remove hir::Crate::attrs.Camille GILLOT-2/+2
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-3/+11
2021-03-09Collect attributes during HIR lowering.Camille GILLOT-8/+23
2021-03-06Edit ructc_ast_lowering docspierwill-7/+9
Fixes some punctuation and formatting; also makes some small wording changes.
2021-02-25Add a cache for rustc_legacy_const_genericsAmanieu d'Antras-1/+1
2021-02-25Address review commentsAmanieu d'Antras-11/+1
2021-02-24TODO -> FIXMEAmanieu d'Antras-1/+1
2021-02-23Add #[rustc_legacy_const_generics]Amanieu d'Antras-0/+12
2021-02-18ast: Stop using `Mod` in `Crate`Vadim Petrochenkov-2/+2
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-15Trait impls are Items, therefore HIR owners.Camille GILLOT-1/+1
2021-02-15Index Modules using their LocalDefId.Camille GILLOT-5/+5
2021-02-15Only store a LocalDefId in hir::Item.Camille GILLOT-18/+15
Items are guaranteed to be HIR owner.
2021-02-15Use ItemId as a strongly typed index.Camille GILLOT-2/+4
2021-02-04lowering of generic args in AssocTyConstraintb-naber-7/+32
2021-02-02Auto merge of #81405 - bugadani:ast, r=cjgillotbors-2/+3
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-02Bump rustfmt versionMark Rousskov-1/+3
Also switches on formatting of the mir build module
2021-02-01Box the biggest ast::ItemKind variantsDániel Buga-2/+3
2021-01-31Rollup merge of #80470 - SimonSapin:array-intoiter-type, r=m-ou-seJonas Schievink-1/+0
Stabilize by-value `[T; N]` iterator `core::array::IntoIter` Tracking issue: https://github.com/rust-lang/rust/issues/65798 This is unblocked now that `min_const_generics` has been stabilized in https://github.com/rust-lang/rust/pull/79135. This PR does *not* include the corresponding `IntoIterator` impl, which is https://github.com/rust-lang/rust/pull/65819. Instead, an iterator can be constructed through the `new` method. `new` would become unnecessary when `IntoIterator` is implemented and might be deprecated then, although it will stay stable.
2021-01-13Lint on extern in item declaration positionMark Rousskov-1/+2
2021-01-13Introduce missing ABI lint on extern blocksMark Rousskov-1/+23
2021-01-09ast: Remove some indirection layers from values in key-value attributesVadim Petrochenkov-4/+30
2021-01-07rustc_parse: Better spans for synthesized token streamsVadim Petrochenkov-8/+2
2021-01-03Make `ExpnData` fields `krate` and `orig_id` privateAaron Hill-5/+2
These fields are only used by hygiene serialized, and should not be accessed by anything outside of `rustc_span`.
2021-01-01first pass at default values for const genericsJulian Knodt-2/+3
- Adds optional default values to const generic parameters in the AST and HIR - Parses these optional default values - Adds a `const_generics_defaults` feature gate
2020-12-30Rollup merge of #80495 - jyn514:rename-empty, r=petrochenkovMara Bos-1/+1
Rename kw::Invalid -> kw::Empty See https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F/near/220054471 for context. r? `@petrochenkov`