summary refs log tree commit diff
path: root/compiler
AgeCommit message (Collapse)AuthorLines
2024-10-11Disable jump threading UnOp::Not for non-boolMichael Goulet-0/+8
(cherry picked from commit f0bfba258330884df9c9d14a0aafd741ca9bbdc9)
2024-10-08Reject leading unsafe in `cfg!(...)` and `--check-cfg`.Urgau-2/+2
(cherry picked from commit 9cb540a13cb2249754ea3e755cb1472151d061db)
2024-10-08Only add an automatic SONAME for Rust dylibsJosh Stone-15/+70
(cherry picked from commit f46057bf1cc0dc24a0ecd7d87c9c93872e685253)
2024-09-26Don't call extern_crate when local crate name is the same as a dependency ↵Michael Goulet-0/+1
and we have a trait error (cherry picked from commit 9d5d03b7dec8a87c81528e9a1310313fa3f0111e)
2024-09-26Inline expected_inputs_for_expected_output into ↵Michael Goulet-77/+66
check_argument_types/check_expr_struct_fields (cherry picked from commit 95b9ecd6d671637e9e3db55ed31d06882d3cad4d)
2024-09-26Use equality when relating formal and expected type in arg checkingMichael Goulet-5/+4
(cherry picked from commit c3f9c4f4d4bbc83c7de79a09c7ec0e7fda8efc5e)
2024-09-19Check params for unsafety in THIRMichael Goulet-0/+14
(cherry picked from commit 12f2bcde63285bf2b2f9f9ac615d4edf139a3f0e)
2024-09-19Revert "Rollup merge of #129749 - krasimirgg:llvm-20-lto, r=nikic"Tyler Mandry-7/+3
This reverts commit 8c7a7e346be4cdf13e77ab4acbfb5ade819a4e60, reversing changes made to a00bd75b6c5c96d0a35afa2dc07ce3155112d278. (cherry picked from commit 472fef6a70d6621611a20f13f02c16be93589f5c)
2024-09-18Revert warning empty patterns as unreachableNadrieril-1/+5
(cherry picked from commit 5b7be148ea0128daad309cf5a123c868a65d7737)
2024-09-02replace placeholder versionBoxy-16/+16
2024-08-31Auto merge of #129831 - matthiaskrgr:rollup-befq6zx, r=matthiaskrgrbors-17/+7
Rollup of 11 pull requests Successful merges: - #128523 (Add release notes for 1.81.0) - #129605 (Add missing `needs-llvm-components` directives for run-make tests that need target-specific codegen) - #129650 (Clean up `library/profiler_builtins/build.rs`) - #129651 (skip stage 0 target check if `BOOTSTRAP_SKIP_TARGET_SANITY` is set) - #129684 (Enable Miri to pass pointers through FFI) - #129762 (Update the `wasm-component-ld` binary dependency) - #129782 (couple more crash tests) - #129816 (tidy: say which feature gate has a stability issue mismatch) - #129818 (make the const-unstable-in-stable error more clear) - #129824 (Fix code examples buttons not appearing on click on mobile) - #129826 (library: Fix typo in `core::mem`) r? `@ghost` `@rustbot` modify labels: rollup
2024-08-31Rollup merge of #129818 - RalfJung:const-stability, r=compiler-errorsMatthias Krüger-4/+3
make the const-unstable-in-stable error more clear The default should be to add `rustc_const_unstable`, not `rustc_allow_const_fn_unstable`. Also I discovered our check for missing const stability attributes on stable functions -- but strangely that check only kicks in for "reachable" functions. `check_missing_stability` checks for reachability since all reachable functions must have a stability attribute, but I would say if a function has `#[stable]` it should also have const-stability attributes regardless of reachability.
2024-08-31Rollup merge of #129762 - alexcrichton:update-wasm-component-ld, r=jieyouxuMatthias Krüger-1/+1
Update the `wasm-component-ld` binary dependency This keeps it up-to-date by moving from 0.5.6 to 0.5.7. While here I've additionally updated some other wasm-related dependencies in the workspace to keep them up-to-date and try to avoid duplicate versions as well.
2024-08-31Rollup merge of #129684 - Strophox:miri-pass-pointer-to-ffi, r=RalfJungMatthias Krüger-12/+3
Enable Miri to pass pointers through FFI Following https://github.com/rust-lang/rust/pull/126787, the purpose of this PR is to now enable Miri to execute native calls that make use of pointers. > <details> > > <summary> Simple example </summary> > > ```rust > extern "C" { > fn ptr_printer(ptr: *mut i32); > } > > fn main() { > let ptr = &mut 42 as *mut i32; > unsafe { > ptr_printer(ptr); > } > } > ``` > ```c > void ptr_printer(int *ptr) { > printf("printing pointer dereference from C: %d\n", *ptr); > } > ``` > should now show `printing pointer dereference from C: 42`. > > </details> Note that this PR does not yet implement any logic involved in updating Miri's "analysis" state (byte initialization, provenance) upon such a native call. r? ``@RalfJung``
2024-08-31don't take reachability into account when warning about missing-const-stabilityRalf Jung-2/+1
2024-08-31make the const-unstable-in-stable error more clearRalf Jung-2/+2
2024-08-31Rollup merge of #129812 - RalfJung:box-custom-alloc, r=compiler-errorsMatthias Krüger-6/+15
interpret, codegen: tweak some comments and checks regarding Box with custom allocator Cc https://github.com/rust-lang/rust/issues/95453
2024-08-31Rollup merge of #129767 - nnethercote:rm-extern-crate-tracing-4, r=jieyouxuMatthias Krüger-18/+211
Remove `#[macro_use] extern crate tracing`, round 4 Because explicit importing of macros via use items is nicer (more standard and readable) than implicit importing via #[macro_use]. Continuing the work from #124511, #124914, and #125434. After this PR no `rustc_*` crates use `#[macro_use] extern crate tracing` except for `rustc_codegen_gcc` which is a special case and I will do separately. r? ```@jieyouxu```
2024-08-31Rollup merge of #129749 - krasimirgg:llvm-20-lto, r=nikicMatthias Krüger-3/+7
llvm-wrapper: adapt for LLVM API changes No functional changes intended. Updates the wrapper for https://github.com/5c4lar/llvm-project/commit/21eddfac3d75879b3e0b09c5bc848526dcab6ab0. ````@rustbot```` label: +llvm-main r? ````@nikic````
2024-08-31Rollup merge of #129711 - lqd:nll-mir-dumps, r=compiler-errorsMatthias Krüger-64/+204
Expand NLL MIR dumps This PR is a first step to clean up and expand NLL MIR dumps: - by restoring the "mir-include-spans" comments which are useful for `-Zdump-mir=nll` - by adding the list of borrows to NLL MIR dumps, where they are introduced in the CFG and in which region Comments in MIR dumps were turned off in #112346, but as shown in #114652 they were still useful for us working with NLL MIR dumps. So this PR pulls `-Z mir-include-spans` into its own options struct, so that passes dumping MIR can override them if need be. The rest of the compiler is not affected, only the "nll" pass dumps have these comments enabled again. The CLI still has priority when specifying the flag, so that we can explicitly turn them off in the `mir-opt` tests to keep blessed dumps easier to work with (which was one of the points of #112346). Then, as part of a couple steps to improve NLL/polonius MIR dumps and `.dot` visualizations, I've also added the list of borrows and where they're introduced. I'm doing all this to help debug some polonius scope issues in my prototype location-sensitive analysis :3. I'll probably add member constraints soon.
2024-08-31Rollup merge of #129659 - RalfJung:const-fn-lang-feat, r=fee1-deadMatthias Krüger-7/+2
const fn stability checking: also check declared language features Fixes https://github.com/rust-lang/rust/issues/129656 `@oli-obk` I assume it is just an oversight that this didn't use `features().declared()`? Or is there a deep reason that this must only check `declared_lib_features`?
2024-08-31const fn stability checking: also check declared language featuresRalf Jung-7/+2
2024-08-31interpret, codegen: tweak some comments and checks regarding Box with custom ↵Ralf Jung-6/+15
allocator
2024-08-31Rollup merge of #129751 - RalfJung:interpret-visit-field-order, ↵Matthias Krüger-9/+10
r=compiler-errors interpret/visitor: make memory order iteration slightly more efficient Finally I know enough about RPIT to write this iterator signature correctly. :D This means memory-order iteration now needs an allocation, but it avoids quadratic complexity (where it has to do a linear scan n times to find the n-th field in memory order), so that seems like a win overall. The changed code only affects Miri; the rustc changes are NOPs.
2024-08-31Rollup merge of #129725 - compiler-errors:predicates-of, r=fmeaseMatthias Krüger-82/+96
Stop using `ty::GenericPredicates` for non-predicates_of queries `GenericPredicates` is a struct of several parts: A list of of an item's own predicates, and a parent def id (and some effects related stuff, but ignore that since it's kinda irrelevant). When instantiating these generic predicates, it calls `predicates_of` on the parent and instantiates its predicates, and appends the item's own instantiated predicates too: https://github.com/rust-lang/rust/blob/acb4e8b6251f1d8da36f08e7a70fa23fc581839e/compiler/rustc_middle/src/ty/generics.rs#L407-L413 Notice how this should result in a recursive set of calls to `predicates_of`... However, `GenericPredicates` is *also* misused by a bunch of *other* queries as a convenient way of passing around a list of predicates. For these queries, we don't ever set the parent def id of the `GenericPredicates`, but if we did, then this would be very easy to mistakenly call `predicates_of` instead of some other intended parent query. Given that footgun, and the fact that we don't ever even *use* the parent def id in the `GenericPredicates` returned from queries like `explicit_super_predicates_of`, It really has no benefit over just returning `&'tcx [(Clause<'tcx>, Span)]`. This PR additionally opts to wrap the results of `EarlyBinder`, as we've tended to use that in the return type of these kinds of queries to properly convey that the user has params to deal with, and it also gives a convenient way of iterating over a slice of things after instantiating.
2024-08-31Rollup merge of #129724 - nnethercote:rm-Option-bang, r=fee1-deadMatthias Krüger-66/+68
Remove `Option<!>` return types. Several compiler functions have `Option<!>` for their return type. That's odd. The only valid return value is `None`, so why is this type used? Because it lets you write certain patterns slightly more concisely. E.g. if you have these common patterns: ``` let Some(a) = f() else { return }; let Ok(b) = g() else { return }; ``` you can shorten them to these: ``` let a = f()?; let b = g().ok()?; ``` Huh. An `Option` return type typically designates success/failure. How should I interpret the type signature of a function that always returns (i.e. doesn't panic), does useful work (modifying `&mut` arguments), and yet only ever fails? This idiom subverts the type system for a cute syntactic trick. Furthermore, returning `Option<!>` from a function F makes things syntactically more convenient within F, but makes things worse at F's callsites. The callsites can themselves use `?` with F but should not, because they will get an unconditional early return, which is almost certainly not desirable. Instead the return value should be ignored. (Note that some of callsites of `process_operand`, `process_immedate`, `process_assign` actually do use `?`, though the early return doesn't matter in these cases because nothing of significance comes after those calls. Ugh.) When I first saw this pattern I had no idea how to interpret it, and it took me several minutes of close reading to understand everything I've written above. I even started a Zulip thread about it to make sure I understood it properly. "Save a few characters by introducing types so weird that compiler devs have to discuss it on Zulip" feels like a bad trade-off to me. This commit replaces all the `Option<!>` return values and uses `else`/`return` (or something similar) to replace the relevant `?` uses. The result is slightly more verbose but much easier to understand. r? ``````@cjgillot``````
2024-08-31Rollup merge of #129723 - compiler-errors:extern-providers, r=lcnrMatthias Krüger-43/+21
Simplify some extern providers Simplifies some extern crate providers: 1. Generalize the `ProcessQueryValue` identity impl to work on non-`Option` types. 2. Allow `ProcessQueryValue` to wrap its output in an `EarlyBinder`, to simplify `explicit_item_bounds`/`explicit_item_super_predicates`. 3. Use `{ table }` and friends more when possible.
2024-08-31Rollup merge of #129534 - workingjubilee:ratchet-wasm-c-abi-fcw-to-deny, ↵Matthias Krüger-1/+1
r=daxpedda,alexcrichton Deny `wasm_c_abi` lint to nudge the last 25% This shouldn't affect projects indirectly depending on wasm-bindgen because cargo passes `--cap-lints=allow` when building dependencies. The motivation is that the ecosystem has mostly taken up the versions of wasm-bindgen that are compatible in general, but ~25% or so of recent downloads remain on lower versions. However, this change might still be unnecessarily disruptive. I mostly propose it as a discussion point.
2024-08-31Rollup merge of #129527 - compiler-errors:lint-nit, r=NadrierilMatthias Krüger-20/+14
Don't use `TyKind` in a lint Allows us to remove an inherent method from `TyKind` from the type ir crate.
2024-08-31Rollup merge of #129366 - petrochenkov:libsearch, r=jieyouxuMatthias Krüger-61/+111
linker: Synchronize native library search in rustc and linker Also search for static libraries with alternative naming (`libname.a`) on MSVC when producing executables or dynamic libraries, and not just rlibs. This unblocks https://github.com/rust-lang/rust/pull/123436. try-job: x86_64-msvc
2024-08-31Rollup merge of #120221 - compiler-errors:statements-are-not-patterns, ↵Matthias Krüger-42/+46
r=nnethercote Don't make statement nonterminals match pattern nonterminals Right now, the heuristic we use to check if a token may begin a pattern nonterminal falls back to `may_be_ident`: https://github.com/rust-lang/rust/blob/ef71f1047e04438181d7cb925a833e2ada6ab390/compiler/rustc_parse/src/parser/nonterminal.rs#L21-L37 This has the unfortunate side effect that a `stmt` nonterminal eagerly matches against a `pat` nonterminal, leading to a parse error: ```rust macro_rules! m { ($pat:pat) => {}; ($stmt:stmt) => {}; } macro_rules! m2 { ($stmt:stmt) => { m! { $stmt } }; } m2! { let x = 1 } ``` This PR fixes it by more accurately reflecting the set of nonterminals that may begin a pattern nonterminal. As a side-effect, I modified `Token::can_begin_pattern` to work correctly and used that in `Parser::nonterminal_may_begin_with`.
2024-08-30enable Miri to pass const pointers through FFIStrophox-12/+3
Co-authored-by: Ralf Jung <post@ralfj.de>
2024-08-30Remove `#[macro_use] extern crate tracing` from `rustc_hir_typeck`.Nicholas Nethercote-3/+29
2024-08-30Remove `#[macro_use] extern crate tracing` from `rustc_trait_selection`.Nicholas Nethercote-3/+48
2024-08-30Remove `#[macro_use] extern crate tracing` from `rustc_hir_analysis`.Nicholas Nethercote-3/+31
2024-08-30Remove `#[macro_use] extern crate tracing` from `rustc_borrowck`.Nicholas Nethercote-3/+38
2024-08-30add borrows to NLL MIR dumpsRémy Rakic-1/+14
explicitly disable `-Zmir-include-spans` in mir-opt tests This will override the NLL default of true, and keep the blessed dumps easier to work with.
2024-08-30refactor NLL MIR dump entry pointRémy Rakic-15/+23
2024-08-30enable extra comments in NLL MIR dumpsRémy Rakic-21/+40
2024-08-30make `-Z mir-include-spans` a dedicated enumRémy Rakic-7/+44
We want to allow setting this on the CLI, override it only in MIR passes, and disable it altogether in mir-opt tests. The default value is "only for NLL MIR dumps", which is considered off for all intents and purposes, except for `rustc_borrowck` when an NLL MIR dump is requested.
2024-08-30introduce `PrettyPrintMirOptions` for cosmetic MIR dump optionsRémy Rakic-29/+92
initially starting with `-Z mir-include-spans` because we want them in the NLL mir dump pass
2024-08-30Remove `#[macro_use] extern crate tracing` from `rustc_infer`.Nicholas Nethercote-3/+26
2024-08-30Remove `#[macro_use] extern crate tracing` from `rustc_mir_transform`.Nicholas Nethercote-3/+39
2024-08-30Remove `Option<!>` return types.Nicholas Nethercote-66/+68
Several compiler functions have `Option<!>` for their return type. That's odd. The only valid return value is `None`, so why is this type used? Because it lets you write certain patterns slightly more concisely. E.g. if you have these common patterns: ``` let Some(a) = f() else { return }; let Ok(b) = g() else { return }; ``` you can shorten them to these: ``` let a = f()?; let b = g().ok()?; ``` Huh. An `Option` return type typically designates success/failure. How should I interpret the type signature of a function that always returns (i.e. doesn't panic), does useful work (modifying `&mut` arguments), and yet only ever fails? This idiom subverts the type system for a cute syntactic trick. Furthermore, returning `Option<!>` from a function F makes things syntactically more convenient within F, but makes things worse at F's callsites. The callsites can themselves use `?` with F but should not, because they will get an unconditional early return, which is almost certainly not desirable. Instead the return value should be ignored. (Note that some of callsites of `process_operand`, `process_immedate`, `process_assign` actually do use `?`, though the early return doesn't matter in these cases because nothing of significance comes after those calls. Ugh.) When I first saw this pattern I had no idea how to interpret it, and it took me several minutes of close reading to understand everything I've written above. I even started a Zulip thread about it to make sure I understood it properly. "Save a few characters by introducing types so weird that compiler devs have to discuss it on Zulip" feels like a bad trade-off to me. This commit replaces all the `Option<!>` return values and uses `else`/`return` (or something similar) to replace the relevant `?` uses. The result is slightly more verbose but much easier to understand.
2024-08-29Update the `wasm-component-ld` binary dependencyAlex Crichton-1/+1
This keeps it up-to-date by moving from 0.5.6 to 0.5.7. While here I've additionally updated some other wasm-related dependencies in the workspace to keep them up-to-date and try to avoid duplicate versions as well.
2024-08-29Auto merge of #129750 - GuillaumeGomez:rollup-gphsb7y, r=GuillaumeGomezbors-360/+508
Rollup of 7 pull requests Successful merges: - #123940 (debug-fmt-detail option) - #128166 (Improved `checked_isqrt` and `isqrt` methods) - #128970 (Add `-Zlint-llvm-ir`) - #129316 (riscv64imac: allow shadow call stack sanitizer) - #129690 (Add `needs-unwind` compiletest directive to `libtest-thread-limit` and replace some `Path` with `path` in `run-make`) - #129732 (Add `unreachable_pub`, round 3) - #129743 (Fix rustdoc clippy lints) r? `@ghost` `@rustbot` modify labels: rollup
2024-08-29Auto merge of #129714 - saethlin:half-a-recursion, r=compiler-errorsbors-1/+9
Use a reduced recursion limit in the MIR inliner's cycle breaker This probably papers over https://github.com/rust-lang/rust/issues/128887, but primarily I'm opening this PR because multiple compiler people have thought about making this change which probably means it's a good idea. r? compiler-errors
2024-08-29Simplify some extern providersMichael Goulet-43/+21
2024-08-29interpret/visitor: make memory order iteration slightly more efficientRalf Jung-9/+10
2024-08-29Rollup merge of #129732 - nnethercote:unreachable_pub-3, r=UrgauGuillaume Gomez-347/+403
Add `unreachable_pub`, round 3 A follow-up to #129648. r? `@Urgau`