about summary refs log tree commit diff
path: root/compiler/rustc_middle/src
AgeCommit message (Collapse)AuthorLines
2024-04-14Merge `WithNumNodes` into DirectedGraphMaybe Waffle-4/+2
2024-04-13Rollup merge of #123890 - klensy:cl, r=fee1-deadMatthias Krüger-45/+0
removed (mostly) unused code First commit removes unused code, second one - some old debug output, probably unused?
2024-04-13remove some ancient debug output, looks unused?klensy-15/+0
2024-04-12Rollup merge of #123834 - compiler-errors:async-closure-with-tainted-body, ↵Matthias Krüger-1/+1
r=oli-obk Don't do coroutine-closure-specific upvar analysis if tainted by errors See the comment Fixes #123821 Fixes #123818
2024-04-12Don't do coroutine-closure-specific upvar analysis if tainted by errorsMichael Goulet-1/+1
2024-04-12remove dead codeklensy-30/+0
2024-04-12Rollup merge of #123789 - klensy:rq, r=cjgillotMatthias Krüger-12/+0
move QueryKeyStringCache from rustc_middle to rustc_query_impl, where it actually used Also allows to drop measureme dep on rustc_middle.
2024-04-11Rollup merge of #123660 - compiler-errors:coroutine-closure-env, r=oli-obkMatthias Krüger-3/+71
Make the computation of `coroutine_captures_by_ref_ty` more sophisticated Currently, we treat all the by-(mut/)ref borrows of a coroutine-closure as having a "closure env" borrowed lifetime. When we have the given code: ```rust let x: &'a i32 = ...; let c = async || { let _x = *x; }; ``` Then when we call: ```rust c() // which, because `AsyncFn` takes a `&self`, we insert an autoref: (&c /* &'env {coroutine-closure} */)() ``` We will return a future whose captures contain `&'env i32` instead of `&'a i32`, which is way more restrictive than necessary. We should be able to drop `c` while the future is alive since it's not actually borrowing any data *originating from within* the closure's captures, but since the capture has that `'env` lifetime, this is not possible. This wouldn't be true, for example, if the closure captured `i32` instead of `&'a i32`, because the `'env` lifetime is actually *necessary* since the data (`i32`) is owned by the closure. This PR identifies two criteria where we *need* to take the borrow with the closure env lifetime: 1. If the closure borrows data from inside the closure's captures. This is not true if the parent capture is by-ref, OR if the parent capture is by-move and the child capture begins with a deref projection. This is the example described above. 2. If we're dealing with mutable references, since we cannot reborrow `&'env mut &'a mut i32` into `&'a mut i32`, *only* `&'env mut i32`. See the documentation on `should_reborrow_from_env_of_parent_coroutine_closure` for more info. **important:** As disclaimer states on that function, luckily, if this heuristic is not correct, then the program is not unsound, since we still borrowck and validate the choices made from this function -- the only side-effect is that the user may receive unnecessary borrowck errors. Fixes #123241
2024-04-11move QueryKeyStringCache from rustc_middle to rustc_query_impl, where it ↵klensy-12/+0
actually used also allows to drop measureme dep on rustc_middle
2024-04-11Auto merge of #123007 - kadiwa4:suggest_convert_ptr_to_mut_ref, r=estebankbors-13/+2
Rework ptr-to-ref conversion suggestion for method calls If we have a value `z` of type `*const u8` and try to call `z.to_string()`, the upstream compiler will show you a note suggesting to call `<*const u8>::as_ref` first. This PR extends that: - The note will only be shown when the method would exist on the corresponding reference type - It can now suggest any of `<*const u8>::as_ref`, `<*mut u8>::as_ref` and `<*mut u8>::as_mut`, depending on what the method needs. I didn't introduce a `help` message because that's not a good idea with `unsafe` functions (and you'd also need to unwrap the `Option<&_>` somehow). People should check the safety requirements. For the simplest case ```rust fn main() { let x = 8u8; let z: *const u8 = &x; // issue #21596 println!("{}", z.to_string()); //~ ERROR E0599 } ``` the output changes like this: ```diff error[E0599]: `*const u8` doesn't implement `std::fmt::Display` --> $DIR/suggest-convert-ptr-to-ref.rs:5:22 | LL | println!("{}", z.to_string()); | ^^^^^^^^^ `*const u8` cannot be formatted with the default formatter | - = note: try using `<*const T>::as_ref()` to get a reference to the type behind the pointer: https://doc.rust-lang.org/std/primitive.pointer.html#method.as_ref - = note: using `<*const T>::as_ref()` on a pointer which is unaligned or points to invalid or uninitialized memory is undefined behavior +note: the method `to_string` exists on the type `&u8` + --> $SRC_DIR/alloc/src/string.rs:LL:COL + = note: try using the unsafe method `<*const T>::as_ref` to get an optional reference to the value behind the pointer: https://doc.rust-lang.org/std/primitive.pointer.html#method.as_ref = note: the following trait bounds were not satisfied: `*const u8: std::fmt::Display` which is required by `*const u8: ToString` ``` I removed the separate note about the safety requirements because it was incomplete and the linked doc page already has the information you need. Fixes #83695, but that's more of a side effect. The upstream compiler already suggests the right method name here.
2024-04-11Auto merge of #122213 - estebank:issue-50195, r=oli-obk,estebankbors-0/+16
Provide suggestion to dereference closure tail if appropriate When encoutnering a case like ```rust use std::collections::HashMap; fn main() { let vs = vec![0, 0, 1, 1, 3, 4, 5, 6, 3, 3, 3]; let mut counts = HashMap::new(); for num in vs { let count = counts.entry(num).or_insert(0); *count += 1; } let _ = counts.iter().max_by_key(|(_, v)| v); ``` produce the following suggestion ``` error: lifetime may not live long enough --> $DIR/return-value-lifetime-error.rs:13:47 | LL | let _ = counts.iter().max_by_key(|(_, v)| v); | ------- ^ returning this value requires that `'1` must outlive `'2` | | | | | return type of closure is &'2 &i32 | has type `&'1 (&i32, &i32)` | help: dereference the return value | LL | let _ = counts.iter().max_by_key(|(_, v)| **v); | ++ ``` Fix #50195.
2024-04-10Use a helper to zip together parent and child captures for coroutine-closuresMichael Goulet-3/+71
2024-04-10introduce `Mutability::ptr_str`Kalle Wachsmuth-13/+2
2024-04-09Fix stage 2Michael Goulet-1/+1
2024-04-09Add redundant_lifetime_args lintMichael Goulet-8/+7
2024-04-09Rollup merge of #123662 - compiler-errors:no-upvars-yet, r=oli-obkGuillaume Gomez-1/+1
Don't rely on upvars being assigned just because coroutine-closure kind is assigned Previously, code relied on the implicit assumption that if a coroutine-closure's kind variable was constrained, then its upvars were also constrained. This is because we assign all of them at once at the end up upvar analysis. However, there's another way that a coroutine-closure's kind can be constrained: from a signature hint in closure signature deduction. After #123350, we use these hints, which means the implicit assumption above no longer holds. This PR adds the necessary checks so that we don't ICE. r? oli-obk
2024-04-09Auto merge of #123272 - saethlin:reachable-mono-cleanup, r=cjgillotbors-53/+95
Only collect mono items from reachable blocks Fixes the wrong comment pointed out in: https://github.com/rust-lang/rust/pull/121421#discussion_r1537378431 Moves the analysis to use the worklist strategy: https://github.com/rust-lang/rust/pull/121421#discussion_r1501840823 Also fixes https://github.com/rust-lang/rust/issues/85836, using the same reachability analysis
2024-04-09Auto merge of #123099 - oli-obk:span_tcx, r=petrochenkovbors-18/+26
Replace some `CrateStore` trait methods with hooks. Just like with the `CrateStore` trait, this avoids the cyclic definition issues with `CStore` being defined after TyCtxt, but needing to be used in TyCtxt.
2024-04-08Don't rely on upvars being assigned just because coroutine-closure kind is ↵Michael Goulet-1/+1
assigned
2024-04-08Auto merge of #122077 - oli-obk:eager_opaque_checks4, r=lcnrbors-47/+49
Pass list of defineable opaque types into canonical queries This eliminates `DefiningAnchor::Bubble` for good and brings the old solver closer to the new one wrt cycles and nested obligations. At that point the difference between `DefiningAnchor::Bind([])` and `DefiningAnchor::Error` was academic. We only used the difference for some sanity checks, which actually had to be worked around in places, so I just removed `DefiningAnchor` entirely and just stored the list of opaques that may be defined. fixes #108498 fixes https://github.com/rust-lang/rust/issues/116877 * [x] run crater - https://github.com/rust-lang/rust/pull/122077#issuecomment-2013293931
2024-04-08Auto merge of #123645 - matthiaskrgr:rollup-yd8d7f1, r=matthiaskrgrbors-1/+4
Rollup of 9 pull requests Successful merges: - #122781 (Fix argument ABI for overaligned structs on ppc64le) - #123367 (Safe Transmute: Compute transmutability from `rustc_target::abi::Layout`) - #123518 (Fix `ByMove` coroutine-closure shim (for 2021 precise closure capturing behavior)) - #123547 (bootstrap: remove unused pub fns) - #123564 (Don't emit divide-by-zero panic paths in `StepBy::len`) - #123578 (Restore `pred_known_to_hold_modulo_regions`) - #123591 (Remove unnecessary cast from `LLVMRustGetInstrProfIncrementIntrinsic`) - #123632 (parser: reduce visibility of unnecessary public `UnmatchedDelim`) - #123635 (CFI: Fix ICE in KCFI non-associated function pointers) r? `@ghost` `@rustbot` modify labels: rollup
2024-04-08Rollup merge of #123635 - maurer:kcfi-no-assoc, r=compiler-errorsMatthias Krüger-1/+4
CFI: Fix ICE in KCFI non-associated function pointers We oddly weren't testing the more usual case of casting non-methods to function pointers. The KCFI shim insertion logic would ICE on these due to asking for an irrefutable associated item if we cast a function to a function pointer without needing a traditional shim. r? `@compiler-errors`
2024-04-08Auto merge of #120614 - DianQK:simplify-switch-int, r=cjgillotbors-0/+6
Transforms match into an assignment statement Fixes #106459. We should be able to do some similar transformations, like `enum` to `enum`. r? mir-opt
2024-04-08CFI: Fix ICE in KCFI non-associated function pointersMatthew Maurer-1/+4
We oddly weren't testing the more usual case of casting non-methods to function pointers. The KCFI shim insertion logic would ICE on these due to asking for an irrefutable associated item if we cast a function to a function pointer without needing a traditional shim.
2024-04-08Ensure the canonical_param_env_cache does not contain inconsistent ↵Oli Scherer-5/+10
information about the defining anchor
2024-04-08Shrink the size of ClosureTypeInfo to fit into 64 bytes againOli Scherer-9/+25
2024-04-08Eliminate `DefiningAnchor` now that is just a single-variant enumOli Scherer-35/+18
2024-04-08Pass list of defineable opaque types into canonical queriesOli Scherer-20/+18
2024-04-08Actually create ranged int types in the type system.Oli Scherer-12/+211
2024-04-08Transforms match into an assignment statementDianQK-0/+6
2024-04-07Only collect mono items from reachable blocksBen Kimock-53/+95
2024-04-07Don't even parse an intrinsic unless the feature gate is enabledMichael Goulet-3/+8
2024-04-07Auto merge of #123058 - lukas-code:clauses, r=lcnrbors-103/+256
[perf] cache type info for ParamEnv This is an attempt to mitigate some of the perf regressions in https://github.com/rust-lang/rust/pull/122553#issuecomment-2007563027, but seems worth to test and land separately, since it is mostly unrelated to that PR.
2024-04-06add RawListLukas Markeffsky-255/+100
2024-04-06Put checks that detect UB under their own flag below debug_assertionsBen Kimock-5/+3
2024-04-05Provide suggestion to dereference closure tail if appropriateEsteban Küber-0/+16
When encoutnering a case like ```rust //@ run-rustfix use std::collections::HashMap; fn main() { let vs = vec![0, 0, 1, 1, 3, 4, 5, 6, 3, 3, 3]; let mut counts = HashMap::new(); for num in vs { let count = counts.entry(num).or_insert(0); *count += 1; } let _ = counts.iter().max_by_key(|(_, v)| v); ``` produce the following suggestion ``` error: lifetime may not live long enough --> $DIR/return-value-lifetime-error.rs:13:47 | LL | let _ = counts.iter().max_by_key(|(_, v)| v); | ------- ^ returning this value requires that `'1` must outlive `'2` | | | | | return type of closure is &'2 &i32 | has type `&'1 (&i32, &i32)` | help: dereference the return value | LL | let _ = counts.iter().max_by_key(|(_, v)| **v); | ++ ``` Fix #50195.
2024-04-05Fix typoWaffle Maybe-1/+1
2024-04-05Rollup merge of #123311 - Jules-Bertholet:andpat-everywhere, r=NadrierilGuillaume Gomez-0/+56
Match ergonomics: implement "`&`pat everywhere" Implements the eat-two-layers (feature gate `and_pat_everywhere`, all editions) ~and the eat-one-layer (feature gate `and_eat_one_layer_2024`, edition 2024 only, takes priority on that edition when both feature gates are active)~ (EDIT: will be done in later PR) semantics. cc #123076 r? ``@Nadrieril`` ``@rustbot`` label A-patterns A-edition-2024
2024-04-04Rollup merge of #123464 - fmease:rn-has-proj-to-has-aliases, r=compiler-errorsJacob Pratt-2/+2
Cleanup: Rename `HAS_PROJECTIONS` to `HAS_ALIASES` etc. The name of the bitflag `HAS_PROJECTIONS` and of its corresponding method `has_projections` is quite historical dating back to a time when projections were the only kind of alias type. I think it's time to update it to clear up any potential confusion for newcomers and to reduce unnecessary friction during contributor onboarding. r? types
2024-04-04Rollup merge of #123454 - petrochenkov:zeroindex2, r=fmeaseJacob Pratt-1/+1
hir: Use `ItemLocalId::ZERO` in a couple more places Follow up to https://github.com/rust-lang/rust/pull/123415 and https://github.com/rust-lang/rust/pull/123419.
2024-04-04Rollup merge of #123363 - lcnr:normalizes-to-zero-to-inf, r=BoxyUwUJacob Pratt-10/+5
change `NormalizesTo` to fully structurally normalize notes in https://hackmd.io/wZ016dE4QKGIhrOnHLlThQ need to also update the dev-guide once this PR lands. in short, the setup is now as follows: `normalizes-to` internally implements one step normalization, applying that normalization to the `goal.predicate.term` causes the projected term to get recursively normalized. With this `normalizes-to` normalizes until the projected term is rigid, meaning that we normalize as many steps necessary, but at least 1. To handle rigid aliases, we add another candidate only if the 1 to inf step normalization failed. With this `normalizes-to` is now full structural normalization. We can now change `AliasRelate` to simply emit `normalizes-to` goals for the rhs and lhs. This avoids the concerns from https://github.com/rust-lang/trait-system-refactor-initiative/issues/103 and generally feels cleaner
2024-04-04Auto merge of #123097 - oli-obk:perf_experiment, r=petrochenkovbors-11/+22
Try using a `dyn Debug` trait object instead of a closure These closures were introduced in https://github.com/rust-lang/rust/pull/93098 let's see if we can't use fmt::Arguments instead cc `@Aaron1011`
2024-04-04Rename HAS_PROJECTIONS to HAS_ALIASES etc.León Orell Valerian Liehr-2/+2
2024-04-04cache type info for ParamEnvLukas Markeffsky-67/+375
2024-04-04Rollup merge of #123439 - Zalathar:constants, r=oli-obkMatthias Krüger-8/+0
coverage: Remove useless constants After #122972 and #123419, these constants don't serve any useful purpose, so get rid of them. `@rustbot` label +A-code-coverage
2024-04-04hir: Use `ItemLocalId` in a couple more placesVadim Petrochenkov-1/+1
2024-04-04normalizes-to change from '1' to '0 to inf' stepslcnr-10/+5
2024-04-04Auto merge of #123052 - maurer:addr-taken, r=compiler-errorsbors-10/+61
CFI: Support function pointers for trait methods Adds support for both CFI and KCFI for function pointers to trait methods by attaching both concrete and abstract types to functions. KCFI does this through generation of a `ReifyShim` on any function pointer for a method that could go into a vtable, and keeping this separate from `ReifyShim`s that are *intended* for vtable us by setting a `ReifyReason` on them. CFI does this by setting both the concrete and abstract type on every instance. This should land after #123024 or a similar PR, as it diverges the implementation of CFI vs KCFI. r? `@compiler-errors`
2024-04-04Auto merge of #123440 - jhpratt:rollup-yat6crk, r=jhprattbors-16/+16
Rollup of 4 pull requests Successful merges: - #122356 (std::rand: fix dragonflybsd after #121942.) - #123093 (Add a nice header to our README.md) - #123307 (Fix f16 and f128 feature gating on different editions) - #123401 (Check `x86_64` size assertions on `aarch64`, too) r? `@ghost` `@rustbot` modify labels: rollup
2024-04-03Rollup merge of #123401 - Zalathar:assert-size-aarch64, r=fmeaseJacob Pratt-16/+16
Check `x86_64` size assertions on `aarch64`, too (Context: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Checking.20size.20assertions.20on.20aarch64.3F) Currently the compiler has around 30 sets of `static_assert_size!` for various size-critical data structures (e.g. various IR nodes), guarded by `#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]`. (Presumably this cfg avoids having to maintain separate size values for 32-bit targets and unusual 64-bit targets. Apparently it may have been necessary before the i128/u128 alignment changes, too.) This is slightly incovenient for people on aarch64 workstations (e.g. Macs), because the assertions normally aren't checked until we push to a PR. So this PR adds `aarch64` to the `#[cfg(..)]` guarding all of those assertions in the compiler. --- Implemented with a simple find/replace. Verified by manually inspecting each `static_assert_size!` in `compiler/`, and checking that either the replacement succeeded, or adding aarch64 wouldn't have been appropriate.