about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src/traits
AgeCommit message (Collapse)AuthorLines
2024-05-10Use fewer origins when creating type variables.Nicholas Nethercote-22/+7
`InferCtxt::next_{ty,const}_var*` all take an origin, but the `param_def_id` is almost always `None`. This commit changes them to just take a `Span` and build the origin within the method, and adds new methods for the rare cases where `param_def_id` might not be `None`. This avoids a lot of tedious origin building. Specifically: - next_ty_var{,_id_in_universe,_in_universe}: now take `Span` instead of `TypeVariableOrigin` - next_ty_var_with_origin: added - next_const_var{,_in_universe}: takes Span instead of ConstVariableOrigin - next_const_var_with_origin: added - next_region_var, next_region_var_in_universe: these are unchanged, still take RegionVariableOrigin The API inconsistency (ty/const vs region) seems worth it for the large conciseness improvements.
2024-05-09always use `GenericArgsRef`lcnr-2/+2
2024-05-07Fix ICEs in diagnostic::on_unimplementedMichael Goulet-51/+69
2024-05-03Do not ICE on foreign malformed `diagnostic::on_unimplemented`Esteban Küber-6/+8
Fix #124651.
2024-05-02Take ocx by move for pending obligationsMichael Goulet-1/+8
2024-05-02Use ObligationCtxt in favor of TraitEngine in many placesMichael Goulet-56/+85
2024-05-02Rollup merge of #124624 - WaffleLapkin:old_unit, r=fmeaseMatthias Krüger-2/+2
Use `tcx.types.unit` instead of `Ty::new_unit(tcx)` I don't think there is any need for the function, given that we can just access the `.types`, similarly to all other primitives?
2024-05-02Inline & delete `Ty::new_unit`, since it's just a field accessWaffle Lapkin-2/+2
2024-05-02shallow resolve in orphan checklcnr-28/+27
2024-05-01Auto merge of #124356 - fmease:fewer-magic-numbers-in-names, r=lcnrbors-6/+6
Cleanup: Replace item names referencing GitHub issues or error codes with something more meaningful **lcnr** in https://github.com/rust-lang/rust/pull/117164#pullrequestreview-1969935387: > […] while I know that there's precendent to name things `Issue69420`, I really dislike this as it requires looking up the issue to figure out the purpose of such a variant. Actually referring to the underlying issue, e.g. `AliasMayNormToUncovered` or whatever and then linking to the issue in a doc comment feels a lot more desirable to me. We should ideally rename all the functions and enums which currently use issue numbers. I've grepped through `compiler/` like crazy and think that I've found all instances of this pattern. However, I haven't renamed `compute_2229_migrations_*`. Should I? The first commit introduces an abhorrent and super long name for an item because naming is hard but also scary looking / unwelcoming names are good for things related to temporary-ish backcompat hacks. I'll let you discover it by yourself. Contains a bit of drive-by cleanup and a diag migration bc that was the simplest option. r? lcnr or compiler
2024-04-30Auto merge of #117164 - fmease:orphan-norm, r=lcnrbors-67/+115
Lazily normalize inside trait ref during orphan check & consider ty params in rigid alias types to be uncovered Fixes #99554, fixes rust-lang/types-team#104. Fixes #114061. Supersedes #100555. Tracking issue for the future compatibility lint: #124559. r? lcnr
2024-04-30Give items related to issue 33140 a more meaningful nameLeón Orell Valerian Liehr-6/+6
2024-04-30Normalize trait ref before orphan check & consider ty params in alias types ↵León Orell Valerian Liehr-67/+115
to be uncovered
2024-04-30Rollup merge of #124511 - nnethercote:rm-extern-crates, r=fee1-deadMatthias Krüger-3/+16
Remove many `#[macro_use] extern crate foo` items This requires the addition of more `use` items, which often make the code more verbose. But they also make the code easier to read, because `#[macro_use]` obscures where macros are defined. r? `@fee1-dead`
2024-04-29Actually use probes when needed and stop relying on existing outer probesMichael Goulet-3/+2
2024-04-29Remove `extern crate smallvec` from a couple of crates.Nicholas Nethercote-2/+2
2024-04-29Remove `extern crate rustc_data_structures` from numerous crates.Nicholas Nethercote-1/+1
2024-04-29Remove `extern crate rustc_macros` from numerous crates.Nicholas Nethercote-0/+13
2024-04-26Auto merge of #122385 - lcnr:analyze-obligations-for-infer, r=compiler-errorsbors-3/+7
`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-25Renamed DerivedObligation to WellFormedDeriveObligationMichael Goulet-4/+4
2024-04-25hir typeck: look into nested goalslcnr-3/+7
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-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 #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/+45
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-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-1/+1
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-1/+1
We want to run them on all 64-bit platforms.
2024-04-17Use non-exhaustive matches for TyKindDaria Sukhonina-2/+2
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-16/+15
Simplify shallow resolver to just fold ty/consts Probably faster than using a whole folder?
2024-04-16Add simple async drop glue generationzetanumbers-1/+45
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