about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection
AgeCommit message (Collapse)AuthorLines
2024-04-26Auto merge of #122385 - lcnr:analyze-obligations-for-infer, r=compiler-errorsbors-238/+421
`obligations_for_self_ty`: use `ProofTreeVisitor` for nested goals As always, dealing with proof trees continues to be a hacked together mess. After this PR and #124380 the only remaining blocker for core is https://github.com/rust-lang/trait-system-refactor-initiative/issues/90. There is also a `ProofTreeVisitor` issue causing an ICE when compiling `alloc` which I will handle in a separate PR. This issue likely affects coherence diagnostics more generally. The core idea is to extend the proof tree visitor to support visiting nested candidates without using a `probe`. We then simply recurse into nested candidates if they are the only potentially applicable candidate for a given goal and check whether the self type matches the expected one. For that to work, we need to improve `CanonicalState` to also handle unconstrained inference variables created inside of the trait solver. This is done by extending the `var_values` of `CanoncalState` with each fresh inference variables. Furthermore, we also store the state of all inference variables at the end of each probe. When recursing into `InspectCandidates` we then unify the values of all these states. r? `@compiler-errors`
2024-04-25Rollup merge of #124381 - compiler-errors:derived-for-wf, r=lcnrMichael Goulet-4/+4
Renamed `DerivedObligation` to `WellFormedDeriveObligation` It's used when computing `WellFormed` obligations, so let's give it a less ambiguous name.
2024-04-25Rollup merge of #124379 - compiler-errors:remove-new-solver-lookup-behavior, ↵Michael Goulet-7/+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-25Renamed DerivedObligation to WellFormedDeriveObligationMichael Goulet-4/+4
2024-04-25use `EagerResolver`lcnr-1/+3
2024-04-25hir typeck: look into nested goalslcnr-237/+418
uses a `ProofTreeVisitor` to look into nested goals when looking at the pending obligations during hir typeck. Used by closure signature inference, coercion, and for async functions.
2024-04-25Remove special-casing for SimplifiedType for next solverMichael Goulet-7/+9
2024-04-24Suggest cloning captured binding in `move` closureEsteban Küber-1/+10
``` error[E0507]: cannot move out of `bar`, a captured variable in an `FnMut` closure --> $DIR/borrowck-move-by-capture.rs:9:29 | LL | let bar: Box<_> = Box::new(3); | --- captured outer variable LL | let _g = to_fn_mut(|| { | -- captured by this `FnMut` closure LL | let _h = to_fn_once(move || -> isize { *bar }); | ^^^^^^^^^^^^^^^^ ---- | | | | | variable moved due to use in closure | | move occurs because `bar` has type `Box<isize>`, which does not implement the `Copy` trait | `bar` is moved here | help: clone the value before moving it into the closure | LL ~ let value = bar.clone(); LL ~ let _h = to_fn_once(move || -> isize { value }); | ```
2024-04-24Modify `find_expr` from `Span` to better account for closuresEsteban Küber-6/+13
Start pointing to where bindings were declared when they are captured in closures: ``` error[E0597]: `x` does not live long enough --> $DIR/suggest-return-closure.rs:23:9 | LL | let x = String::new(); | - binding `x` declared here ... LL | |c| { | --- value captured here LL | x.push(c); | ^ borrowed value does not live long enough ... LL | } | -- borrow later used here | | | `x` dropped here while still borrowed ``` Suggest cloning in more cases involving closures: ``` error[E0507]: cannot move out of `foo` in pattern guard --> $DIR/issue-27282-move-ref-mut-into-guard.rs:11:19 | LL | if { (|| { let mut bar = foo; bar.take() })(); false } => {}, | ^^ --- move occurs because `foo` has type `&mut Option<&i32>`, which does not implement the `Copy` trait | | | `foo` is moved here | = note: variables bound in patterns cannot be moved from until after the end of the pattern guard help: consider cloning the value if the performance cost is acceptable | LL | if { (|| { let mut bar = foo.clone(); bar.take() })(); false } => {}, | ++++++++ ```
2024-04-23Rollup merge of #124218 - Xiretza:subsubdiagnostics, r=davidtwcoLeón Orell Valerian Liehr-1/+1
Allow nesting subdiagnostics in #[derive(Subdiagnostic)]
2024-04-23Rollup merge of #120929 - long-long-float:wrap-dyn-in-suggestion, r=fmeaseLeón Orell Valerian Liehr-8/+19
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-23Rollup merge of #124168 - oli-obk:define_opaque_types12, r=lcnrMatthias Krüger-1/+1
Use `DefiningOpaqueTypes::Yes` in rustdoc, where the `InferCtxt` is guaranteed to have no opaque types it can define r? `@lcnr` I manually checked there it's always `tcx.infer_ctxt().build()`
2024-04-23Auto merge of #121801 - zetanumbers:async_drop_glue, r=oli-obkbors-1/+117
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-6/+6
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-8/+19
2024-04-22Use `DefiningOpaqueTypes::Yes`, as the `InferCtxt` we use has no opaque ↵Oli Scherer-1/+1
types it may define
2024-04-22Fix copy-paste typo in the comment within ↵Daria Sukhonina-2/+2
consider_builtin_async_destruct_candidate
2024-04-22Exhaustivelly match TyKind in consider_builtin_async_destruct_candidateDaria Sukhonina-1/+1
2024-04-21Pass translation closure to add_to_diag_with() as referenceXiretza-1/+1
2024-04-20merge two impl blocksLukas Markeffsky-2/+0
2024-04-20remove `InferCtxt::clear_caches`Lukas Markeffsky-3/+0
2024-04-20include ParamEnv in projection cache keyLukas Markeffsky-11/+16
2024-04-19Stop taking ParamTy/ParamConst/EarlyParamRegion/AliasTy by refMichael Goulet-6/+6
2024-04-19Let inherent associated types constrain opaque types during projectionOli Scherer-1/+1
2024-04-18Auto merge of #124008 - nnethercote:simpler-static_assert_size, r=Nilstriebbors-2/+2
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-2/+2
We want to run them on all 64-bit platforms.
2024-04-17Use non-exhaustive matches for TyKindDaria Sukhonina-8/+8
Also no longer export noop async_drop_in_place_raw
2024-04-17Rename `BindingAnnotation` to `BindingMode`Jules Bertholet-3/+1
2024-04-17Rollup merge of #122813 - nnethercote:nicer-quals, r=compiler-errorsMatthias Krüger-7/+6
Qualifier tweaking Adding and removing qualifiers in some cases that make things nicer. Details in individual commits. r? `@compiler-errors`
2024-04-17Auto merge of #124040 - GuillaumeGomez:rollup-hrrvsgh, r=GuillaumeGomezbors-4/+14
Rollup of 7 pull requests Successful merges: - #123673 (Don't ICE for kind mismatches during error rendering) - #123675 (Taint const qualifs if a static is referenced that didn't pass wfcheck) - #123975 (Port the 2 `rust-lld` run-make tests to `rmake`) - #124000 (Use `/* value */` as a placeholder) - #124013 (Box::into_raw: make Miri understand that this is a box-to-raw cast) - #124027 (Prefer identity equality over equating types during coercion.) - #124036 (Remove `default_hidden_visibility: false` from wasm targets) r? `@ghost` `@rustbot` modify labels: rollup
2024-04-17Rollup merge of #124000 - compiler-errors:sugg-tweaks, r=wesleywiserGuillaume Gomez-4/+11
Use `/* value */` as a placeholder The expression `value` isn't a valid suggestion; let's use `/* value */` as a placeholder (which is also invalid) since it more clearly signals to the user that they need to fill it in with something meaningful. This parallels the suggestions we have in a couple other places, like arguments. We could also print the type name instead of `/* value */`, especially if it's suggestable, but I don't care strongly about that.
2024-04-17Rollup merge of #123673 - oli-obk:sig_wfcheck_ice, r=jieyouxu,estebankGuillaume Gomez-0/+3
Don't ICE for kind mismatches during error rendering fixes #123457 also some test suite cleanups to make backtraces easier to read
2024-04-16Auto merge of #123537 - compiler-errors:shallow, r=lcnrbors-17/+16
Simplify shallow resolver to just fold ty/consts Probably faster than using a whole folder?
2024-04-16Add simple async drop glue generationzetanumbers-1/+117
Explainer: https://zetanumbers.github.io/book/async-drop-design.html https://github.com/rust-lang/rust/pull/121801
2024-04-16Don't ICE for kind mismatches during error renderingOli Scherer-0/+3
2024-04-16Fail candidate assembly for erroneous typesGurinder Singh-1/+12
Trait predicates for types which have errors may still evaluate to OK leading to downstream ICEs. Now we return a selection error for such types in candidate assembly and thereby prevent such issues
2024-04-16Avoid lots of `hir::HirId{,Map,Set}` qualifiers.Nicholas Nethercote-2/+2
Because they're a bit redundant.
2024-04-16Avoid unnecessary `rustc_span::DUMMY_SP` usage.Nicholas Nethercote-5/+4
In some cases `DUMMY_SP` is already imported. In other cases this commit adds the necessary import, in files where `DUMMY_SP` is used more than once.
2024-04-15Make array suggestions slightly more accurateMichael Goulet-3/+10
2024-04-15Use /* value */ as a placeholderMichael Goulet-1/+1
2024-04-16Rollup merge of #123016 - compiler-errors:no-type-var-origin, r=lcnrLeón Orell Valerian Liehr-47/+25
Remove `TypeVariableOriginKind` and `ConstVariableOriginKind` It's annoying to have to import `TypeVariableOriginKind` just to fill it with `MiscVariable` for almost every use. Every other usage other than `TypeParameterDefinition` wasn't even used -- I can see how it may have been useful once for debugging, but I do quite a lot of typeck debugging and I've never really needed it. So let's just remove it, and keep around the only useful thing which is the `DefId` of the param for `var_for_def`. This is based on #123006, which removed the special use of `TypeVariableOriginKind::OpaqueInference`, which I'm pretty sure I was the one that added. r? lcnr or re-roll to types
2024-04-15Simplify shallow resolver to just fold ty/constsMichael Goulet-17/+16
2024-04-15Remove ConstVariableOriginKindMichael Goulet-10/+4
2024-04-15Remove TypeVariableOriginKindMichael Goulet-37/+21
2024-04-15Rollup merge of #123924 - compiler-errors:tuple-sugg, r=estebankMichael Goulet-0/+56
Fix various bugs in `ty_kind_suggestion` Consolidates two implementations of `ty_kind_suggestion` Fixes some misuse of the empty param-env Fixes a problem where we suggested `(42)` instead of `(42,)` for tuple suggestions Suggest a value when `return;`, making it consistent with `break;` Fixes #123906
2024-04-15Rollup merge of #123900 - compiler-errors:nobound, r=lcnrMichael Goulet-23/+20
Stop using `PolyTraitRef` for closure/coroutine predicates already instantiated w placeholders r? lcnr
2024-04-15PolyTraitRefs -> TraitRefsMichael Goulet-9/+4
2024-04-15Stop using PolyTraitRef for closure/coroutine predicates already ↵Michael Goulet-24/+26
instantiated w placeholders
2024-04-14Rollup merge of #123618 - compiler-errors:overflow-ambig, r=spastorinoGuillaume Gomez-6/+18
Discard overflow obligations in `impl_may_apply` Hacky fix for #123493. Throws away obligations that are overflowing in `impl_may_apply` when we recompute if an impl applies, since those will lead to fatal overflow if processed during fulfillment. Something about #114811 (I think it's the predicate reordering) caused us to evaluate predicates differently in error reporting leading to fatal overflow, though I believe the underlying overflow is possible to hit since this code was rewritten to use fulfillment. Fixes #123493
2024-04-14Fix 1-tuple value suggestionMichael Goulet-5/+4