about summary refs log tree commit diff
path: root/compiler
AgeCommit message (Collapse)AuthorLines
2025-04-15Rollup merge of #139789 - lcnr:opaques-auto-trait-leakage, r=compiler-errorsStuart Cook-7/+25
do not unnecessarily leak auto traits in item bounds fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/158 Not a fix for https://github.com/rust-lang/trait-system-refactor-initiative/issues/173 as you may have realized/tried yourself, cc #139788. However, fixing this feels desirable regardless and I don't see any reason not to. r? ```@compiler-errors```
2025-04-15Rollup merge of #139772 - nnethercote:rm-hir-Map, r=ZalatharStuart Cook-40/+17
Remove `hir::Map` A follow-up to https://github.com/rust-lang/rust/pull/139232. r? `@Zalathar`
2025-04-15Rollup merge of #139671 - m-ou-se:proc-macro-span, r=dtolnayStuart Cook-27/+27
Proc macro span API redesign: Replace proc_macro::SourceFile by Span::{file, local_file} Simplification/redesign of the unstable proc macro span API, tracked in https://github.com/rust-lang/rust/issues/54725: Before: ```rust impl Span { pub fn line(&self) -> usize; pub fn column(&self) -> usize; pub fn source_file(&self) -> SourceFile; } #[derive(Clone, Debug, PartialEq, Eq)] pub struct SourceFile { .. } impl !Send for SourceFile {} impl !Sync for SourceFile {} impl SourceFile { pub fn path(&self) -> PathBuf; pub fn is_real(&self) -> bool; } ``` After: ```rust impl Span { pub fn line(&self) -> usize; pub fn column(&self) -> usize; pub fn file(&self) -> String; // Mapped file name, for display purposes. pub fn local_file(&self) -> Option<PathBuf>; // Real file name as it exists on disk. } ``` This resolves the last blocker for stabilizing these methods. (Stabilizing will be a separate PR with FCP.)
2025-04-15Rollup merge of #139669 - nnethercote:overhaul-AssocItem, r=oli-obkStuart Cook-492/+557
Overhaul `AssocItem` `AssocItem` has multiple fields that only make sense some of the time. E.g. the `name` can be empty if it's an RPITIT associated type. It's clearer and less error prone if these fields are moved to the relevant `kind` variants. r? ``@fee1-dead``
2025-04-15Rollup merge of #138393 - oli-obk:pattern-type-in-pattern, r=BoxyUwUStuart Cook-7/+36
Allow const patterns of matches to contain pattern types Trying to pattern match on a type containing a pattern type will currently fail with an ICE ```rust error: internal compiler error: compiler/rustc_mir_build/src/builder/matches/test.rs:459:18: invalid type for non-scalar compare: (u32) is 1.. --> src/main.rs:22:5 | 22 | TWO => {} | ^^^ ``` because the compiler tries to generate a MIR `BinOp(Eq)` operation on a pattern type, which is not supported. While we could support that, there are side effects of allowing this (none that would compile, but the compiler would simultaneously think it could `==` pattern types and that it could not because `PartialEq` is not implemented. So instead I change the logic for pattern matching to transmute pattern types to their base type before comparing. r? ```@BoxyUwU``` cc #123646 ```@scottmcm``` ```@joshtriplett```
2025-04-15Rollup merge of #138374 - celinval:issue-136925-const-contract, ↵Stuart Cook-14/+23
r=compiler-errors,oli-obk,RalfJung Enable contracts for const functions Use `const_eval_select!()` macro to enable contract checking only at runtime. The existing contract logic relies on closures, which are not supported in constant functions. This commit also removes one level of indirection for ensures clauses since we no longer build a closure around the ensures predicate. Resolves #136925 **Call-out:** This is still a draft PR since CI is broken due to a new warning message for unreachable code when the bottom of the function is indeed unreachable. It's not clear to me why the warning wasn't triggered before. r? ```@compiler-errors```
2025-04-15Auto merge of #139826 - matthiaskrgr:rollup-0q0qvkd, r=matthiaskrgrbors-97/+71
Rollup of 8 pull requests Successful merges: - #139745 (Avoid unused clones in `Cloned<I>` and `Copied<I>`) - #139757 (opt-dist: use executable-extension for host llvm-profdata) - #139778 (Add test for issue 34834) - #139783 (Use `compiletest-ignore-dir` for bootstrap self-tests) - #139797 (Allow (but don't require) `#[unsafe(naked)]` so that `compiler-builtins` can upgrade to it) - #139799 (Specify `--print info=file` syntax in `--help`) - #139811 (Use `newtype_index!`-generated types more idiomatically) - #139813 (Miri subtree update) r? `@ghost` `@rustbot` modify labels: rollup
2025-04-14Stabilize `-Zdwarf-version` as `-Cdwarf-version`Wesley Wiser-2/+12
2025-04-15Fix HIR pretty-printing of fns with just a variadic arg.Nicholas Nethercote-1/+3
Avoid the extraneous comma.
2025-04-15Pretty-print `PatKind::Missing` as `_`.Nicholas Nethercote-3/+4
Printing "no pattern" as `_` isn't ideal, but better than crashing, and HIR pretty-printing already has plenty of imperfections. The added `f2` and `f6` examples are ones that triggered the crash. Note that some of the added examples are printed badly, e.g. `fn(, ...)`. The next commit will fix those. Fixes #139633.
2025-04-15Move `name` field from `AssocItem` to `AssocKind` variants.Nicholas Nethercote-218/+263
To accurately reflect that RPITIT assoc items don't have a name. This avoids the use of `kw::Empty` to mean "no name", which is error prone. Helps with #137978.
2025-04-15Move two methods from `AssocKind` to `AssocItem`.Nicholas Nethercote-27/+24
Because all the other similar methods are on `AssocItem`.
2025-04-15Move `opt_rpitit_info` field to `hir::AssocKind::Type`.Nicholas Nethercote-89/+101
From `hir::AssocItem`.
2025-04-14Rollup merge of #139811 - yotamofek:pr/newtype_cleanups, r=oli-obkMatthias Krüger-87/+61
Use `newtype_index!`-generated types more idiomatically Continuation of sorts of #139674 Shouldn't affect anything, just makes some code simpler
2025-04-14Rollup merge of #139799 - clubby789:print=file, r=jieyouxuMatthias Krüger-10/+4
Specify `--print info=file` syntax in `--help` Closes #139794 I moved the listing of information that can be printed to the help string as it's getting rather long and it makes the `[=FILE]` part easier to see
2025-04-14Rollup merge of #139797 - folkertdev:naked-allow-unsafe, r=tgross35Matthias Krüger-0/+6
Allow (but don't require) `#[unsafe(naked)]` so that `compiler-builtins` can upgrade to it tracking issue: https://github.com/rust-lang/rust/issues/138997 Per https://github.com/rust-lang/rust/pull/134213#issuecomment-2755984503, we want to make the `#[naked]` attribute an unsafe attribute. Making that change runs into a cyclic dependency with `compiler-builtins` which uses `#[naked]`, where `rustc` needs an updated `compiler-builtins` and vice versa. So based on https://github.com/rust-lang/rust/pull/139753 and [#t-compiler/help > updating &#96;compiler-builtins&#96; and &#96;rustc&#96;](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/updating.20.60compiler-builtins.60.20and.20.60rustc.60), this PR allows, but does not require `#[unsafe(naked)]`, and makes that change for some of the tests to check that both `#[naked]` and `#[unsafe(naked)]` are accepted. Then we can upgrade and synchronize `compiler-builtins`, and then make `#[naked]` (without `unsafe`) invalid. r? `@traviscross` (or someone from t-compiler if you're faster and this look allright)
2025-04-14Auto merge of #139577 - davidtwco:sizedness-go-vroom, r=oli-obkbors-24/+56
re-use `Sized` fast-path There's an existing fast path for the `type_op_prove_predicate` predicate, checking for trivially `Sized` types, which can be re-used when evaluating obligations within queries. This should improve performance and was found to be beneficial in #137944. r? types
2025-04-14Remove safe removeChris Denton-28/+6
2025-04-14Allow (but don't require) `#[unsafe(naked)]` so that `compiler-builtins` can ↵Folkert de Vries-0/+6
upgrade to it
2025-04-14Normalize ADT fields in find_tails_for_unsizingMichael Goulet-31/+32
2025-04-14Use `newtype_index!`-generated types more idiomaticallyYotam Ofek-87/+61
2025-04-14Rollup merge of #139777 - compiler-errors:debuggier-proj, r=lcnrMatthias Krüger-2/+2
Remove `define_debug_via_print` for `ExistentialProjection`, use regular structural debug impl The pretty print impl for `ExistentialProjection` always prints `AssocItem = Ty`: https://github.com/rust-lang/rust/blob/6e830462330a9e34d8176e86d4580dd0820c6fd5/compiler/rustc_middle/src/ty/print/pretty.rs#L3293-L3299 We can't change this, b/c it's used for both pretty printing dyn types and for legacy symbol mangling. Unfortunately, we also use this printing procedure for `Debug` impls. That means that it leaves out the *trait name* and *trait args* when debug printing an `ExistentialProjection` (or an `ExistentialPredicate` which has a variant for `ExistentialProjection`). This leads to awkward situations, like the two seemingly identical existential projection predicates present in a `dyn Trait` type using the definition below: ```rust trait Super { type Assoc; } trait Foo: Super<A, Assoc = i32> + Super<B, Assoc = i32> {} ``` Namely, they both just render as `Projection(Assoc = i32)`! This makes debugging `dyn Trait` type system bugs really hard, so let's use the *regular* debug impl for `ExistentialProjection`.
2025-04-14Rollup merge of #139767 - compiler-errors:www, r=oli-obkMatthias Krüger-19/+19
Visit place in `BackwardIncompatibleDropHint` statement Remove a weird hack from the `LocalUpdater` where we were manually visiting the place stored in a `StatementKind::BackwardIncompatibleDropHint` because the MIR visitor impls weren't doing so. Also, clean up `BackwardIncompatibleDropHint`s in `CleanupPostBorrowck`, since they're not needed for runtime MIR.
2025-04-14Rollup merge of #139392 - compiler-errors:raw-expr, r=oli-obkMatthias Krüger-1/+49
Detect and provide suggestion for `&raw EXPR` When emitting an error in the parser, and we detect that the previous token was `raw` and we *could* have consumed `const`/`mut`, suggest that this may have been a mistyped raw ref expr. To do this, we add `const`/`mut` to the expected token set when parsing `&raw` as an expression (which does not affect the "good path" of parsing, for the record). This is kind of a rudimentary error improvement, since it doesn't actually attempt to recover anything, leading to some other knock-on errors b/c we still treat `&raw` as the expression that was parsed... but at least we add the suggestion! I don't think the parser grammar means we can faithfully recover `&raw EXPR` early, i.e. during `parse_expr_borrow`. Fixes #133231
2025-04-14Rollup merge of #139127 - compiler-errors:prim-ty-hack, r=oli-obkMatthias Krüger-0/+5
Fix up partial res of segment in primitive resolution hack There is a hack in the resolver: ``` // In `a(::assoc_item)*` `a` cannot be a module. If `a` does resolve to a module we // don't report an error right away, but try to fallback to a primitive type. ``` This fixes up the resolution for primitives which would otherwise resolve to a module, but we weren't also updating the res of the path segment, leading to weird diagnostics. We explicitly call `self.r.partial_res_map.insert` instead of `record_partial_res` b/c we have recorded a partial res already, and we specifically want to override it. cc https://github.com/rust-lang/rust/issues/139095#issuecomment-2764371934
2025-04-14Remove define_debug_via_print for ExistentialProjectionMichael Goulet-2/+2
2025-04-14Derive Obligation's fold implsMichael Goulet-32/+7
2025-04-14Allow const patterns of matches to contain pattern typesOli Scherer-7/+36
2025-04-14Specify `--print info=file` syntax in `--help`clubby789-10/+4
2025-04-14normalize: prefer ParamEnv over AliasBoundlcnr-21/+30
2025-04-14do not leak auto traits in item boundslcnr-7/+25
2025-04-14drop global where-bounds before merging candidateslcnr-2/+6
2025-04-14Add unit tests for minimal_scc_representativeMatthew Jasper-0/+41
2025-04-14Auto merge of #139241 - bvanjoi:less-decoding, r=petrochenkovbors-64/+23
don't store opaque info during encoding Now `remapped_ctxts` reserved and let's check the performance. r? `@petrochenkov`
2025-04-14Handle regions equivalent to 'static in non_local_boundsMatthew Jasper-1/+16
`non_local_bounds` would only find non local bounds that strictly bound a given region, but it's possible that a local region is equated to 'static when showing a type referencing a locally bound lifetime, such as `dyn Any + 'a` in the tests added, is well-formed. In this case we should return 'static.
2025-04-14Share part of the global_asm!() implementation between cg_ssa and cg_clifbjorn3-138/+73
2025-04-14Use cg_ssa's version of codegen_naked_asm in cg_clifbjorn3-283/+258
2025-04-14Pass &mut self to codegen_global_asmbjorn3-11/+19
2025-04-14Make codegen_naked_asm publicbjorn3-2/+2
This allows it to be reused by codegen backends that don't use cg_ssa like cg_clif.
2025-04-14Pass MonoItemData to MonoItem::definebjorn3-14/+13
2025-04-14Move codegen_naked_asm call up into MonoItem::definebjorn3-8/+14
2025-04-14Make codegen_naked_asm retrieve the MIR Body itselfbjorn3-5/+6
2025-04-14Only require a CodegenCx for codegen_naked_asmbjorn3-9/+17
2025-04-14Don't begin defining a function when codegening a naked functionbjorn3-7/+7
While LLVM is rather permissive in this regards, some other codegen backends demand that once you declare a function for definition you actually define contents of the function, which doesn't happen for naked functions as we actually generate assembly for them.
2025-04-14Handle protected visibility in codegen_naked_asmbjorn3-4/+7
2025-04-14Use START_BLOCK in codegen_naked_asmbjorn3-2/+2
2025-04-14Auto merge of #139781 - jhpratt:rollup-qadsjvb, r=jhprattbors-692/+724
Rollup of 9 pull requests Successful merges: - #138336 (Improve `-Z crate-attr` diagnostics) - #139636 (Encode dep node edge count as u32 instead of usize) - #139666 (cleanup `mir_borrowck`) - #139695 (compiletest: consistently use `camino::{Utf8Path,Utf8PathBuf}` throughout) - #139699 (Proactively update coroutine drop shim's phase to account for later passes applied during shim query) - #139718 (enforce unsafe attributes in pre-2024 editions by default) - #139722 (Move some things to rustc_type_ir) - #139760 (UI tests: migrate remaining compile time `error-pattern`s to line annotations when possible) - #139776 (Switch attrs to `diagnostic::on_unimplemented`) r? `@ghost` `@rustbot` modify labels: rollup
2025-04-14Consistent with treating Ctor Call as Struct in liveness analysisxizheyin-1/+4
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-04-14Move `has_self` field to `hir::AssocKind::Fn`.Nicholas Nethercote-253/+259
`hir::AssocItem` currently has a boolean `fn_has_self_parameter` field, which is misplaced, because it's only relevant for associated fns, not for associated consts or types. This commit moves it (and renames it) to the `AssocKind::Fn` variant, where it belongs. This requires introducing a new C-style enum, `AssocTag`, which is like `AssocKind` but without the fields. This is because `AssocKind` values are passed to various functions like `find_by_ident_and_kind` to indicate what kind of associated item should be searched for, and having to specify `has_self` isn't relevant there. New methods: - Predicates `AssocItem::is_fn` and `AssocItem::is_method`. - `AssocItem::as_tag` which converts `AssocItem::kind` to `AssocTag`. Removed `find_by_name_and_kinds`, which is unused. `AssocItem::descr` can now distinguish between methods and associated functions, which slightly improves some error messages.
2025-04-14Use `Symbol` in `LateContext::get_associated_type`.Nicholas Nethercote-3/+8
To avoid unnecessary interning.