about summary refs log tree commit diff
path: root/compiler/rustc_infer/src/traits
AgeCommit message (Collapse)AuthorLines
2022-02-14Call the method fork instead of clone and add proper commentsSantiago Pastorino-1/+1
2022-02-11Revert "Auto merge of #92007 - oli-obk:lazy_tait2, r=nikomatsakis"Oli Scherer-3/+0
This reverts commit e7cc3bddbe0d0e374d05e7003e662bba1742dbae, reversing changes made to 734368a200904ef9c21db86c595dc04263c87be0.
2022-02-02Lazily resolve type-alias-impl-trait defining usesOli Scherer-0/+3
by using an opaque type obligation to bubble up comparisons between opaque types and other types Also uses proper obligation causes so that the body id works, because out of some reason nll uses body ids for logic instead of just diagnostics.
2022-01-28Remove generalization over projectionkadmin-2/+6
Instead, just use a term everywhere.
2022-01-16Rollup merge of #92710 - jackh726:issue-92280, r=nikomatsakisMatthias Krüger-4/+13
Include Projections when elaborating TypeOutlives Fixes #92280 In `Elaborator`, we elaborate that `Foo<<Bar as Baz>::Assoc>: 'a` -> `<Bar as Baz>::Assoc: 'a`. This is the same rule that would be applied to any other `Param`. If there are escaping vars, we continue to do nothing. r? `@nikomatsakis`
2022-01-15Rollup merge of #92191 - jackh726:issue-89352, r=nikomatsakisMatthias Krüger-1/+1
Prefer projection candidates instead of param_env candidates for Sized predicates Fixes #89352 Also includes some drive by logging and verbose printing changes that I found useful when debugging this, but I can remove this if needed. This is a little hacky - but imo no more than the rest of `candidate_should_be_dropped_in_favor_of`. Importantly, in a Chalk-like world, both candidates should be completely compatible. r? ```@nikomatsakis```
2022-01-10Elaborate param_env predicates when checking if type outlives involving ↵Jack Huey-4/+13
projection holds
2021-12-22When obligation is a sized predicate, prefer projection or object candidates ↵Jack Huey-1/+1
instead of param_env candidates
2021-12-20Eliminate `ObligationCauseData`.Nicholas Nethercote-1/+1
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-9/+9
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-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-13Remove `in_band_lifetimes` from `rustc_infer`LegionMammal978-9/+9
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-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-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-2/+2
2021-12-02Reduce boilerplate around infallible foldersAlan Egerton-4/+7
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-28Auto merge of #91230 - eggyal:fallible-type-fold, r=jackh726bors-5/+5
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-26Make `TypeFoldable` implementors short-circuit on errorLeSeulArtichaut-5/+5
Co-authored-by: Alan Egerton <eggyal@gmail.com>
2021-11-25Visit `param_env` field in Obligation's `TypeFoldable` implAaron Hill-1/+2
This oversight appears to have gone unnoticed for a long time without causing issues, but it should still be fixed.
2021-11-14Fix span for non-satisfied trivial trait boundsNilstrieb-0/+17
The spans for "trait bound not satisfied" errors in trivial trait bounds referenced the entire item (fn, impl, struct) before. Now they only reference the obligation itself (`String: Copy`) Address #90869
2021-11-11Auto merge of #90648 - matthewjasper:assoc-item-cleanup, r=cjgillotbors-3/+2
Assoc item cleanup This removes some fields from ObligationCauseCode Split out of #90639
2021-11-08fmtDeadbeef-8/+3
2021-11-08Make select_* methods return Vec for TraitEngineDeadbeef-4/+4
2021-11-07Remove some fields from `ObligationCauseCode`Matthew Jasper-3/+2
2021-10-23Auto merge of #90104 - spastorino:coherence-for-negative-trait, r=nikomatsakisbors-1/+19
Implement coherence checks for negative trait impls The main purpose of this PR is to be able to [move Error trait to core](https://github.com/rust-lang/project-error-handling/issues/3). This feature is necessary to handle the following from impl on box. ```rust impl From<&str> for Box<dyn Error> { ... } ``` Without having negative traits affect coherence moving the error trait into `core` and moving that `From` impl to `alloc` will cause the from impl to no longer compiler because of a potential future incompatibility. The compiler indicates that `&str` _could_ introduce an `Error` impl in the future, and thus prevents the `From` impl in `alloc` that would cause overlap with `From<E: Error> for Box<dyn Error>`. Adding `impl !Error for &str {}` with the negative trait coherence feature will disable this error by encoding a stability guarantee that `&str` will never implement `Error`, making the `From` impl compile. We would have this in `alloc`: ```rust impl From<&str> for Box<dyn Error> {} // A impl<E> From<E> for Box<dyn Error> where E: Error {} // B ``` and this in `core`: ```rust trait Error {} impl !Error for &str {} ``` r? `@nikomatsakis` This PR was built on top of `@yaahc` PR #85764. Language team proposal: to https://github.com/rust-lang/lang-team/issues/96
2021-10-22Document flip polaritySantiago Pastorino-0/+3
2021-10-20Add TraitObligation::polarity() for better encapsulationSantiago Pastorino-0/+4
2021-10-20Consider negative polarity on overlap checkSantiago Pastorino-1/+12
2021-10-15Move push_outlives_components to rustc_inferjackh726-2/+2
2021-09-24Rollup merge of #89001 - jackh726:binder-cleanup, r=nikomatsakisJubilee-1/+2
Be explicit about using Binder::dummy This is somewhat of a late followup to the binder refactor PR. It removes `ToPredicate` and `ToPolyTraitImpls` that hide the use of `Binder::dummy`. While this does make code a bit more verbose, it allows us be more careful about where we create binders. Another alternative here might be to add a new trait `ToBinder` or something with a `dummy()` fn. Which could still allow grepping but allows doing something like `trait_ref.dummy()` (but I also wonder if longer-term, it would be better to be even more explicit with a `bind_with_vars(ty::List::empty())` *but* that's not clear yet. r? ``@nikomatsakis``
2021-09-17Add another case of fallback to () avoid breakageMark Rousskov-0/+3
This adds src/test/ui/never_type/fallback-closure-ret.rs as a test case which showcases the failure mode fixed by this commit.
2021-09-17Auto merge of #88945 - Aaron1011:no-projection-completion, ↵bors-41/+0
r=wesleywiser,jackh726 Remove concept of 'completion' from the projection cache Fixes #88910 When we initially store a `NormalizedTy` in the projection cache, we discard all obligations that we can (while ensuring that we don't cause any issues with incremental compilation). Marking a projection cache entry as 'completed' discards all obligations associated with it. This can only cause problems, since any obligations stored in the cache are there for a reason (e.g. they evaluate to `EvaluatedToOkModuloRegions`). This commit removes `complete` and `complete_normalized` entirely.
2021-09-16Auto merge of #88719 - estebank:point-at-arg-for-obligation, r=nagisabors-5/+1
Point at argument instead of call for their obligations When an obligation is introduced by a specific `fn` argument, point at the argument instead of the `fn` call if the obligation fails to be fulfilled. Move the information about pointing at the call argument expression in an unmet obligation span from the `FulfillmentError` to a new `ObligationCauseCode`. When giving an error about an obligation introduced by a function call that an argument doesn't fulfill, and that argument is a block, add a span_label pointing at the innermost tail expression. Current output: ``` error[E0425]: cannot find value `x` in this scope --> f10.rs:4:14 | 4 | Some(x * 2) | ^ not found in this scope error[E0277]: expected a `FnOnce<({integer},)>` closure, found `Option<_>` --> f10.rs:2:31 | 2 | let p = Some(45).and_then({ | ______________________--------_^ | | | | | required by a bound introduced by this call 3 | | |x| println!("doubling {}", x); 4 | | Some(x * 2) | | ----------- 5 | | }); | |_____^ expected an `FnOnce<({integer},)>` closure, found `Option<_>` | = help: the trait `FnOnce<({integer},)>` is not implemented for `Option<_>` ``` Previous output: ``` error[E0425]: cannot find value `x` in this scope --> f10.rs:4:14 | 4 | Some(x * 2) | ^ not found in this scope error[E0277]: expected a `FnOnce<({integer},)>` closure, found `Option<_>` --> f10.rs:2:22 | 2 | let p = Some(45).and_then({ | ^^^^^^^^ expected an `FnOnce<({integer},)>` closure, found `Option<_>` | = help: the trait `FnOnce<({integer},)>` is not implemented for `Option<_>` ``` Partially address #27300. Will require rebasing on top of #88546.
2021-09-16Refactor `FulfillmentError` to track less dataEsteban Kuber-5/+1
Move the information about pointing at the call argument expression in an unmet obligation span from the `FulfillmentError` to a new `ObligationCauseCode`.
2021-09-15Remove ToPredicate impls that use Binder::dummyjackh726-1/+2
2021-09-15Move object safety suggestions to the end of the errorEsteban Kuber-4/+8
2021-09-14Remove concept of 'completion' from the projection cacheAaron Hill-41/+0
Fixes #88910 When we initially store a `NormalizedTy` in the projection cache, we discard all obligations that we can (while ensuring that we don't cause any issues with incremental compilation). Marking a projection cache entry as 'completed' discards all obligations associated with it. This can only cause problems, since any obligations stored in the cache are there for a reason (e.g. they evaluate to `EvaluatedToOkModuloRegions`). This commit removes `complete` and `complete_normalized` entirely.
2021-08-25Rollup merge of #88218 - Aaron1011:missing-method-dyn, r=nagisaLéo Lanteri Thauvin-6/+0
Remove `Session.trait_methods_not_found` Instead, avoid registering the problematic well-formed obligation to begin with. This removes global untracked mutable state, and avoids potential issues with incremental compilation.
2021-08-22Fix typos “a”→“an”Frank Steffahn-1/+1
2021-08-21Remove `Session.trait_methods_not_found`Aaron Hill-6/+0
Instead, avoid registering the problematic well-formed obligation to begin with. This removes global untracked mutable state, and avoids potential issues with incremental compilation.
2021-08-19introduce a Coerce predicateNiko Matsakis-0/+4
2021-08-14Assign FIXMEs to me and remove obsolete onesDeadbeef-1/+1
Also fixed capitalization of documentation
2021-08-13Pass constness to SelectionContextDeadbeef-0/+18
2021-08-13move Constness into TraitPredicateDeadbeef-1/+1
2021-07-20Refactor vtable format.Charles Lew-3/+3
2021-07-16Add initial implementation of HIR-based WF checking for diagnosticsAaron Hill-1/+6
During well-formed checking, we walk through all types 'nested' in generic arguments. For example, WF-checking `Option<MyStruct<u8>>` will cause us to check `MyStruct<u8>` and `u8`. However, this is done on a `rustc_middle::ty::Ty`, which has no span information. As a result, any errors that occur will have a very general span (e.g. the definintion of an associated item). This becomes a problem when macros are involved. In general, an associated type like `type MyType = Option<MyStruct<u8>>;` may have completely different spans for each nested type in the HIR. Using the span of the entire associated item might end up pointing to a macro invocation, even though a user-provided span is available in one of the nested types. This PR adds a framework for HIR-based well formed checking. This check is only run during error reporting, and is used to obtain a more precise span for an existing error. This is accomplished by individually checking each 'nested' type in the HIR for the type, allowing us to find the most-specific type (and span) that produces a given error. The majority of the changes are to the error-reporting code. However, some of the general trait code is modified to pass through more information. Since this has no soundness implications, I've implemented a minimal version to begin with, which can be extended over time. In particular, this only works for HIR items with a corresponding `DefId` (e.g. it will not work for WF-checking performed within function bodies).