about summary refs log tree commit diff
path: root/compiler/rustc_ast_lowering/src/lib.rs
AgeCommit message (Collapse)AuthorLines
2025-02-09compiler: start using rustc_ast_lowering in rustc_passesJubilee Young-1/+1
2025-02-09compiler: gate `extern "{abi}"` in ast_loweringJubilee Young-0/+1
By moving this stability check into AST lowering, we effectively make it impossible to accidentally miss, as it must happen to generate HIR. Also, we put the ABI-stability code next to code that actually uses it! This allows code that wants to reason about backend ABI implementations to stop worrying about high-level concerns like syntax stability, while still leaving it as the authority on what ABIs actually exist. It also makes it easy to refactor things to have more consistent errors. For now, we only apply this to generalize the existing messages a bit.
2025-02-06Auto merge of #136471 - safinaskar:parallel, r=SparrowLiibors-8/+9
tree-wide: parallel: Fully removed all `Lrc`, replaced with `Arc` tree-wide: parallel: Fully removed all `Lrc`, replaced with `Arc` This is continuation of https://github.com/rust-lang/rust/pull/132282 . I'm pretty sure I did everything right. In particular, I searched all occurrences of `Lrc` in submodules and made sure that they don't need replacement. There are other possibilities, through. We can define `enum Lrc<T> { Rc(Rc<T>), Arc(Arc<T>) }`. Or we can make `Lrc` a union and on every clone we can read from special thread-local variable. Or we can add a generic parameter to `Lrc` and, yes, this parameter will be everywhere across all codebase. So, if you think we should take some alternative approach, then don't merge this PR. But if it is decided to stick with `Arc`, then, please, merge. cc "Parallel Rustc Front-end" ( https://github.com/rust-lang/rust/issues/113349 ) r? SparrowLii `@rustbot` label WG-compiler-parallel
2025-02-05Rollup merge of #128045 - pnkfelix:rustc-contracts, r=oli-obkLeón Orell Valerian Liehr-0/+20
#[contracts::requires(...)] + #[contracts::ensures(...)] cc https://github.com/rust-lang/rust/issues/128044 Updated contract support: attribute syntax for preconditions and postconditions, implemented via a series of desugarings that culminates in: 1. a compile-time flag (`-Z contract-checks`) that, similar to `-Z ub-checks`, attempts to ensure that the decision of enabling/disabling contract checks is delayed until the end user program is compiled, 2. invocations of lang-items that handle invoking the precondition, building a checker for the post-condition, and invoking that post-condition checker at the return sites for the function, and 3. intrinsics for the actual evaluation of pre- and post-condition predicates that third-party verification tools can intercept and reinterpret for their own purposes (e.g. creating shims of behavior that abstract away the function body and replace it solely with the pre- and post-conditions). Known issues: * My original intent, as described in the MCP (https://github.com/rust-lang/compiler-team/issues/759) was to have a rustc-prefixed attribute namespace (like rustc_contracts::requires). But I could not get things working when I tried to do rewriting via a rustc-prefixed builtin attribute-macro. So for now it is called `contracts::requires`. * Our attribute macro machinery does not provide direct support for attribute arguments that are parsed like rust expressions. I spent some time trying to add that (e.g. something that would parse the attribute arguments as an AST while treating the remainder of the items as a token-tree), but its too big a lift for me to undertake. So instead I hacked in something approximating that goal, by semi-trivially desugaring the token-tree attribute contents into internal AST constucts. This may be too fragile for the long-term. * (In particular, it *definitely* breaks when you try to add a contract to a function like this: `fn foo1(x: i32) -> S<{ 23 }> { ... }`, because its token-tree based search for where to inject the internal AST constructs cannot immediately see that the `{ 23 }` is within a generics list. I think we can live for this for the short-term, i.e. land the work, and continue working on it while in parallel adding a new attribute variant that takes a token-tree attribute alongside an AST annotation, which would completely resolve the issue here.) * the *intent* of `-Z contract-checks` is that it behaves like `-Z ub-checks`, in that we do not prematurely commit to including or excluding the contract evaluation in upstream crates (most notably, `core` and `std`). But the current test suite does not actually *check* that this is the case. Ideally the test suite would be extended with a multi-crate test that explores the matrix of enabling/disabling contracts on both the upstream lib and final ("leaf") bin crates.
2025-02-03Express contracts as part of function header and lower it to the contract ↵Celina G. Val-0/+20
lang items includes post-developed commit: do not suggest internal-only keywords as corrections to parse failures. includes post-developed commit: removed tabs that creeped in into rustfmt tool source code. includes post-developed commit, placating rustfmt self dogfooding. includes post-developed commit: add backquotes to prevent markdown checking from trying to treat an attr as a markdown hyperlink/ includes post-developed commit: fix lowering to keep contracts from being erroneously inherited by nested bodies (like closures). Rebase Conflicts: - compiler/rustc_parse/src/parser/diagnostics.rs - compiler/rustc_parse/src/parser/item.rs - compiler/rustc_span/src/hygiene.rs Remove contracts keywords from diagnostic messages
2025-02-03tree-wide: parallel: Fully removed all `Lrc`, replaced with `Arc`Askar Safin-8/+9
2025-02-03Use a different hir type for patterns in pattern types than we use in match ↵Oli Scherer-1/+3
patterns
2025-02-01Rename `tcx.ensure_with_value()` to `tcx.ensure_done()`Zalathar-4/+4
2025-01-23Handle parenthesised infer argsBoxy-6/+11
2025-01-23Semantic changes from new hir representationBoxy-1/+1
Always lower to `GenericArg::Infer` Update `PlaceholderCollector` Update closure lifetime binder infer var visitor Fallback visitor handle ambig infer args Ensure type infer args have their type recorded
2025-01-23Split hir `TyKind` and `ConstArgKind` in two and update `hir::Visitor`Boxy-5/+7
2025-01-23Make `hir::TyKind::TraitObject` use tagged ptrBoxy-4/+7
2025-01-08Exhaustively handle expressions in patternsOli Scherer-0/+1
2025-01-02Unconditionally lower generic_arg_inferMichael Goulet-6/+3
2025-01-01Fix ICE when opaque captures a duplicated/invalid lifetimeMichael Goulet-2/+2
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-2/+1
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-12-15Add hir::AttributeJonathan Dönszelmann-19/+25
2024-12-15Rename `value` field to `expr` to simplify later commits' diffsOli Scherer-3/+3
2024-12-14(Re-)Implement impl_trait_in_bindingsMichael Goulet-0/+10
2024-12-12Lower AST and resolve lifetimes for unsafe binder typesMichael Goulet-0/+7
2024-12-03Rollup merge of #133779 - BoxyUwU:array_const_arg_infer_hir_id, ↵Matthias Krüger-1/+2
r=compiler-errors Use correct `hir_id` for array const arg infers Fixes #133771 `self.next_id()` results in the `DefId` for the const argument, created from the hack introduced by #133468, having no `HirId` associated with it. This then results in an ICE in metadata encoding. Fixing this then results in *another* ICE where `encode_defs` was not skipping encoding `type_of` and other queries for `DefId`s when they correspond to a `ConstArgKind::Infer` node. This only reproduces with a library crate as metadata is not encoded for binaries, and apparently we had 0 tests for `generic_arg_infer` for array lengths in a library crate so this was not caught :< cc #133589 `@voidc` r? `@compiler-errors` `@lcnr`
2024-12-03Use correct `hir_id` for array const arg infersBoxy-1/+2
2024-12-02Rollup merge of #133746 - oli-obk:push-xwyrylxmrtvq, r=jieyouxuGuillaume Gomez-5/+3
Change `AttrArgs::Eq` to a struct variant Cleanups for simplifying https://github.com/rust-lang/rust/pull/131808 Basically changes `AttrArgs::Eq` to a struct variant and then avoids several matches on `AttrArgsEq` in favor of methods on it. This will make future refactorings simpler, as they can either keep methods or switch to field accesses without having to restructure code
2024-12-02Deduplicate some matches that always panic in one armOli Scherer-4/+2
2024-12-02Change `AttrArgs::Eq` into a struct variantOli Scherer-3/+3
2024-12-01Rollup merge of #133589 - voidc:remove-array-len, r=boxyuwuJacob Pratt-10/+9
Remove `hir::ArrayLen` This refactoring removes `hir::ArrayLen`, replacing it with `hir::ConstArg`. To represent inferred array lengths (previously `hir::ArrayLen::Infer`), a new variant `ConstArgKind::Infer` is added. r? `@BoxyUwU`
2024-11-30Remove hir::ArrayLen, introduce ConstArgKind::InferDominik Stolz-10/+9
Remove Node::ArrayLenInfer
2024-11-28ast_lowering: rm separate `def_id_parent`lcnr-40/+14
no longer necessary as we now always create a ` DefId` for anon-consts
2024-11-28always create `DefId`s when lowering anon-constslcnr-15/+4
2024-11-25Remove dead code stemming from the old effects desugaring (II)León Orell Valerian Liehr-15/+3
2024-11-19Introduce `min_generic_const_args` and directly represent pathsNoah Lev-48/+60
Co-authored-by: Boxy UwU <rust@boxyuwu.dev> Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
2024-11-15Fix span edition for 2024 RPIT coming from an external macroEric Huss-1/+1
This fixes a problem where code generated by an external macro with an RPIT would end up using the call-site edition instead of the macro's edition for the RPIT. When used from a 2024 crate, this caused the code to change behavior to the 2024 capturing rules, which we don't want. This was caused by the impl-trait lowering code would replace the span with one marked with `DesugaringKind::OpaqueTy` desugaring. However, it was also overriding the edition of the span with the edition of the local crate. Instead it should be using the edition of the span itself. Fixes https://github.com/rust-lang/rust/issues/132917
2024-10-31Encode cross-crate opaque type originMichael Goulet-3/+3
2024-10-30Remap impl-trait lifetimes on HIR instead of AST lowering.Camille GILLOT-246/+9
2024-10-29Rollup merge of #131375 - klensy:clone_on_ref_ptr, r=cjgillotJubilee-1/+1
compiler: apply clippy::clone_on_ref_ptr for CI Apply lint https://rust-lang.github.io/rust-clippy/master/index.html#/clone_on_ref_ptr for compiler, also see https://github.com/rust-lang/rust/pull/131225#discussion_r1790109443. Some Arc's can be misplaced with Lrc's, sorry. https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/enable.20more.20clippy.20lints.20for.20compiler.20.28and.5Cor.20std.29
2024-10-28fix clippy::clone_on_ref_ptr for compilerklensy-1/+1
2024-10-28more consistent debug_assertionsAdwin White-3/+14
2024-10-28Add duplicate lowering checkAdwin White-12/+23
2024-10-28Lower AST node id only onceAdwin White-37/+28
2024-10-24Remove associated type based effects logicMichael Goulet-17/+3
2024-10-23nightly feature tracking: get rid of the per-feature bool fieldsRalf Jung-6/+6
2024-10-22Represent TraitBoundModifiers as distinct parts in HIRMichael Goulet-18/+4
2024-10-19Make sure that outer opaques capture inner opaques's lifetimes even with ↵Michael Goulet-58/+21
precise capturing syntax
2024-10-15Auto merge of #131723 - matthiaskrgr:rollup-krcslig, r=matthiaskrgrbors-28/+22
Rollup of 9 pull requests Successful merges: - #122670 (Fix bug where `option_env!` would return `None` when env var is present but not valid Unicode) - #131095 (Use environment variables instead of command line arguments for merged doctests) - #131339 (Expand set_ptr_value / with_metadata_of docs) - #131652 (Move polarity into `PolyTraitRef` rather than storing it on the side) - #131675 (Update lint message for ABI not supported) - #131681 (Fix up-to-date checking for run-make tests) - #131702 (Suppress import errors for traits that couldve applied for method lookup error) - #131703 (Resolved python deprecation warning in publish_toolstate.py) - #131710 (Remove `'apostrophes'` from `rustc_parse_format`) r? `@ghost` `@rustbot` modify labels: rollup
2024-10-15Rollup merge of #130635 - eholk:pin-reborrow-sugar, r=compiler-errorsMatthias Krüger-8/+43
Add `&pin (mut|const) T` type position sugar This adds parser support for `&pin mut T` and `&pin const T` references. These are desugared to `Pin<&mut T>` and `Pin<&T>` in the AST lowering phases. This PR currently includes #130526 since that one is in the commit queue. Only the most recent commits (bd450027eb4a94b814a7dd9c0fa29102e6361149 and following) are new. Tracking: - #130494 r? `@compiler-errors`
2024-10-14Move trait bound modifiers into ast::PolyTraitRefMichael Goulet-9/+6
2024-10-14Move trait bound modifiers into hir::PolyTraitRefMichael Goulet-23/+20
2024-10-13Remove const trait bound modifier hackMichael Goulet-8/+2
2024-10-11Auto merge of #131045 - compiler-errors:remove-unnamed_fields, r=wesleywiserbors-40/+0
Retire the `unnamed_fields` feature for now `#![feature(unnamed_fields)]` was implemented in part in #115131 and #115367, however work on that feature has (afaict) stalled and in the mean time there have been some concerns raised (e.g.[^1][^2]) about whether `unnamed_fields` is worthwhile to have in the language, especially in its current desugaring. Because it represents a compiler implementation burden including a new kind of anonymous ADT and additional complication to field selection, and is quite prone to bugs today, I'm choosing to remove the feature. However, since I'm not one to really write a bunch of words, I'm specifically *not* going to de-RFC this feature. This PR essentially *rolls back* the state of this feature to "RFC accepted but not yet implemented"; however if anyone wants to formally unapprove the RFC from the t-lang side, then please be my guest. I'm just not totally willing to summarize the various language-facing reasons for why this feature is or is not worthwhile, since I'm coming from the compiler side mostly. Fixes #117942 Fixes #121161 Fixes #121263 Fixes #121299 Fixes #121722 Fixes #121799 Fixes #126969 Fixes #131041 Tracking: * https://github.com/rust-lang/rust/issues/49804 [^1]: https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Unnamed.20struct.2Funion.20fields [^2]: https://github.com/rust-lang/rust/issues/49804#issuecomment-1972619108
2024-10-10Add gate for precise capturing in traitsMichael Goulet-5/+14