summary refs log tree commit diff
path: root/compiler/rustc_infer/src
AgeCommit message (Collapse)AuthorLines
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-22Use `derive_default_enum` in the compilerJacob Pratt-7/+3
2021-11-21Simplify for loop desugarCameron Steffen-6/+18
2021-11-21Auto merge of #91104 - matthiaskrgr:rollup-duk33o1, r=matthiaskrgrbors-6/+18
Rollup of 4 pull requests Successful merges: - #91008 (Adds IEEE 754-2019 minimun and maximum functions for f32/f64) - #91070 (Make `LLVMRustGetOrInsertGlobal` always return a `GlobalVariable`) - #91097 (Add spaces in opaque `impl Trait` with more than one trait) - #91098 (Don't suggest certain fixups (`.field`, `.await`, etc) when reporting errors while matching on arrays ) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-11-21Auto merge of #89580 - estebank:trait-bounds-are-tricky, r=nagisabors-5/+16
Point at source of trait bound obligations in more places Be more thorough in using `ItemObligation` and `BindingObligation` when evaluating obligations so that we can point at trait bounds that introduced unfulfilled obligations. We no longer incorrectly point at unrelated trait bounds (`substs-ppaux.verbose.stderr`). In particular, we now point at trait bounds on method calls. We no longer point at "obvious" obligation sources (we no longer have a note pointing at `Trait` saying "required by a bound in `Trait`", like in `associated-types-no-suitable-supertrait*`). We no longer point at associated items (`ImplObligation`), as they didn't add any user actionable information, they just added noise. Address part of #89418.
2021-11-20Fix for issue 91058Michael Goulet-4/+16
2021-11-20Use same_type_modulo_infer in more placesMichael Goulet-2/+2
2021-11-20Point at source of trait bound obligations in more placesEsteban Kuber-5/+16
Be more thorough in using `ItemObligation` and `BindingObligation` when evaluating obligations so that we can point at trait bounds that introduced unfulfilled obligations. We no longer incorrectly point at unrelated trait bounds (`substs-ppaux.verbose.stderr`). In particular, we now point at trait bounds on method calls. We no longer point at "obvious" obligation sources (we no longer have a note pointing at `Trait` saying "required by a bound in `Trait`", like in `associated-types-no-suitable-supertrait*`). Address part of #89418.
2021-11-20Suggest await on cases involving inferMichael Goulet-3/+31
2021-11-17Rollup merge of #90884 - Nilstrieb:fix-span-trivial-trait-bound, r=estebankMatthias Krüger-0/+17
Fix span for non-satisfied trivial trait bounds 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-17Rollup merge of #90667 - rukai:improve_static_lifetime_diagnostics, r=estebankMatthias Krüger-41/+24
Improve diagnostics when a static lifetime is expected Makes progress towards https://github.com/rust-lang/rust/issues/90600 The diagnostics here were previously entirely removed due to giving a misleading suggestion but if we instead provide an informative label in that same location it should better help the user understand the situation. I included the example from the issue as it demonstrates an area where the diagnostics are still lacking. Happy to remove that if its just adding noise atm.
2021-11-16Fix await suggestion betterMichael Goulet-19/+26
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-14Improve diagnostics when a static lifetime is expectedLucas Kent-41/+24
2021-11-11Use `associated_item_def_ids` moreMatthew Jasper-7/+1
2021-11-11Remove unused field of `RegionVariableOrigin`Matthew Jasper-3/+3
2021-11-11Auto merge of #90648 - matthewjasper:assoc-item-cleanup, r=cjgillotbors-47/+25
Assoc item cleanup This removes some fields from ObligationCauseCode Split out of #90639
2021-11-09Rollup merge of #89561 - nbdd0121:const_typeck, r=nikomatsakisMatthias Krüger-4/+4
Type inference for inline consts Fixes #78132 Fixes #78174 Fixes #81857 Fixes #89964 Perform type checking/inference of inline consts in the same context as the outer def, similar to what is currently done to closure. Doing so would require `closure_base_def_id` of the inline const to return the outer def, and since `closure_base_def_id` can be called on non-local crate (and thus have no HIR available), a new `DefKind` is created for inline consts. The type of the generated anon const can capture lifetime of outer def, so we couldn't just use the typeck result as the type of the inline const's def. Closure has a similar issue, and it uses extra type params `CK, CS, U` to capture closure kind, input/output signature and upvars. I use a similar approach for inline consts, letting it have an extra type param `R`, and then `typeof(InlineConst<[paremt generics], R>)` would just be `R`. In borrowck region requirements are also propagated to the outer MIR body just like it's currently done for closure. With this PR, inline consts in expression position are quitely usable now; however the usage in pattern position is still incomplete -- since those does not remain in the MIR borrowck couldn't verify the lifetime there. I have left an ignored test as a FIXME. Some disucssions can be found on [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/inline.20consts.20typeck). cc `````@spastorino````` `````@lcnr````` r? `````@nikomatsakis````` `````@rustbot````` label A-inference F-inline_const T-compiler
2021-11-08fmtDeadbeef-8/+3
2021-11-08Make select_* methods return Vec for TraitEngineDeadbeef-6/+6
2021-11-07more clippy fixesMatthias Krüger-1/+1
2021-11-07Remove some fields from `ObligationCauseCode`Matthew Jasper-47/+25
2021-11-07Rename functions reflect that inline const is also "typeck_child"Gary Guo-4/+4
2021-11-06Auto merge of #89970 - jackh726:gats_diagnostics, r=nikomatsakisbors-3/+18
Implementation of GATs outlives lint See #87479 for background. Closes #87479 The basic premise of this lint/error is to require the user to write where clauses on a GAT when those bounds can be implied or proven from any function on the trait returning that GAT. ## Intuitive Explanation (Attempt) ## Let's take this trait definition as an example: ```rust trait Iterable { type Item<'x>; fn iter<'a>(&'a self) -> Self::Item<'a>; } ``` Let's focus on the `iter` function. The first thing to realize is that we know that `Self: 'a` because of `&'a self`. If an impl wants `Self::Item` to contain any data with references, then those references must be derived from `&'a self`. Thus, they must live only as long as `'a`. Furthermore, because of the `Self: 'a` implied bound, they must live only as long as `Self`. Since it's `'a` is used in place of `'x`, it is reasonable to assume that any value of `Self::Item<'x>`, and thus `'x`, will only be able to live as long as `Self`. Therefore, we require this bound on `Item` in the trait. As another example: ```rust trait Deserializer<T> { type Out<'x>; fn deserialize<'a>(&self, input: &'a T) -> Self::Out<'a>; } ``` The intuition is similar here, except rather than a `Self: 'a` implied bound, we have a `T: 'a` implied bound. Thus, the data on `Self::Out<'a>` is derived from `&'a T`, and thus it is reasonable to expect that the lifetime `'x` will always be less than `T`. ## Implementation Algorithm ## * Given a GAT `<P0 as Trait<P1..Pi>>::G<Pi...Pn>` declared as `trait T<A1..Ai> for A0 { type G<Ai...An>; }` used in return type of one associated function `F` * Given env `E` (including implied bounds) for `F` * For each lifetime parameter `'a` in `P0...Pn`: * For each other type parameter `Pi != 'a` in `P0...Pn`: // FIXME: this include of lifetime parameters too * If `E => (P: 'a)`: * Require where clause `Ai: 'a` ## Follow-up questions ## * What should we do when we don't pass params exactly? For this example: ```rust trait Des { type Out<'x, D>; fn des<'z, T>(&self, data: &'z Wrap<T>) -> Self::Out<'z, Wrap<T>>; } ``` Should we be requiring a `D: 'x` clause? We pass `Wrap<T>` as `D` and `'z` as `'x`, and should be able to prove that `Wrap<T>: 'z`. r? `@nikomatsakis`
2021-11-03Add beginner friendly lifetime elision hint to E0623Nilstrieb-8/+86
Suggest adding a new lifetime parameter when two elided lifetimes should match up but don't Issue #90170 This also changes the tests introduced by the previous commits because of another rustc issue (#90258)
2021-10-30Rollup merge of #90395 - b-naber:const-expr-type-relation, r=oli-obkMatthias Krüger-9/+20
Restrict liveness of mutable borrow of inner infcx in ConstInferUnifier::consts Fixes https://github.com/rust-lang/rust/issues/89304 r? ``@oli-obk``
2021-10-29don't mutably borrow inner infcx in all of ConstInferUnifier::constsb-naber-9/+20
2021-10-29Auto merge of #90380 - Mark-Simulacrum:revert-89558-query-stable-lint, r=lcnrbors-1/+0
Revert "Add rustc lint, warning when iterating over hashmaps" Fixes perf regressions introduced in https://github.com/rust-lang/rust/pull/90235 by temporarily reverting the relevant PR.
2021-10-28Revert "Add rustc lint, warning when iterating over hashmaps"Mark Rousskov-1/+0
2021-10-28Move instantiate_opaque_types to rustc_infer.Oli Scherer-2/+278
It does not depend on anything from rustc_trait_selection anymore.
2021-10-28Move some functions into `rustc_infer`.Oli Scherer-1/+315
They don't depend on trait selection anymore, so there is no need for an extension trait.
2021-10-24Rollup merge of #89558 - lcnr:query-stable-lint, r=estebankMatthias Krüger-0/+1
Add rustc lint, warning when iterating over hashmaps r? rust-lang/wg-incr-comp
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-22nice_region_error: Include lifetime placeholders in error outputMichael Howell-11/+48
As you can see in src/test/ui/traits/self-without-lifetime-constraint.stderr you can get very confusing type names if you don't have this. Fixes #87763
2021-10-22Document flip polaritySantiago Pastorino-0/+3
2021-10-21Rollup merge of #90071 - cjgillot:no-blocks, r=oli-obkYuki Okushi-3/+2
Remove hir::map::blocks and use FnKind instead The principal tool is `FnLikeNode`, which is not often used and can be easily implemented using `rustc_hir::intravisit::FnKind`.
2021-10-20Add TraitObligation::polarity() for better encapsulationSantiago Pastorino-0/+4
2021-10-20Consider negative polarity on overlap checkSantiago Pastorino-1/+12
2021-10-19Replace FnLikeNode by FnKind.Camille GILLOT-3/+2
2021-10-19Auto merge of #89933 - est31:let_else, r=michaelwoeristerbors-3/+2
Adopt let_else across the compiler This performs a substitution of code following the pattern: ``` let <id> = if let <pat> = ... { identity } else { ... : ! }; ``` To simplify it to: ``` let <pat> = ... { identity } else { ... : ! }; ``` By adopting the `let_else` feature (cc #87335). The PR also updates the syn crate because the currently used version of the crate doesn't support `let_else` syntax yet. Note: Generally I'm the person who *removes* usages of unstable features from the compiler, not adds more usages of them, but in this instance I think it hopefully helps the feature get stabilized sooner and in a better state. I have written a [comment](https://github.com/rust-lang/rust/issues/87335#issuecomment-944846205) on the tracking issue about my experience and what I feel could be improved before stabilization of `let_else`.
2021-10-18Auto merge of #89229 - oli-obk:i_love_inferctxt, r=jackh726bors-213/+9
Remove redundant member-constraint check impl trait will, for each lifetime in the hidden type, register a "member constraint" that says the lifetime must be equal or outlive one of the lifetimes of the impl trait. These member constraints will be solved by borrowck But, as you can see in the big red block of removed code, there was an ad-hoc check for member constraints happening at the site where they get registered. This check had some minor effects on diagnostics, but will fall down on its feet with my big type alias impl trait refactor. So we removed it and I pulled the removal out into a (hopefully) reviewable PR that works on master directly.
2021-10-18Member constraints already covered all of E0482 already, so that error never ↵Oli Scherer-24/+0
occurred anymore
2021-10-18Remove unused enum variantOli Scherer-24/+1
2021-10-18Remove regionck member constraint handling and leave it to mir borrowckOli Scherer-162/+1
2021-10-16Change outlives clause checking algorithmjackh726-3/+18
2021-10-16Rollup merge of #89915 - jackh726:outlives_cleanup, r=nikomatsakisMatthias Krüger-5/+221
Some outlives cleanup No semantic changes here, only moving code around + using `LocalDefId` instead of `HirId` r? ````@nikomatsakis````
2021-10-16Adopt let_else across the compilerest31-3/+2
This performs a substitution of code following the pattern: let <id> = if let <pat> = ... { identity } else { ... : ! }; To simplify it to: let <pat> = ... { identity } else { ... : ! }; By adopting the let_else feature.
2021-10-15Document the new logicOli Scherer-0/+5
2021-10-15Remove a now-unused traitOli Scherer-23/+0
2021-10-15Equality of regions is not just on identity, but if both regions outlive ↵Oli Scherer-1/+9
each other