summary refs log tree commit diff
path: root/compiler/rustc_infer/src
AgeCommit message (Collapse)AuthorLines
2022-01-03Suggest changing quotes when str/char type mismatchchordtoll-3/+38
2021-12-29Refactor variance diagnostics to work with more typesAaron Hill-2/+3
Instead of special-casing mutable pointers/references, we now support general generic types (currently, we handle `ty::Ref`, `ty::RawPtr`, and `ty::Adt`) When a `ty::Adt` is involved, we show an additional note explaining which of the type's generic parameters is invariant (e.g. the `T` in `Cell<T>`). Currently, we don't explain *why* a particular generic parameter ends up becoming invariant. In the general case, this could require printing a long 'backtrace' of types, so doing this would be more suitable for a follow-up PR. We still only handle the case where our variance switches to `ty::Invariant`.
2021-12-20Eliminate `ObligationCauseData`.Nicholas Nethercote-27/+27
This makes `Obligation` two words bigger, but avoids allocating a lot of the time. I previously tried this in #73983 and it didn't help much, but local timings look more promising now.
2021-12-19Rollup merge of #91878 - LegionMammal978:less-inband-infer, r=Aaron1011Matthias Krüger-49/+48
Remove `in_band_lifetimes` from `rustc_infer` See #91867 for more information. This crate actually had a typo `'ctx` in one of its functions: ```diff -pub fn same_type_modulo_infer(a: Ty<'tcx>, b: Ty<'ctx>) -> bool { +pub fn same_type_modulo_infer<'tcx>(a: Ty<'tcx>, b: Ty<'tcx>) -> bool { ``` Also, I wasn't entirely sure about the lifetimes in `suggest_new_region_bound`: ```diff pub fn suggest_new_region_bound( - tcx: TyCtxt<'tcx>, + tcx: TyCtxt<'_>, err: &mut DiagnosticBuilder<'_>, fn_returns: Vec<&rustc_hir::Ty<'_>>, ``` Should all of those lifetimes really be distinct?
2021-12-19Auto merge of #91957 - nnethercote:rm-SymbolStr, r=oli-obkbors-2/+1
Remove `SymbolStr` This was originally proposed in https://github.com/rust-lang/rust/pull/74554#discussion_r466203544. As well as removing the icky `SymbolStr` type, it allows the removal of a lot of `&` and `*` occurrences. Best reviewed one commit at a time. r? `@oli-obk`
2021-12-18Re-introduce concept of projection cache 'completion'Aaron Hill-3/+69
Instead of clearing out the cache entirely, we store the intermediate evaluation result into the cache entry. This accomplishes several things: * We avoid the performance hit associated with re-evaluating the sub-obligations * We avoid causing issues with incremental compilation, since the final evaluation result is always the same * We avoid affecting other uses of the same `InferCtxt` which might care about 'side effects' from processing the sub-obligations (e,g. region constraints). Only code that is specifically aware of the new 'complete' code is affected
2021-12-18Rollup merge of #92022 - woodenarrow:br_expected_bool, r=estebankMatthias Krüger-4/+4
Eliminate duplicate codes of expected_found_bool The function expected_found_bool is the same as ExpectedFound::new. So use ExpectedFound::new to replace expected_found_bool to eliminate duplicate codes. ![image](https://user-images.githubusercontent.com/95843988/146486722-c910eccd-a36c-4dc5-8b36-214aab058e38.png)
2021-12-17Eliminate duplicate codes of expected_found_boollzh-4/+4
2021-12-17Fix typo in "new region bound" suggestionEsteban Kuber-1/+1
The lifetime name shoud always appear in text surrounded by `.
2021-12-15Remove unnecessary sigils around `Symbol::as_str()` calls.Nicholas Nethercote-2/+1
2021-12-14Stabilize iter::zip.PFPoitras-1/+0
2021-12-13Remove `in_band_lifetimes` from `rustc_infer`LegionMammal978-49/+48
This crate actually had a typo `'ctx` in one of its functions: ```diff -pub fn same_type_modulo_infer(a: Ty<'tcx>, b: Ty<'ctx>) -> bool { +pub fn same_type_modulo_infer<'tcx>(a: Ty<'tcx>, b: Ty<'tcx>) -> bool { ```
2021-12-13Instead of checking for exact bounds, try to prove themJack Huey-2/+2
2021-12-12Revert "Auto merge of #91491 - spastorino:revert-91354, r=oli-obk"Deadbeef-24/+16
This reverts commit ff2439b7b9bafcfdff86b7847128014699df8442, reversing changes made to 2a9e0831d6603d87220cedd1b1293e2eb82ef55c.
2021-12-11Auto merge of #91769 - estebank:type-trait-bound-span-2, r=oli-obkbors-3/+36
Tweak assoc type obligation spans * Point at RHS of associated type in obligation span * Point at `impl` assoc type on projection error * Reduce verbosity of recursive obligations * Point at source of binding lifetime obligation * Tweak "required bound" note * Tweak "expected... found opaque (return) type" labels * Point at set type in impl assoc type WF errors r? `@oli-obk` This is a(n uncontroversial) subset of #85799.
2021-12-11Auto merge of #91799 - matthiaskrgr:rollup-b38xx6i, r=matthiaskrgrbors-49/+130
Rollup of 6 pull requests Successful merges: - #83174 (Suggest using a temporary variable to fix borrowck errors) - #89734 (Point at capture points for non-`'static` reference crossing a `yield` point) - #90270 (Make `Borrow` and `BorrowMut` impls `const`) - #90741 (Const `Option::cloned`) - #91548 (Add spin_loop hint for RISC-V architecture) - #91721 (Minor improvements to `future::join!`'s implementation) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-12-11Rollup merge of #91640 - cjgillot:in-band-collect, r=oli-obkMatthias Krüger-24/+18
Simplify collection of in-band lifetimes Split from https://github.com/rust-lang/rust/pull/91403 r? ````@oli-obk````
2021-12-11Tweak assoc type obligation spansEsteban Kuber-3/+36
* Point at RHS of associated type in obligation span * Point at `impl` assoc type on projection error * Reduce verbosity of recursive obligations * Point at source of binding lifetime obligation * Tweak "required bound" note * Tweak "expected... found opaque (return) type" labels * Point at set type in impl assoc type WF errors
2021-12-10fmtEsteban Kuber-16/+17
2021-12-10review commentEsteban Kuber-3/+3
2021-12-10Remove field from `ErrorValue`Esteban Kuber-12/+12
2021-12-10Review commentsEsteban Kuber-10/+12
2021-12-10Tweak wordingEsteban Kuber-3/+3
2021-12-10Use a more accurate `Span` for `'static` obligation from return typeEsteban Kuber-5/+23
2021-12-10Point at return type when it introduces `'static` obligationEsteban Kuber-0/+20
2021-12-10Add filtering based on involved required lifetimeEsteban Kuber-17/+20
More accurate filtering still needed.
2021-12-10review commentsEsteban Kuber-21/+29
* take diagnostic logic out of happy-path * sort/dedup once * add more comments
2021-12-10Clean up visual output logicEsteban Kuber-71/+21
2021-12-10Point at capture points for non-`'static` reference crossing a `yield` pointEsteban Kuber-16/+95
``` error[E0759]: `self` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement --> $DIR/issue-72312.rs:10:24 | LL | pub async fn start(&self) { | ^^^^^ this data with an anonymous lifetime `'_`... ... LL | require_static(async move { | -------------- ...is required to live as long as `'static` here... LL | &self; | ----- ...and is captured here | note: `'static` lifetime requirement introduced by this trait bound --> $DIR/issue-72312.rs:2:22 | LL | fn require_static<T: 'static>(val: T) -> T { | ^^^^^^^ error: aborting due to previous error For more information about this error, try `rustc --explain E0759`. ``` Fix #72312.
2021-12-08Rollup merge of #90709 - estebank:erase-known-type-params, r=nagisaMatthias Krüger-6/+131
Only shown relevant type params in E0283 label When we point at a binding to suggest giving it a type, erase all the type for ADTs that have been resolved, leaving only the ones that could not be inferred. For small shallow types this is not a problem, but for big nested types with lots of params, this can otherwise cause a lot of unnecessary visual output.
2021-12-07Simplify match.Camille GILLOT-25/+15
2021-12-07Store impl_trait_fn inside OpaqueTyOrigin.Camille GILLOT-10/+14
2021-12-07Rollup merge of #91493 - oli-obk:cleanup, r=michaelwoeristerMatthias Krüger-5/+8
Remove a dead code path. It is neither documented nor can I see any way it could ever be reached. Also, no tests fail when turning that arm into an ICE
2021-12-07Add test with multiple type params failing inferenceEsteban Kuber-3/+1
2021-12-07Refer to const params as "const params" and not "type params"Esteban Kuber-36/+46
2021-12-07Refer to uninferred `const` params by their name, instead of `{ _: _ }`Esteban Kuber-6/+25
When the value of a const param isn't inferred, replace it with the param name from the definition.
2021-12-07Only shown relevant type params in E0283 labelEsteban Kuber-1/+99
When we point at a binding to suggest giving it a type, erase all the type for ADTs that have been resolved, leaving only the ones that could not be inferred. For small shallow types this is not a problem, but for big nested types with lots of params, this can otherwise cause a lot of unnecessary visual output.
2021-12-05Rollup merge of #90023 - b-naber:postpone_const_eval_infer_vars, r=nikomatsakisMatthias Krüger-30/+85
Postpone the evaluation of constant expressions that depend on inference variables Previously `delay_span_bug` calls were triggered once an inference variable was included in the substs of a constant that was to be evaluated. Some of these would merely have resulted in trait candidates being rejected, hence no real error was ever encountered, but the triggering of the `delay_span_bug` then caused an ICE in later stages of the compiler due to no error ever occurring. We now postpone the evaluation of these constants, so any trait obligation fulfillment will simply stall on this constant and the existing type inference machinery of the compiler handles any type errors if present. Fixes https://github.com/rust-lang/rust/issues/89320 Fixes https://github.com/rust-lang/rust/issues/89146 Fixes https://github.com/rust-lang/rust/issues/87964 Fixes https://github.com/rust-lang/rust/issues/87470 Fixes https://github.com/rust-lang/rust/issues/83288 Fixes https://github.com/rust-lang/rust/issues/83249 Fixes https://github.com/rust-lang/rust/issues/90654 I want to thank `@BoxyUwU` for cooperating on this and for providing some help. r? `@lcnr` maybe?
2021-12-03Remove a code path that is neither documented nor can I see the reason it ↵Oli Scherer-5/+8
existed. Also, no tests fail when turning that arm into an ICE
2021-12-03Revert "Auto merge of #91354 - fee1-dead:const_env, r=spastorino"Santiago Pastorino-16/+24
This reverts commit 18bb8c61a975fff6424cda831ace5b0404277145, reversing changes made to d9baa361902b172be716f96619b909f340802dea.
2021-12-02Rename TypeFolderFallible to FallibleTypeFolderAlan Egerton-4/+4
2021-12-02Reduce boilerplate around infallible foldersAlan Egerton-207/+196
2021-12-02Auto merge of #91354 - fee1-dead:const_env, r=spastorinobors-24/+16
Cleanup: Eliminate ConstnessAnd This is almost a behaviour-free change and purely a refactoring. "almost" because we appear to be using the wrong ParamEnv somewhere already, and this is now exposed by failing a test using the unstable `~const` feature. We most definitely need to review all `without_const` and at some point should probably get rid of many of them by using `TraitPredicate` instead of `TraitRef`. This is a continuation of https://github.com/rust-lang/rust/pull/90274. r? `@oli-obk` cc `@spastorino` `@ecstatic-morse`
2021-11-29Reformat everythingDeadbeef-4/+2
2021-11-29Completely remove ConstnessAndOli Scherer-2/+2
2021-11-29Avoid storing the ImplPolarity and Constness next to a TraitRef and use ↵Oli Scherer-4/+4
TraitPredicate instead
2021-11-29Use the constness from the param env instead of having a separate dimension ↵Oli Scherer-18/+12
for it This breaks a ~const test that will be fixed in a follow up commit of this PR
2021-11-28Take a LocalDefId in expect_*item.Camille GILLOT-1/+1
2021-11-28Auto merge of #91230 - eggyal:fallible-type-fold, r=jackh726bors-216/+220
Make `TypeFolder::fold_*` return `Result` Implements rust-lang/compiler-team#432. Initially this is just a rebase of `@LeSeulArtichaut's` work in #85469 (abandoned; see https://github.com/rust-lang/rust/pull/85485#issuecomment-908781112). At that time, it caused a regression in performance that required some further exploration... with this rebased PR bors can hopefully report some perf analysis from which we can investigate further (if the regression is indeed still present). r? `@jackh726` cc `@nikomatsakis`
2021-11-26Use `TypeFolder::Error` for `FullTypeResolver` and `QueryNormalizer`LeSeulArtichaut-21/+7
Co-authored-by: Alan Egerton <eggyal@gmail.com>