about summary refs log tree commit diff
path: root/compiler/rustc_ast_lowering/src
AgeCommit message (Collapse)AuthorLines
2025-06-30Introduce `ByteSymbol`.Nicholas Nethercote-23/+13
It's like `Symbol` but for byte strings. The interner is now used for both `Symbol` and `ByteSymbol`. E.g. if you intern `"dog"` and `b"dog"` you'll get a `Symbol` and a `ByteSymbol` with the same index and the characters will only be stored once. The motivation for this is to eliminate the `Arc`s in `ast::LitKind`, to make `ast::LitKind` impl `Copy`, and to avoid the need to arena-allocate `ast::LitKind` in HIR. The latter change reduces peak memory by a non-trivial amount on literal-heavy benchmarks such as `deep-vector` and `tuple-stress`. `Encoder`, `Decoder`, `SpanEncoder`, and `SpanDecoder` all get some changes so that they can handle normal strings and byte strings. This change does slow down compilation of programs that use `include_bytes!` on large files, because the contents of those files are now interned (hashed). This makes `include_bytes!` more similar to `include_str!`, though `include_bytes!` contents still aren't escaped, and hashing is still much cheaper than escaping.
2025-06-25compiler: remove misleading 'c' from `abi_c_cmse_nonsecure_call` featureJubilee Young-1/+1
2025-06-25compiler: Trim the misleading C from ExternAbi::CCmse*Jubilee Young-2/+2
2025-06-24Rollup merge of #142983 - compiler-errors:taint-invalid-call-abi, ↵Jubilee-0/+3
r=workingjubilee Taint body on invalid call ABI Fixes https://github.com/rust-lang/rust/issues/142969 I'm not certain if there are any other paths that should be tainted, but they would operate similarly. Perhaps pointer coercion. Introduces `extern "rust-invalid"` for testing purposes. r? ```@workingjubilee``` or ```@oli-obk``` (or anyone)
2025-06-24Add rust-invalid ABIMichael Goulet-0/+3
2025-06-24Rewrite #[track_caller]Jana Dönszelmann-1/+2
2025-06-23compiler: plug unsupported ABI leakage from the ASTJubilee Young-4/+24
We modify rustc_ast_lowering to prevent all unsupported ABIs from leaking through the HIR without being checked for target support. Previously ad-hoc checking on various HIR items required making sure we check every HIR item which could contain an `extern "{abi}"` string. This is a losing proposition compared to gating the lowering itself. As a consequence, unsupported ABI strings will now hard-error instead of triggering the FCW `unsupported_fn_ptr_calling_conventions`. This FCW was upgraded to warn in dependencies in Rust 1.87 which was released on 2025 May 17, and it is now 2025 June, so it has become active within a stable Rust version. As we already had errored on these ABIs in most other positions, and have warned for fn ptrs, this breakage has had reasonable foreshadowing. However, this does cause errors for usages of `extern "{abi}"` that were theoretically writeable within source but could not actually be applied in any useful way by Rust programmers without either warning or error. For instance, trait declarations without impls were never checked. These are the exact kinds of leakages that this new approach prevents. A deprecation cycle is not useful for these marginal cases as upon impl, even default impls within traits, different HIR objects would be used. Details of our HIR analysis meant that those objects did get checked. We choose to error twice if an ABI is also barred by a feature gate on the presumption that usage of a target-incorrect ABI is intentional. Co-authored-by: Ralf Jung <post@ralfj.de>
2025-06-22Implement DesugaringKind::FormatLiteralmejrs-1/+8
2025-06-19Auto merge of #140748 - m-ou-se:super-format-args3, r=jdonszelmannbors-135/+103
Allow storing `format_args!()` in variable Fixes https://github.com/rust-lang/rust/issues/92698 Tracking issue for super let: https://github.com/rust-lang/rust/issues/139076 Tracking issue for format_args: https://github.com/rust-lang/rust/issues/99012 This change allows: ```rust let name = "world"; let f = format_args!("hello {name}!"); // New: Store format_args!() for later! println!("{f}"); ``` This will need an FCP. This implementation makes use of `super let`, which is unstable and might not exist in the future in its current form. However, it is entirely reasonable to assume future Rust will always have _a_ way of expressing temporary lifetimes like this, since the (stable) `pin!()` macro needs this too. (This was also the motivation for merging https://github.com/rust-lang/rust/pull/139114.) (This is a second version of https://github.com/rust-lang/rust/pull/139135)
2025-06-19Use expr_ref.Mara Bos-2/+1
2025-06-18Rollup merge of #141610 - BoxyUwU:stabilize_generic_arg_infer, ↵Jakub Beránek-11/+2
r=lcnr,traviscross Stabilize `feature(generic_arg_infer)` Fixes rust-lang/rust#85077 r? lcnr cc ````@rust-lang/project-const-generics````
2025-06-18Fix span of AddrOf in format_args!() expansion.Mara Bos-1/+1
Diagnostics should know that the `&` for arguments in format_args!() come from the macro expansion rather than from the original source.
2025-06-18Allow storing `format_args!()` in `let`.Mara Bos-135/+104
This uses `super let` to allow let f = format_args!("Hello {}", world); println!("{f}"); to work.
2025-06-17Rename hir const arg walking functionsBoxy-1/+1
2025-06-17Reject union default field valuesJieyou Xu-10/+39
2025-06-15Auto merge of #142455 - ↵bors-0/+5
jdonszelmann:attempt-to-mitigate-delayed-lint-perf-problems, r=oli-obk collect delayed lints in hir_crate_items r? `@oli-obk` Attempt to mitigate perf problems in rust-lang/rust#138164
2025-06-13Rollup merge of #142449 - oli-obk:missing-mgca-args, r=BoxyUwUJubilee-2/+2
Require generic params for const generic params I think that was just an oversight when the support for them was added r? `@BoxyUwU` or `@camelid` fixes rust-lang/rust#137188 fixes rust-lang/rust#138166 fixes rust-lang/rust#138240 fixes rust-lang/rust#138266 fixes rust-lang/rust#138359
2025-06-13collect delayed lints in hir_crate_itemsJana Dönszelmann-0/+5
2025-06-13Require generic params for const generic paramsOli Scherer-2/+2
2025-06-13Rollup merge of #142267 - workingjubilee:debug-assert-less-in-ast-lowering, ↵Matthias Krüger-18/+18
r=oli-obk assert more in release in `rustc_ast_lowering` My understanding of the compiler's architecture is that in the `ast_lowering` crate, we are constructing the HIR as a one-time thing per crate. This is after tokenizing, parsing, resolution, expansion, possible reparsing, reresolution, reexpansion, and so on. In other words, there are many reasons that perf-focused PRs spend a lot of time touching `rustc_parse`, `rustc_expand`, `rustc_ast`, and then `rustc_hir` and "onwards", but `ast_lowering` is a little bit of an odd duck. In this crate, we have a number of debug assertions. Some are clearly expensive checks that seem like they are prohibitive to run in actual optimized compiler builds, but then there are a number that are simple asserts on integer equalities, `is_empty`, or the like. I believe we should do some of them even in release builds, because the correctness gain is worth the performance cost: almost zero.
2025-06-13Rollup merge of #140770 - folkertdev:custom-abi, r=tgross35Matthias Krüger-0/+3
add `extern "custom"` functions tracking issue: rust-lang/rust#140829 previous discussion: https://github.com/rust-lang/rust/issues/140566 In short, an `extern "custom"` function is a function with a custom ABI, that rust does not know about. Therefore, such functions can only be defined with `#[unsafe(naked)]` and `naked_asm!`, or via an `extern "C" { /* ... */ }` block. These functions cannot be called using normal rust syntax: calling them can only be done from inline assembly. The motivation is low-level scenarios where a custom calling convention is used. Currently, we often pick `extern "C"`, but that is a lie because the function does not actually respect the C calling convention. At the moment `"custom"` seems to be the name with the most support. That name is not final, but we need to pick something to actually implement this. r? `@traviscross` cc `@tgross35` try-job: x86_64-apple-2
2025-06-12add `extern "custom"` functionsFolkert de Vries-0/+3
2025-06-12introduce new lint infraJana Dönszelmann-22/+62
lint on duplicates during attribute parsing To do this we stuff them in the diagnostic context to be emitted after hir is constructed
2025-06-11stabilize gaiBoxy-11/+2
2025-06-09assert more often in release in ast_loweringJubilee Young-13/+13
2025-06-09assert in release in ast_lowering::itemJubilee Young-5/+5
2025-06-08Remove all unused feature gates from the compilerbjorn3-2/+0
2025-06-06Rollup merge of #142012 - oli-obk:no-optional-spans, r=fee1-deadMatthias Krüger-1/+1
Replace some `Option<Span>` with `Span` and use DUMMY_SP instead of None Turns out many locations actually have a span available that we could use, so I used it
2025-06-05Auto merge of #138677 - shepmaster:consistent-elided-lifetime-syntax, ↵bors-3/+3
r=traviscross,jieyouxu Add a new `mismatched-lifetime-syntaxes` lint The lang-team [discussed this](https://hackmd.io/nf4ZUYd7Rp6rq-1svJZSaQ) and I attempted to [summarize](https://github.com/rust-lang/rust/pull/120808#issuecomment-2701863833) their decision. The summary-of-the-summary is: - Using two different kinds of syntax for elided lifetimes is confusing. In rare cases, it may even [lead to unsound code](https://github.com/rust-lang/rust/issues/48686)! Some examples: ```rust // Lint will warn about these fn(v: ContainsLifetime) -> ContainsLifetime<'_>; fn(&'static u8) -> &u8; ``` - Matching up references with no lifetime syntax, references with anonymous lifetime syntax, and paths with anonymous lifetime syntax is an exception to the simplest possible rule: ```rust // Lint will not warn about these fn(&u8) -> &'_ u8; fn(&'_ u8) -> &u8; fn(&u8) -> ContainsLifetime<'_>; ``` - Having a lint for consistent syntax of elided lifetimes will make the [future goal](https://github.com/rust-lang/rust/issues/91639) of warning-by-default for paths participating in elision much simpler. --- This new lint attempts to accomplish the goal of enforcing consistent syntax. In the process, it supersedes and replaces the existing `elided-named-lifetimes` lint, which means it starts out life as warn-by-default.
2025-06-05Replace some `Option<Span>` with `Span` and use DUMMY_SP instead of NoneOli Scherer-1/+1
2025-06-03Add `iter` macroOli Scherer-7/+8
This adds an `iter!` macro that can be used to create movable generators. This also adds a yield_expr feature so the `yield` keyword can be used within iter! macro bodies. This was needed because several unstable features each need `yield` expressions, so this allows us to stabilize them separately from any individual feature. Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de> Co-authored-by: Jieyou Xu <jieyouxu@outlook.com> Co-authored-by: Travis Cross <tc@traviscross.com>
2025-06-03Rename `LifetimeSyntax` variants to lang-team-approved namesJake Goulding-3/+3
2025-06-03Auto merge of #141954 - matthiaskrgr:rollup-zptd6t9, r=matthiaskrgrbors-7/+1
Rollup of 9 pull requests Successful merges: - rust-lang/rust#141554 (Improve documentation for codegen options) - rust-lang/rust#141817 (rustc_llvm: add Windows system libs only when cross-compiling from Wi…) - rust-lang/rust#141843 (Add `visit_id` to ast `Visitor`) - rust-lang/rust#141881 (Subtree update of `rust-analyzer`) - rust-lang/rust#141898 ([rustdoc-json] Implement PartialOrd and Ord for rustdoc_types::Id) - rust-lang/rust#141921 (Disable f64 minimum/maximum tests for arm 32) - rust-lang/rust#141930 (Enable triagebot `[concern]` functionality) - rust-lang/rust#141936 (Decouple "reporting in deps" from `FutureIncompatibilityReason`) - rust-lang/rust#141949 (move `test-float-parse` tool into `src/tools` dir) r? `@ghost` `@rustbot` modify labels: rollup
2025-06-03Rollup merge of #141843 - fee1-dead-contrib:ast_visitor_visit_id, r=oli-obkMatthias Krüger-7/+1
Add `visit_id` to ast `Visitor` This helps with efforts to deduplicate the `MutVisitor` and the `Visitor` code. All users of `Visitor`'s methods that have extra `NodeId` as parameters really just want to visit the id on its own. Also includes some methods deduplicated and cleaned up as a result of this change. r? oli-obk
2025-06-03Overhaul `UsePath`.Nicholas Nethercote-14/+32
`UsePath` contains a `SmallVec<[Res; 3]>`. This holds up to three `Res` results, one per namespace (type, value, or macro). `lower_import_res` takes a `PerNS<Option<Res<NodeId>>>` result and lowers it into the `SmallVec`. This is pretty weird. The input `PerNS` makes it clear which `Res` belongs to which namespace, but the `SmallVec` throws that information away. And code that operates on the `SmallVec` tends to use iteration (or even just grabbing the first entry!) without knowing which namespace the `Res` belongs to. Even weirder! Also, `SmallVec` is an overly flexible type to use here, because it can contain any number of elements (even though it's optimized for 3 in this case). This commit changes `UsePath` so it also contains a `PerNS<Option<Res<HirId>>>`. This type preserves more information and is more self-documenting. The commit also changes a lot of the use sites to access the result for a particular namespace. E.g. if you're looking up a trait, it will be in the `Res` for the type namespace if it's present; it's silly to look in the `Res` for the value namespace or macro namespace. Overall I find the new code much easier to understand. However, some use sites still iterate. These now use `present_items` because that filters out the `None` results. Also, `redundant_pub_crate.rs` gets a bigger change. A `UseKind:ListStem` item gets no `Res` results, which means the old `all` call in `is_not_macro_export` would succeed (because `all` succeeds on an empty iterator) and the `ListStem` would be ignored. This is what we want, but was more by luck than design. The new code detects `ListStem` explicitly. The commit generalizes the name of that function accordingly. Finally, the commit also removes the `use_path` arena, because `PerNS<Option<Res>>` impls `Copy` (unlike `SmallVec`) and it can be allocated in the arena shared by all `Copy` types.
2025-06-01Add `visit_id` to ast `Visitor`Deadbeef-7/+1
This helps with efforts to deduplicate the `MutVisitor` and the `Visitor` code. All users of `Visitor`'s methods that have extra `NodeId` as parameters really just want to visit the id on its own. Also includes some methods deduplicated and cleaned up as a result of this change.
2025-05-30Reorder hir fn stuff.Nicholas Nethercote-1/+1
In `Fn`, put `ident` next to `generics` as is common in many other types. In `print_fn`, make the argument order match the printing order.
2025-05-30Reorder fields in `hir::ItemKind` variants.Nicholas Nethercote-7/+7
Specifically `TyAlias`, `Enum`, `Struct`, `Union`. So the fields match the textual order in the source code. The interesting part of the change is in `compiler/rustc_hir/src/hir.rs`. The rest is extremely mechanical refactoring.
2025-05-28Reorder `ast::ItemKind::{Struct,Enum,Union}` fields.Nicholas Nethercote-3/+3
So they match the order of the parts in the source code, e.g.: ``` struct Foo<T, U> { t: T, u: U } <-><----> <------------> / | \ ident generics variant_data ```
2025-05-22Rename `kw::Empty` as `sym::empty`.Nicholas Nethercote-2/+2
Because the empty string is not a keyword.
2025-05-20Inline and remove `lower_*` methods.Nicholas Nethercote-28/+18
They are all short and have a single call site.
2025-05-20Hoist `ItemLowerer` out of a loop.Nicholas Nethercote-7/+7
2025-05-20Remove unused return value from `lower_node`.Nicholas Nethercote-3/+1
2025-05-13Auto merge of #140887 - pietroalbini:pa-bootstrap-update, r=compiler-errorsbors-1/+0
Stage0 bootstrap update This PR [follows the release process](https://forge.rust-lang.org/release/process.html#master-bootstrap-update-tuesday) to update the stage0 compiler. The only thing of note is https://github.com/rust-lang/rust/commit/58651d1b316e268fac2100c3ae37bb502a36b8ba, which was flagged by clippy as a correctness fix. I think allowing that lint in our case makes sense, but it's worth to have a second pair of eyes on it. r? `@Mark-Simulacrum`
2025-05-12Fix typosomahs-1/+1
2025-05-12update cfg(bootstrap)Pietro Albini-1/+0
2025-05-05Auto merge of #140453 - Zoxc:next-disambiguator, r=oli-obkbors-10/+9
Remove global `next_disambiguator` state and handle it with a `DisambiguatorState` type This removes `Definitions.next_disambiguator` as it doesn't guarantee deterministic def paths when `create_def` is called in parallel. Instead a new `DisambiguatorState` type is passed as a mutable reference to `create_def` to help create unique def paths. `create_def` calls with distinct `DisambiguatorState` instances must ensure that that the def paths are unique without its help. Anon associated types did rely on this global state for uniqueness and are changed to use (method they're defined in + their position in the method return type) as the `DefPathData` to ensure uniqueness. This also means that the method they're defined in appears in error messages, which is nicer. `DefPathData::NestedStatic` is added to use for nested data inside statics instead of reusing `DefPathData::AnonConst` to avoid conflicts with those. cc `@oli-obk`
2025-05-04Initial support for dynamically linked cratesBryanskiy-1/+3
2025-05-02Rollup merge of #139046 - nnethercote:hir-Lifetime-better, r=lcnrStuart Cook-18/+22
Improve `Lifetime::suggestion` r? ``@lcnr``
2025-05-02Handle `Path<>` better in error messages.Nicholas Nethercote-18/+22
`Path<>` needs to be distinguished from `Path<T>`. This commit does that, improving some error messages.