summary refs log tree commit diff
path: root/compiler
AgeCommit message (Collapse)AuthorLines
2025-06-20Rollup merge of #142765 - workingjubilee:more-abimap-docs, r=compiler-errorsTrevor Gross-0/+6
rustc_target: document public AbiMap-related fn and variants
2025-06-20Rollup merge of #142716 - nnethercote:adjust-with_generic_param_rib, ↵Trevor Gross-119/+77
r=petrochenkov Adjust `with_generic_param_rib`. Currently all of its call sites construct a `LifetimeRibKind::Generics` value, which `with_generic_param_rib` then deconstructs (and panics if it's a different `LifetimeRibKind` variant). This commit makes the code simpler and shorter: the call sites just pass in the three values and `with_generic_param_rib` constructs the `LifetimeRibKind::Generics` value from them. r? `@petrochenkov`
2025-06-20Rollup merge of #142571 - cjgillot:borrowed-classes, r=oli-obkTrevor Gross-27/+30
Reason about borrowed classes in CopyProp. Fixes https://github.com/rust-lang/rust/issues/141122 The current implementation of `CopyProp` avoids unifying two borrowed locals, as this would change the result of address comparison. However, the implementation was inconsistent with the general algorithm, which identifies equivalence classes of locals and then replaces all locals by a single representative of their equivalence class. This PR fixes it by forbidding the unification of two *classes* if any of those contain a borrowed local.
2025-06-20Rollup merge of #142485 - mu001999-contrib:dead-code/adt-pattern, r=petrochenkovTrevor Gross-50/+28
Marks ADT live if it appears in pattern Marks ADT live if it appears in pattern, it implies the construction of the ADT. 1. Then we can detect unused private ADTs impl `Default`, without special logics for `Default` and other std traits. 2. We can also remove `rustc_trivial_field_reads` on `Default`, and the logic in `should_ignore_item` (introduced by rust-lang/rust#126302). Fixes rust-lang/rust#120770 Extracted from rust-lang/rust#128637. r? `@petrochenkov`
2025-06-20Rollup merge of #142476 - dtolnay:attrbinop, r=fmeaseTrevor Gross-12/+38
Insert parentheses around binary operation with attribute Fixes the bug found by `@fmease` in https://github.com/rust-lang/rust/pull/134661#pullrequestreview-2538983253. Previously, `-Zunpretty=expanded` would expand this program as follows: ```rust #![feature(stmt_expr_attributes)] #![allow(unused_attributes)] macro_rules! group { ($e:expr) => { $e }; } macro_rules! extra { ($e:expr) => { #[allow()] $e }; } fn main() { let _ = #[allow()] 1 + 1; let _ = group!(#[allow()] 1) + 1; let _ = 1 + group!(#[allow()] 1); let _ = extra!({ 0 }) + 1; let _ = extra!({ 0 } + 1); } ``` ```console let _ = #[allow()] 1 + 1; let _ = #[allow()] 1 + 1; let _ = 1 + #[allow()] 1; let _ = #[allow()] { 0 } + 1; let _ = #[allow()] { 0 } + 1; ``` The first 4 statements are the correct expansion, but the last one is not. The attribute is supposed to apply to the entire binary operation, not only to the left operand. After this PR, the 5th statement will expand to: ```console let _ = #[allow()] ({ 0 } + 1); ``` In the future, as some subset of `stmt_expr_attributes` approaches stabilization, it is possible that we will need to do parenthesization for a number of additional cases depending on the outcome of https://github.com/rust-lang/rust/issues/127436. But for now, at least this PR makes the pretty-printer align with the current behavior of the parser. r? fmease
2025-06-20Rollup merge of #142384 - celinval:chores-rayon-mv, r=oli-obkTrevor Gross-22/+7889
Bringing `rustc_rayon_core` in tree as `rustc_thread_pool` This PR moves [`rustc_rayon_core`](https://github.com/rust-lang/rustc-rayon/tree/5fadf44/rayon-core) from commit `5fadf44` as suggested in [this zulip thread](https://rust-lang.zulipchat.com/#narrow/channel/187679-t-compiler.2Fparallel-rustc/topic/Bringing.20.60rustc_rayon_core.60.20in.20tree). I tried to split the work into separate commits so it is easy to review. The first commit is a simple copy and paste from the fork, and subsequent changes were made to use the new crate and to ensure the new crate complies with different format and lint expectations. **Call-out:** I was also wondering if I need to make any further changes to accommodate licensing requirements. r? oli-obk
2025-06-20Auto merge of #142794 - tgross35:rollup-iae7okj, r=tgross35bors-610/+678
Rollup of 9 pull requests Successful merges: - rust-lang/rust#142331 (Add `trim_prefix` and `trim_suffix` methods for both `slice` and `str` types.) - rust-lang/rust#142491 (Rework #[cold] attribute parser) - rust-lang/rust#142494 (Fix missing docs in `rustc_attr_parsing`) - rust-lang/rust#142495 (Better template for `#[repr]` attributes) - rust-lang/rust#142497 (Fix random failure when JS code is executed when the whole file was not read yet) - rust-lang/rust#142575 (Ensure copy* intrinsics also perform the static self-init checks) - rust-lang/rust#142650 (Refactor Translator) - rust-lang/rust#142713 (mbe: Refactor transcription) - rust-lang/rust#142755 (rustdoc: Remove `FormatRenderer::cache`) r? `@ghost` `@rustbot` modify labels: rollup
2025-06-20Insert parentheses around binary operation with attributeDavid Tolnay-12/+38
2025-06-20Recover from semicolon field separatorCameron Steffen-15/+18
2025-06-20Port `#[may_dangle]` to the new attribute systemPavel Grigorenko-3/+33
2025-06-20Use gen blocks in the compiler instead of from_coroutineMichael Goulet-154/+139
2025-06-20Rollup merge of #142769 - jdonszelmann:remove-useless-new-method, r=tgross35Jakub Beránek-9/+3
remove equivalent new method on context Noticed the two had converged so much they literally became equivalent. So one could go hehe
2025-06-20Rollup merge of #142767 - nnethercote:symbol-cleanups, r=petrochenkovJakub Beránek-21/+26
Some symbol and PathRoot cleanups I'm looking into unifying how we join and print paths. Here are some preliminary cleanups. r? ``@petrochenkov``
2025-06-20Rollup merge of #142715 - folkertdev:fn-align-corrections, r=jdonszelmannJakub Beránek-2/+2
correct template for `#[align]` attribute Tracking issue: https://github.com/rust-lang/rust/issues/82232 related: https://github.com/rust-lang/rust/pull/142507 I didn't fully understand what `template!` did, clearly. An empty `#[align]` attribute was still rejected later, but without this change it does get suggested in certain cases. I've also updated some outdated references to `#[repr(align)]` on functions. r? ``@jdonszelmann``
2025-06-20compiler: Rename LayoutS to LayoutData in commentsZachary S-8/+8
2025-06-20Factor out seen_comma variableCameron Steffen-15/+3
2025-06-20Rollup merge of #142713 - tgross35:mbe-transcribe-refactor, r=petrochenkovTrevor Gross-363/+404
mbe: Refactor transcription Introduce `MacroTcbCtx` that holds everything relevant to transcription. This allows for the following changes: * Split `transcribe_sequence` and `transcribe_metavar` out of the heavily nested `transcribe` * Split `metavar_expr_concat` out of `transcribe_metavar_expr` This is a nonfunctional change.
2025-06-20Rollup merge of #142650 - camsteffen:refactor-translator, r=petrochenkovTrevor Gross-232/+185
Refactor Translator My main motivation was to simplify the usage of `SilentEmitter` for users like rustfmt. A few refactoring opportunities arose along the way. * Replace `Translate` trait with `Translator` struct * Replace `Emitter: Translate` with `Emitter::translator` * Split `SilentEmitter` into `FatalOnlyEmitter` and `SilentEmitter`
2025-06-20Rollup merge of #142575 - oli-obk:sneaky-self-init, r=RalfJungTrevor Gross-1/+6
Ensure copy* intrinsics also perform the static self-init checks fixes rust-lang/rust#142532 r? `@RalfJung`
2025-06-20Rollup merge of #142495 - jdonszelmann:better-repr-template, r=oli-obkTrevor Gross-1/+2
Better template for `#[repr]` attributes
2025-06-20Rollup merge of #142494 - jdonszelmann:missing-attr-parsing-docs, r=oli-obkTrevor Gross-0/+19
Fix missing docs in `rustc_attr_parsing`
2025-06-20Rollup merge of #142491 - jdonszelmann:cold, r=oli-obkTrevor Gross-13/+62
Rework #[cold] attribute parser r? `@oli-obk`
2025-06-20error on calls to ABIs that cannot be calledFolkert de Vries-25/+52
2025-06-20Add diagnostic items for ClippySamuel Tardieu-0/+7
2025-06-20expected word diagnostic testJana Dönszelmann-3/+4
2025-06-20coldJana Dönszelmann-13/+61
2025-06-20Auto merge of #142316 - compiler-errors:cache-param-env, r=lcnrbors-20/+177
[perf] Cache the canonical *instantiation* of param-envs r? lcnr
2025-06-20Ensure copy* intrinsics also perform the static self-init checksOli Scherer-1/+6
2025-06-20Rollup merge of #142687 - cjgillot:less-hir_crate, r=oli-obkTrevor Gross-100/+48
Reduce uses of `hir_crate`. I tried rebasing my old incremental-HIR branch. This is a by-product, which is required if we want to get rid of `hir_crate` entirely. The second commit is a drive-by cleanup. It can be pulled into its own PR. r? ````@oli-obk````
2025-06-20Rollup merge of #140920 - RalfJung:target-feature-unification, ↵Trevor Gross-602/+486
r=nnethercote,WaffleLapkin Extract some shared code from codegen backend target feature handling There's a bunch of code duplication between the GCC and LLVM backends in target feature handling. This moves that into new shared helper functions in `rustc_codegen_ssa`. The first two commits should be purely refactoring. I am fairly sure the LLVM-side behavior stays the same; if the GCC side deliberately diverges from this then I may have missed that. I did account for one divergence, which I do not know is deliberate or not: GCC does not seem to use the `-Ctarget-feature` flag to populate `cfg(target_feature)`. That seems odd, since the `-Ctarget-feature` flag is used to populate the return value of `global_gcc_features` which controls the target features actually used by GCC. ``@GuillaumeGomez`` ``@antoyo`` is there a reason `target_config` ignores `-Ctarget-feature` but `global_gcc_features` does not? The second commit also cleans up a bunch of unneeded complexity added in https://github.com/rust-lang/rust/pull/135927. The third commit extracts some shared logic out of the functions that populate `cfg(target_feature)` and the backend target feature set, respectively. This one actually has some slight functional changes: - Before, with `-Ctarget-feature=-feat`, if there is some other feature `x` that implies `feat` we would *not* add `-x` to the backend target feature set. Now, we do. This fixes rust-lang/rust#134792. - The logic that removes `x` from `cfg(target_feature)` in this case also changed a bit, avoiding a large number of calls to the (uncached) `sess.target.implied_target_features` (if there were a large number of positive features listed before a negative feature) but instead constructing a full inverse implication map when encountering the first negative feature. Ideally this would be done with queries but the backend target feature logic runs before `tcx` so we can't use that... - Previously, if feature "a" implied "b" and "b" was unstable, then using `-Ctarget-feature=+a` would also emit a warning about `b`. I had to remove this since when accounting for negative implications, this emits a ton of warnings in a bunch of existing tests... I assume this was unintentional anyway. The fourth commit increases consistency of the GCC backend with the LLVM backend. The last commit does some further cleanup: - Get rid of RUSTC_SPECIAL_FEATURES. It was only needed for s390x "backchain", but since LLVM 19 that is always a regular target feature so we don't need this hack any more. The hack also has various unintended side-effects so we don't want to keep it. Fixes https://github.com/rust-lang/rust/issues/142412. - Move RUSTC_SPECIFIC_FEATURES handling into the shared parse_rust_feature_flag helper so all consumers of `-Ctarget-feature` that only care about actual target features (and not "crt-static") have it. Previously, we actually set `cfg(target_feature = "crt-static")` twice: once in the backend target feature logic, and once specifically for that one feature. IIUC, some targets are meant to ignore `-Ctarget-feature=+crt-static`, it seems like before this PR that flag still incorrectly enabled `cfg(target_feature = "crt-static")` (but I didn't test this). - Move fixed_x18 handling together with retpoline handling. - Forbid setting fixed_x18 as a regular target feature, even unstably. It must be set via the `-Z` flag. ``@bjorn3`` I did not touch the cranelift backend here, since AFAIK it doesn't really support target features. But if you ever do, please use the new helpers. :) Cc ``@workingjubilee``
2025-06-20Rollup merge of #138291 - jdonszelmann:optimize-attr, r=oli-obkTrevor Gross-52/+63
rewrite `optimize` attribute to use new attribute parsing infrastructure r? ```@oli-obk``` I'm afraid we'll get quite a few of these PRs in the future. If we get a lot of trivial changes I'll start merging multiple into one PR. They should be easy to review :) Waiting on #138165 first
2025-06-20remove equivalent new method on contextJana Dönszelmann-9/+3
2025-06-20Avoid some unnecessary symbol interning.Nicholas Nethercote-8/+9
- `Ident::from_str_and_span` -> `Ident::new` when the string is pre-interned. - `Ident::from_str` -> `Ident::with_dummy_span` when the string is pre-interned. - `_d` and `_e` are unused.
2025-06-20Use a symbol for `ExpansionConfig::crate_name`.Nicholas Nethercote-11/+12
This avoids some symbol interning and `to_string` conversions.
2025-06-20Fix `tests/ui/asm/naked-invalid-attr.stderr`.Nicholas Nethercote-2/+5
`{{root}}` is supposed to be an internal-only name but it shows up in the output. (I'm working towards a more general fix -- a universal "joiner" function that can be used all over the place -- but I'm not there yet, so let's fix this one in-place for now.)
2025-06-19rustc_target: document public AbiMap-related fn and variantsJubilee Young-0/+6
2025-06-19Auto merge of #140748 - m-ou-se:super-format-args3, r=jdonszelmannbors-162/+114
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-19Extract SilentEmitterCameron Steffen-38/+21
2025-06-19Rename SilentEmitter -> FatalOnlyEmitterCameron Steffen-8/+8
2025-06-19Extract Translator structCameron Steffen-191/+161
2025-06-19mbe: Refactor transcriptionTrevor Gross-348/+389
Introduce `MacroTcbCtx` that holds everything relevant to transcription. This allows for the following changes: * Split `transcribe_sequence` and `transcribe_metavar` out of the heavily nested `transcribe` * Split `metavar_expr_concat` out of `transcribe_metavar_expr` This is a nonfunctional change.
2025-06-19mbe: Move `transcribe_metavar_expr` directly after `transcribe`Trevor Gross-96/+96
Be more consistent with the otherwise top-down organization of this file.
2025-06-19Improve diagnostics for `concat_bytes!` with C string literalsTrevor Gross-10/+41
Use the same error as other invalid types for `concat_bytes!`, rather than using `ConcatCStrLit` from `concat!`. Also add more information with a note about why this doesn't work, and a suggestion to use a null-terminated byte string instead.
2025-06-19Remove old format_args diagnostic.Mara Bos-27/+11
2025-06-19Use expr_ref.Mara Bos-2/+1
2025-06-19correct template for `#[align]`Folkert de Vries-2/+2
it should not suggest just `#[align]`
2025-06-19Update compiler/rustc_interface/src/passes.rsCamille Gillot-1/+1
Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
2025-06-19Adjust `with_generic_param_rib`.Nicholas Nethercote-119/+77
Currently all of its call sites construct a `LifetimeRibKind::Generics` value, which `with_generic_param_rib` then deconstructs (and panics if it's a different `LifetimeRibKind` variant). This commit makes the code simpler and shorter: the call sites just pass in the three values and `with_generic_param_rib` constructs the `LifetimeRibKind::Generics` value from them.
2025-06-19completely deduplicate `Visitor` and `MutVisitor`Deadbeef-674/+461
2025-06-19remove `walk_item_kind` from `MutVisitor`Deadbeef-49/+3
just using `walk_item` instead would be okay.