about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/ty
AgeCommit message (Collapse)AuthorLines
2024-04-26Auto merge of #120845 - petrochenkov:debmac, r=oli-obkbors-17/+1
debuginfo: Stabilize `-Z debug-macros`, `-Z collapse-macro-debuginfo` and `#[collapse_debuginfo]` `-Z debug-macros` is "stabilized" by enabling it by default and removing. `-Z collapse-macro-debuginfo` is stabilized as `-C collapse-macro-debuginfo`. It now supports all typical boolean values (`parse_opt_bool`) in addition to just yes/no. Default value of `collapse_debuginfo` was changed from `false` to `external` (i.e. collapsed if external, not collapsed if local) - https://github.com/rust-lang/rust/issues/100758#issuecomment-1935815625 describes some debugging scenarios that motivate this default as reasonable. `#[collapse_debuginfo]` attribute without a value is no longer supported to avoid guessing the default. Stabilization report: https://github.com/rust-lang/rust/pull/120845#issuecomment-1939145242 Closes https://github.com/rust-lang/rust/issues/100758 Closes https://github.com/rust-lang/rust/issues/41743 Closes https://github.com/rust-lang/rust/issues/39153
2024-04-25Rollup merge of #124379 - compiler-errors:remove-new-solver-lookup-behavior, ↵Michael Goulet-56/+9
r=lcnr Remove special-casing for `SimplifiedType` for next solver It's unnecessary due to the way that we fully normalize the self type before assembly begins. r? lcnr
2024-04-25debuginfo: Stabilize `-Z debug-macros`, `-Z collapse-macro-debuginfo` and ↵Vadim Petrochenkov-17/+1
`#[collapse_debuginfo]` `-Z debug-macros` is "stabilized" by enabling it by default and removing. `-Z collapse-macro-debuginfo` is stabilized as `-C collapse-macro-debuginfo`. It now supports all typical boolean values (`parse_opt_bool`) in addition to just yes/no. Default value of `collapse_debuginfo` was changed from `false` to `external` (i.e. collapsed if external, not collapsed if local). `#[collapse_debuginfo]` attribute without a value is no longer supported to avoid guessing the default.
2024-04-25Remove special-casing for SimplifiedType for next solverMichael Goulet-56/+9
2024-04-24Auto merge of #122500 - petrochenkov:deleg, r=fmeasebors-3/+10
delegation: Support renaming, and async, const, extern "ABI" and C-variadic functions Also allow delegating to functions with opaque types (`impl Trait`). The delegation item will refer to the original opaque type from the callee, fresh opaque type won't be created, which seems like a reasonable behavior. (Such delegation items will cause query cycles when used in trait impls, but it can be fixed later.) Part of https://github.com/rust-lang/rust/issues/118212.
2024-04-24Error on using `yield` without also using `#[coroutine]` on the closureOli Scherer-52/+59
And suggest adding the `#[coroutine]` to the closure
2024-04-23Auto merge of #123126 - oli-obk:feed_crate_num, r=davidtwcobors-8/+19
Enable `CrateNum` query feeding via `TyCtxt` Instead of having a magic function that violates some `TyCtxtFeed` invariants, add a `create_def` equivalent for `CrateNum`s. Note that this still isn't tracked by the query system (unlike `create_def`), and that feeding most `CrateNum` queries for crates other than the local one will likely cause performance regressions. These things should be attempted on their own separately, but this PR should stand on its own
2024-04-23delegation: Support async, const, extern "ABI" and C-variadic functionsVadim Petrochenkov-3/+10
Also allow `impl Trait` in delegated functions. The delegation item will refer to the original opaque type from the callee, fresh opaque type won't be created.
2024-04-23Rollup merge of #123993 - compiler-errors:coroutine-obl, r=lcnrLeón Orell Valerian Liehr-7/+4
Do `check_coroutine_obligations` once per typeck root We only need to do `check_coroutine_obligations` once per typeck root, especially since the new solver can't really (easily) associate which obligations correspond to which coroutines. This requires us to move the checks for sized coroutine fields into `mir_coroutine_witnesses`, but that's fine imo. r? lcnr
2024-04-23Rollup merge of #122598 - Nadrieril:full-derefpats, r=matthewjasperLeón Orell Valerian Liehr-1/+1
deref patterns: lower deref patterns to MIR This lowers deref patterns to MIR. This is a bit tricky because this is the first kind of pattern that requires storing a value in a temporary. Thanks to https://github.com/rust-lang/rust/pull/123324 false edges are no longer a problem. The thing I'm not confident about is the handling of fake borrows. This PR ignores any fake borrows inside a deref pattern. We are guaranteed to at least fake borrow the place of the first pointer value, which could be enough, but I'm not certain.
2024-04-23Rollup merge of #120929 - long-long-float:wrap-dyn-in-suggestion, r=fmeaseLeón Orell Valerian Liehr-17/+22
Wrap dyn type with parentheses in suggestion Close #120223 Fix wrong suggestion that is grammatically incorrect. Specifically, I added parentheses to dyn types that need lifetime bound. ``` help: consider adding an explicit lifetime bound | 4 | executor: impl FnOnce(T) -> (dyn Future<Output = ()>) + 'static, | + +++++++++++ ```
2024-04-23Auto merge of #124277 - matthiaskrgr:rollup-zdb93i4, r=matthiaskrgrbors-0/+4
Rollup of 7 pull requests Successful merges: - #123680 (Deny gen keyword in `edition_2024_compat` lints) - #124057 (Fix ICE when ADT tail has type error) - #124168 (Use `DefiningOpaqueTypes::Yes` in rustdoc, where the `InferCtxt` is guaranteed to have no opaque types it can define) - #124197 (Move duplicated code in functions in `tests/rustdoc-gui/notable-trait.goml`) - #124200 (Improve handling of expr->field errors) - #124220 (Miri: detect wrong vtables in wide pointers) - #124266 (remove an unused type from the reentrant lock tests) r? `@ghost` `@rustbot` modify labels: rollup
2024-04-23Rollup merge of #124057 - gurry:124031-ice-layout-errored, r=compiler-errorsMatthias Krüger-0/+4
Fix ICE when ADT tail has type error Fixes #124031
2024-04-23Auto merge of #123992 - compiler-errors:no-has-typeck-results, r=jackh726bors-0/+11
`has_typeck_results` doesnt need to be a query self-explanatory
2024-04-23Auto merge of #121801 - zetanumbers:async_drop_glue, r=oli-obkbors-7/+248
Add simple async drop glue generation This is a prototype of the async drop glue generation for some simple types. Async drop glue is intended to behave very similar to the regular drop glue except for being asynchronous. Currently it does not execute synchronous drops but only calls user implementations of `AsyncDrop::async_drop` associative function and awaits the returned future. It is not complete as it only recurses into arrays, slices, tuples, and structs and does not have same sensible restrictions as the old `Drop` trait implementation like having the same bounds as the type definition, while code assumes their existence (requires a future work). This current design uses a workaround as it does not create any custom async destructor state machine types for ADTs, but instead uses types defined in the std library called future combinators (deferred_async_drop, chain, ready_unit). Also I recommend reading my [explainer](https://zetanumbers.github.io/book/async-drop-design.html). This is a part of the [MCP: Low level components for async drop](https://github.com/rust-lang/compiler-team/issues/727) work. Feature completeness: - [x] `AsyncDrop` trait - [ ] `async_drop_in_place_raw`/async drop glue generation support for - [x] Trivially destructible types (integers, bools, floats, string slices, pointers, references, etc.) - [x] Arrays and slices (array pointer is unsized into slice pointer) - [x] ADTs (enums, structs, unions) - [x] tuple-like types (tuples, closures) - [ ] Dynamic types (`dyn Trait`, see explainer's [proposed design](https://github.com/zetanumbers/posts/blob/main/async-drop-design.md#async-drop-glue-for-dyn-trait)) - [ ] coroutines (https://github.com/rust-lang/rust/pull/123948) - [x] Async drop glue includes sync drop glue code - [x] Cleanup branch generation for `async_drop_in_place_raw` - [ ] Union rejects non-trivially async destructible fields - [ ] `AsyncDrop` implementation requires same bounds as type definition - [ ] Skip trivially destructible fields (optimization) - [ ] New [`TyKind::AdtAsyncDestructor`](https://github.com/zetanumbers/posts/blob/main/async-drop-design.md#adt-async-destructor-types) and get rid of combinators - [ ] [Synchronously undroppable types](https://github.com/zetanumbers/posts/blob/main/async-drop-design.md#exclusively-async-drop) - [ ] Automatic async drop at the end of the scope in async context
2024-04-22Rollup merge of #124183 - compiler-errors:unnecessary-by-ref, r=oli-obkGuillaume Gomez-11/+11
Stop taking `ParamTy`/`ParamConst`/`EarlyParamRegion`/`AliasTy` by ref It's unnecessary and is annoying when we have it by value.
2024-04-23Wrap dyn type with parentheses in suggestionlong-long-float-17/+22
2024-04-22Fix typo in the has_surface_drop's doc commentDaria Sukhonina-1/+1
Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
2024-04-22Fix ICE when ADT tail has type errorGurinder Singh-0/+4
2024-04-20Address closure-related reviewNadrieril-1/+1
2024-04-20Rollup merge of #123409 - ZhuUx:master, r=oli-obkMatthias Krüger-0/+1
Implement Modified Condition/Decision Coverage This is an implementation based on llvm backend support (>= 18) by `@evodius96` and branch coverage support by `@Zalathar.` ### Major changes: * Add -Zcoverage-options=mcdc as switch. Now coverage options accept either `no-branch`, `branch`, or `mcdc`. `mcdc` also enables `branch` because it is essential to work. * Add coverage mapping for MCDCBranch and MCDCDecision. Note that MCDCParameter evolves from llvm 18 to llvm 19. The mapping in rust side mainly references to 19 and is casted to 18 types in llvm wrapper. * Add wrapper for mcdc instrinc functions from llvm. And inject associated statements to mir. * Add BcbMappingKind::Decision, I'm not sure is it proper but can't find a better way temporarily. * Let coverage-dump support parsing MCDCBranch and MCDCDecision from llvm ir. * Add simple tests to check whether mcdc works. * Same as clang, currently rustc does not generate instrument for decision with more than 6 condtions or only 1 condition due to considerations of resource. ### Implementation Details 1. To get information about conditions and decisions, `MCDCState` in `BranchInfoBuilder` is used during hir lowering to mir. For expressions with logical op we call `Builder::visit_coverage_branch_operation` to record its sub conditions, generate condition ids for them and save their spans (to construct the span of whole decision). This process mainly references to the implementation in clang and is described in comments over `MCDCState::record_conditions`. Also true marks and false marks introduced by branch coverage are used to detect where the decision evaluation ends: the next id of the condition == 0. 2. Once the `MCDCState::decision_stack` popped all recorded conditions, we can ensure that the decision is checked over and push it into `decision_spans`. We do not manually insert decision span to avoid complexity from then_else_break in nested if scopes. 3. When constructing CoverageSpans, add condition info to BcbMappingKind::Branch and decision info to BcbMappingKind::Decision. If the branch mapping has non-zero condition id it will be transformed to MCDCBranch mapping and insert `CondBitmapUpdate` statements to its evaluated blocks. While decision bcb mapping will insert `TestVectorBitmapUpdate` in all its end blocks. ### Usage ```bash echo "[build]\nprofiler=true" >> config.toml ./x build --stage 1 ./x test tests/coverage/mcdc_if.rs ``` to build the compiler and run tests. ```shell export PATH=path/to/llvm-build:$PATH rustup toolchain link mcdc build/host/stage1 cargo +mcdc rustc --bin foo -- -Cinstrument-coverage -Zcoverage-options=mcdc cd target/debug LLVM_PROFILE_FILE="foo.profraw" ./foo llvm-profdata merge -sparse foo.profraw -o foo.profdata llvm-cov show ./foo -instr-profile=foo.profdata --show-mcdc ``` to check "foo" code. ### Problems to solve For now decision mapping will insert statements to its all end blocks, which may be optimized by inserting a final block of the decision. To do this we must also trace the evaluated value at each end of the decision and join them separately. This implementation is not heavily tested so there should be some unrevealed issues. We are going to check our rust products in the next. Please let me know if you had any suggestions or comments.
2024-04-19Stop taking ParamTy/ParamConst/EarlyParamRegion/AliasTy by refMichael Goulet-11/+11
2024-04-19Auto merge of #124113 - RalfJung:interpret-scalar-ops, r=oli-obkbors-38/+64
interpret: use ScalarInt for bin-ops; avoid PartialOrd for ScalarInt Best reviewed commit-by-commit r? `@oli-obk`
2024-04-19avoid PartialOrd on ScalarIntRalf Jung-2/+2
we don't know their sign so we cannot, in general, order them properly
2024-04-19Remove `feed_local_crate` in favor of creating the `CrateNum` via `TyCtxt`Oli Scherer-7/+0
2024-04-19Prepare for `CrateNum` query feeding on creationOli Scherer-2/+5
2024-04-19Isolate `CrateNum` creation to `TyCtxt` methodsOli Scherer-0/+10
2024-04-19Move `stable_crate_ids` from `CrateStore` to `Untracked`Oli Scherer-1/+6
This way it's like `Definitions`, which creates `DefId`s by interning `DefPathData`s, but for interning stable crate hashes
2024-04-19ScalarInt: add methods to assert being a (u)int of given sizeRalf Jung-29/+40
2024-04-19coverage. Generate Mappings of decisions and conditions for MC/DCzhuyunxing-0/+1
2024-04-19Auto merge of #117919 - daxpedda:wasm-c-abi, r=wesleywiserbors-1/+15
Introduce perma-unstable `wasm-c-abi` flag Now that `wasm-bindgen` v0.2.88 supports the spec-compliant C ABI, the idea is to switch to that in a future version of Rust. In the meantime it would be good to let people test and play around with it. This PR introduces a new perma-unstable `-Zwasm-c-abi` compiler flag, which switches to the new spec-compliant C ABI when targeting `wasm32-unknown-unknown`. Alternatively, we could also stabilize this and then deprecate it when we switch. I will leave this to the Rust maintainers to decide. This is a companion PR to #117918, but they could be merged independently. MCP: https://github.com/rust-lang/compiler-team/issues/703 Tracking issue: https://github.com/rust-lang/rust/issues/122532
2024-04-18interpret/binary_int_op: avoid dropping to raw ints until we determined the signRalf Jung-8/+23
2024-04-18Fix disabling the export of noop async_drop_in_place_rawDaria Sukhonina-2/+4
2024-04-18Auto merge of #124008 - nnethercote:simpler-static_assert_size, r=Nilstriebbors-7/+7
Simplify `static_assert_size`s. We want to run them on all 64-bit platforms. r? `@ghost`
2024-04-18Simplify `static_assert_size`s.Nicholas Nethercote-7/+7
We want to run them on all 64-bit platforms.
2024-04-17has_typeck_results doesnt need to be a queryMichael Goulet-0/+11
2024-04-17Use non-exhaustive matches for TyKindDaria Sukhonina-91/+74
Also no longer export noop async_drop_in_place_raw
2024-04-17Rename `BindingAnnotation` to `BindingMode`Jules Bertholet-12/+7
2024-04-16Add simple async drop glue generationzetanumbers-7/+263
Explainer: https://zetanumbers.github.io/book/async-drop-design.html https://github.com/rust-lang/rust/pull/121801
2024-04-16Avoid lots of `hir::HirId{,Map,Set}` qualifiers.Nicholas Nethercote-31/+29
Because they're a bit redundant.
2024-04-15Do check_coroutine_obligations once per typeck rootMichael Goulet-6/+3
2024-04-15Rename coroutine_stalled_predicatesMichael Goulet-2/+2
2024-04-16Rollup merge of #123603 - compiler-errors:no-intrinsic, r=estebankLeón Orell Valerian Liehr-3/+8
Don't even parse an intrinsic unless the feature gate is enabled Don't return true in `tcx.is_intrinsic` if the function is defined locally and `#![feature(intrinsics)]` is not enabled. This is a slightly more general fix than #123526, since #123587 shows that we have simplifying assumptions about intrinsics elsewhere in the compiler. This will make the code ICE again if the user **enables** `#[feature(intrinsics)]`, but I kind of feel like if we want to fix that, we should make the `INTERNAL_FEATURES` lint `Deny` again. Perhaps we could do that on non-nightly compilers. Or we should just stop compilation altogether if they have `#![feature]` enabled on a non-nightly compiler. As for the UX of *real* cases of hitting these ICEs, I believe pretty strongly that if a compiler/stdlib dev is modifying internal intrinsics (intentionally, like when making a change to rustc) we have no guarantee to make the ICE better looking for them. Honestly, *not* spitting out a stack trace is probably a disservice to the people who hit those ICEs in that case. r? `@Nilstrieb` `@estebank`
2024-04-12Don't do coroutine-closure-specific upvar analysis if tainted by errorsMichael Goulet-1/+1
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-11Auto merge of #123007 - kadiwa4:suggest_convert_ptr_to_mut_ref, r=estebankbors-7/+1
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-10Use a helper to zip together parent and child captures for coroutine-closuresMichael Goulet-3/+71
2024-04-10introduce `Mutability::ptr_str`Kalle Wachsmuth-7/+1
2024-04-09Fix stage 2Michael Goulet-1/+1
2024-04-09Add redundant_lifetime_args lintMichael Goulet-8/+7