about summary refs log tree commit diff
path: root/compiler/rustc_infer
AgeCommit message (Collapse)AuthorLines
2023-07-14refactor(rustc_middle): Substs -> GenericArgMahdi Dibaiee-245/+237
2023-07-12Re-format let-else per rustfmt updateMark Rousskov-35/+55
2023-07-11Rollup merge of #113567 - chenyukang:yukang-fix-113354-while-let, r=cjgillotJubilee-38/+39
While let suggestion will work for closure body Fixes #113354
2023-07-11Auto merge of #112984 - BoxyUwU:debug_with_infcx, r=compiler-errorsbors-0/+38
Introduce `trait DebugWithInfcx` to debug format types with universe info Seeing universes of infer vars is valuable for debugging but currently we have no way of easily debug formatting a type with the universes of all the infer vars shown. In the future I hope to augment the new solver's proof tree output with a `DebugWithInfcx` impl so that it can show universes but I left that out of this PR as it would be non trivial and this is already large and complex enough. The goal here is to make the various abstractions taking `T: Debug` able to use the codepath for printing out universes, that way we can do `debug!("{:?}", my_x)` and have `my_x` have universes shown, same for the `write!` macro. It's not possible to put the `Infcx: InferCtxtLike<I>` into the formatter argument to `Debug::fmt` so it has to go into the self ty. For this we introduce the type `OptWithInfcx<I: Interner, Infcx: InferCtxtLike<I>, T>` which has the data `T` optionally coupled with the infcx (more on why it's optional later). Because of coherence/orphan rules it's not possible to write the impl `Debug for OptWithInfcx<..., MyType>` when `OptWithInfcx` is in a upstream crate. This necessitates a blanket impl in the crate defining `OptWithInfcx` like so: `impl<T: DebugWithInfcx> Debug for OptWithInfcx<..., T>`. It is not intended for people to manually call `DebugWithInfcx::fmt`, the `Debug` impl for `OptWithInfcx` should be preferred. The infcx has to be optional in `OptWithInfcx` as otherwise we would end up with a large amount of code duplication. Almost all types that want to be used with `OptWithInfcx` do not themselves need access to the infcx so if we were to not optional we would end up with large `Debug` and `DebugWithInfcx` impls that were practically identical other than that when formatting their fields we wrap the field in `OptWithInfcx` instead of formatting it alone. The only types that need access to the infcx themselves are ty/const/region infer vars, everything else is implemented by having the `Debug` impl defer to `OptWithInfcx` with no infcx available. The `DebugWithInfcx` impl is pretty much just the standard `Debug` impl except that instead of recursively formatting fields with `write!(f, "{x:?}")` we must do `write!(f, "{:?}", opt_infcx.wrap(x))`. This is some pretty rough boilerplate but I could not think of an alternative unfortunately. `OptWithInfcx::wrap` is an eager `Option::map` because 99% of callsites were discarding the existing data in `OptWithInfcx` and did not need lazy evaluation. A trait `InferCtxtLike` was added instead of using `InferCtxt<'tcx>` as we need to implement `DebugWithInfcx` for types living in `rustc_type_ir` which are generic over an interner and do not have access to `InferCtxt` since it lives in `rustc_infer`. Additionally I suspect that adding universe info to new solver proof tree output will require an implementation of `InferCtxtLike` for something that is not an `InferCtxt` although this is not the primary motivaton. --- To summarize: - There is a type `OptWithInfcx` which bundles some data optionally with an infcx with allows us to pass an infcx into a `Debug` impl. It's optional instead of being there unconditionally so that we can share code for `Debug` and `DebugWithInfcx` impls that don't care about whether there is an infcx available but have fields that might care. - There is a trait `DebugWithInfcx` which allows downstream crates to add impls of the form `Debug for OptWithInfcx<...>` which would normally be forbidden by orphan rules/coherence. - There is a trait `InferCtxtLike` to allow us to implement `DebugWithInfcx` for types that live in `rustc_type_ir` This allows debug formatting various `ty::*` structures with universes shown by using the `Debug` impl for `OptWithInfcx::new(ty, infcx)` --- This PR does not add `DebugWithInfcx` impls to absolutely _everything_ that should realistically have them, for example you cannot use `OptWithInfcx<Obligation<Predicate>>`. I am leaving this to a future PR to do so as it would likely be a lot more work to do.
2023-07-11Rollup merge of #113310 - jieyouxu:dont-suggest-impl-trait-in-paths, r=lcnrMatthias Krüger-2/+10
Don't suggest `impl Trait` in path position Fixes #113264.
2023-07-11While let suggestion will work for closureyukang-38/+39
2023-07-08Auto merge of #113474 - compiler-errors:rollup-07x1up7, r=compiler-errorsbors-11/+0
Rollup of 8 pull requests Successful merges: - #113413 (Add needs-triage to all new issues) - #113426 (Don't ICE in `resolve_bound_vars` when associated return-type bounds are in bad positions) - #113427 (Remove `variances_of` on RPITIT GATs, remove its one use-case) - #113441 (miri: check that assignments do not self-overlap) - #113453 (Remove unused from_method from rustc_on_unimplemented) - #113456 (Avoid calling report_forbidden_specialization for RPITITs) - #113466 (Update cargo) - #113467 (Fix comment of `fn_can_unwind`) r? `@ghost` `@rustbot` modify labels: rollup
2023-07-07Rollup merge of #113427 - compiler-errors:no-variances-of-rpitit-gat, ↵Michael Goulet-11/+0
r=spastorino Remove `variances_of` on RPITIT GATs, remove its one use-case It doesn't make sense to implement variances on a GAT anyways, since we don't relate GATs with variance: https://github.com/rust-lang/rust/blob/85bf07972a1041b9e25393b803d0e006bec3eaaf/compiler/rustc_middle/src/ty/relate.rs#L569-L579 r? ``@spastorino``
2023-07-08Auto merge of #112652 - oli-obk:tait_only_in_sig, r=compiler-errorsbors-1/+1
Require TAITs to be mentioned in the signatures of functions that register hidden types for them r? `@lcnr` `@compiler-errors` This implements the lang team decision from [the TAIT design meeting](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/design.20meeting.202023-05-31.20TAITs/near/362518164).
2023-07-08Don't suggest `impl Trait` in path position许杰友 Jieyou Xu (Joe)-2/+10
2023-07-07Require TAITs to be mentioned in the signatures of functions that register ↵Oli Scherer-1/+1
hidden types for them
2023-07-07Auto merge of #113308 - compiler-errors:poly-select, r=lcnrbors-3/+4
Split `SelectionContext::select` into fns that take a binder and don't *most* usages of `SelectionContext::select` don't need to use a binder, but wrap them in a dummy because of the signature. Let's split this out into `SelectionContext::{select,poly_select}` and limit the usages of the latter. Right now, we only have 3 places where we're calling `poly_select` -- fulfillment, internally within the old solver, and the auto-trait finder. r? `@lcnr`
2023-07-07Remove variances_of on RPITIT gats, remove its one use-caseMichael Goulet-11/+0
2023-07-06Avoid calling item_name for RPITITSantiago Pastorino-3/+5
2023-07-06Separate select calls that don't need a binderMichael Goulet-0/+1
2023-07-06TraitObligation -> PolyTraitObligationMichael Goulet-3/+3
2023-07-06Add a new trait to `Debug` things with an infcx availableBoxy-0/+38
2023-07-05Move `TyCtxt::mk_x` to `Ty::new_x` where applicableBoxy-42/+45
2023-07-05Rollup merge of #113319 - lcnr:type-param-def-def-id, r=compiler-errorsMichael Goulet-5/+5
`TypeParameterDefinition` always require a `DefId` the `None` case never actually reaches diagnostics so it feels better for diagnostics to be able to rely on the `DefId` being there, cc #113310
2023-07-05Rollup merge of #113317 - lcnr:sketchy-new-select, r=oli-obkMichael Goulet-24/+13
-Ztrait-solver=next: stop depending on old solver removes the final dependencies on the old solver when `-Ztrait-solver=next` is enabled.
2023-07-04Replace `const_error` methods with `Const::new_error`Boxy-2/+2
2023-07-04Replace `mk_const` with `Const::new_x` methodsBoxy-23/+26
2023-07-04`TypeParameterDefinition` always require a `DefId`lcnr-5/+5
2023-07-04Auto merge of #113303 - compiler-errors:yeet-chalk, r=lcnrbors-5/+1
Remove chalk support from the compiler Removes chalk (`-Ztrait-solver=chalk`) from the compiler and prunes any dead code resulting from this, mainly: * Remove the chalk compatibility layer in `compiler/rustc_traits/src/chalk` * Remove the chalk flag `-Ztrait-solver=chalk` and its `TraitEngine` implementation * Remove `TypeWellFormedFromEnv` (and its many `bug!()` match arms) * Remove the chalk migration mode from compiletest * Remove the `chalkify` UI tests (do we want to keep any of these, but migrate them to `-Ztrait-solver=next`??) Fulfills rust-lang/types-team#93. r? `@jackh726`
2023-07-04 -Ztrait-solver=next: stop depending on old solverlcnr-24/+13
2023-07-04Auto merge of #113215 - compiler-errors:rpitit-predicates-tweaks, r=spastorinobors-1/+3
Make RPITITs assume/require their parent method's predicates Removes a FIXME from the `param_env` query where we were manually adding the parent function's predicates to the RPITIT's assumptions. r? `@spastorino`
2023-07-03remove TypeWellFormedFromEnvMichael Goulet-5/+1
2023-07-03add deep normalization via the new solverlcnr-0/+1
2023-07-01Auto merge of #113154 - lcnr:better-probe-check, r=compiler-errorsbors-33/+14
change snapshot tracking in fulfillment contexts use the exact snapshot number to prevent misuse even when created inside of a snapshot
2023-06-30RPITITs inherit method predicatesMichael Goulet-1/+3
2023-06-29change snapshot tracking in fulfillment contextslcnr-33/+14
2023-06-29Make the Elaboratable trait take clausesMichael Goulet-40/+42
2023-06-27avoid using `format!("{}", ..)`Takayuki Maeda-2/+2
2023-06-26TypeWellFormedInEnvMichael Goulet-2/+3
2023-06-26Migrate predicates_of and caller_bounds to ClauseMichael Goulet-29/+19
2023-06-24Rollup merge of #112703 - aliemjay:next-solver-root-var, r=compiler-errorsGuillaume Gomez-0/+1
[-Ztrait-solver=next, mir-typeck] instantiate hidden types in the root universe Fixes an ICE in the test `member-constraints-in-root-universe`. Main motivation is to make #112691 pass under the new solver. r? ``@compiler-errors``
2023-06-24instantiate hidden types in root universeAli MJ Al-Nasrawy-0/+1
2023-06-23Auto merge of #112891 - oli-obk:impl_trait_in_assoc_tys_cleanup, ↵bors-9/+3
r=compiler-errors Various impl trait in assoc tys cleanups r? `@compiler-errors` All commits except for the last are pure refactorings. 274dab5bd658c97886a8987340bf50ae57900c39 allows struct fields to participate in deciding whether a function has an opaque in its signature. best reviewed commit by commit
2023-06-22Expect clause moreMichael Goulet-4/+4
2023-06-22Migrate item_bounds to ty::ClauseMichael Goulet-7/+25
2023-06-22Point to argument/return type instead of the whole function headerOli Scherer-1/+2
2023-06-22Move `opaque_type_origin_unchecked` onto `TyCtxt` and re-use it where it was ↵Oli Scherer-8/+1
open coded
2023-06-21Rollup merge of #112772 - compiler-errors:clauses-1, r=lcnrNilstrieb-37/+60
Add a fully fledged `Clause` type, rename old `Clause` to `ClauseKind` Does two basic things before I put up a more delicate set of PRs (along the lines of #112714, but hopefully much cleaner) that migrate existing usages of `ty::Predicate` to `ty::Clause` (`predicates_of`/`item_bounds`/`ParamEnv::caller_bounds`). 1. Rename `Clause` to `ClauseKind`, so it's parallel with `PredicateKind`. 2. Add a new `Clause` type which is parallel to `Predicate`. * This type exposes `Clause::kind(self) -> Binder<'tcx, ClauseKind<'tcx>>` which is parallel to `Predicate::kind` 😸 The new `Clause` type essentially acts as a newtype wrapper around `Predicate` that asserts that it is specifically a `PredicateKind::Clause`. Turns out from experimentation[^1] that this is not negative performance-wise, which is wonderful, since this a much simpler design than something that requires encoding the discriminant into the alignment bits of a predicate kind, or something else like that... r? ``@lcnr`` or ``@oli-obk`` [^1]: https://github.com/rust-lang/rust/pull/112714#issuecomment-1595653910
2023-06-19Rollup merge of #112781 - compiler-errors:new-solver-tait-overlaps-hidden, ↵Michael Goulet-4/+6
r=lcnr Don't consider TAIT normalizable to hidden ty if it would result in impossible item bounds See test for example where we shouldn't consider it possible to alias-relate a TAIT and hidden type. r? `@lcnr`
2023-06-19Fully fledged Clause typeMichael Goulet-0/+20
2023-06-19s/Clause/ClauseKindMichael Goulet-37/+40
2023-06-19Don't consider TAIT normalizable to hidden ty if it would result in ↵Michael Goulet-4/+6
impossible item bounds
2023-06-18Treat TAIT equation as always ambiguous in coherenceMichael Goulet-7/+4
2023-06-17Move ConstEvaluatable to ClauseMichael Goulet-2/+2
2023-06-17Move WF goal to clauseMichael Goulet-3/+3