about summary refs log tree commit diff
path: root/compiler/rustc_infer/src/infer
AgeCommit message (Collapse)AuthorLines
2023-11-22Rollup merge of #118147 - Nilstrieb:no-redundant-casts, r=WaffleLapkinMichael Goulet-11/+7
Fix some unnecessary casts `x clippy compiler -Aclippy::all -Wclippy::unnecessary_cast --fix` with some manual review to ensure every fix is correct.
2023-11-22Replace `no_ord_impl` with `orderable`.Nicholas Nethercote-0/+2
Similar to the previous commit, this replaces `newtype_index`'s opt-out `no_ord_impl` attribute with the opt-in `orderable` attribute.
2023-11-21Fix some unnecessary castsNilstrieb-11/+7
`x clippy compiler -Aclippy::all -Wclippy::unnecessary_cast --fix` with some manual review to ensure every fix is correct.
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-25/+25
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
2023-11-21Restore closure-kind error messagesMichael Goulet-2/+4
2023-11-20Don't require intercrate mode for negative coherenceMichael Goulet-2/+9
2023-11-19Make regionck care about placeholders in outlives componentsMichael Goulet-8/+41
2023-11-17Rollup merge of #117549 - DaniPopes:more-copied, r=b-naberMatthias Krüger-1/+1
Use `copied` instead of manual `map`
2023-11-15Re-format code with new rustfmtMark Rousskov-2/+5
2023-11-14review + fix CIlcnr-2/+2
2023-11-14finish `RegionKind` renamelcnr-51/+58
- `ReFree` -> `ReLateParam` - `ReEarlyBound` -> `ReEarlyParam`
2023-11-14Auto merge of #117773 - nnethercote:rm-Zperf-stats, r=wesleywiserbors-7/+0
Remove `-Zperf-stats`. The included measurements have varied over the years. At one point there were quite a few more, but #49558 deleted a lot that were no longer used. Today there's just four, and it's a motley collection that doesn't seem particularly valuable. I think it has been well and truly subsumed by self-profiling, which collects way more data. r? `@wesleywiser`
2023-11-13continue renaminglcnr-14/+14
- `RegionVariableOrigin::~~Late~~BoundRegion` - `~~Late~~BoundRegionConversionTime`
2023-11-13rename `ReLateBound` to `ReBound`lcnr-28/+28
other changes: - `Region::new_late_bound` -> `Region::new_bound` - `Region::is_late_bound` -> `Region::is_bound`
2023-11-13Remove `-Zperf-stats`.Nicholas Nethercote-7/+0
The included measurements have varied over the years. At one point there were quite a few more, but #49558 deleted a lot that were no longer used. Today there's just four, and it's a motley collection that doesn't seem particularly valuable. I think it has been well and truly subsumed by self-profiling, which collects way more data.
2023-11-04fallback for `construct_generic_bound_failure`bohan-8/+12
2023-11-03compiler: use `copied` instead of manual `map`DaniPopes-1/+1
2023-11-03Auto merge of #117507 - nnethercote:rustc_span, r=Nilstriebbors-2/+2
`rustc_span` cleanups Just some things I found while looking over this crate. r? `@oli-obk`
2023-11-02Don't check for alias bounds in liveness when aliases have escaping bound varsMichael Goulet-1/+9
2023-11-02Minimize `pub` usage in `source_map.rs`.Nicholas Nethercote-2/+2
Most notably, this commit changes the `pub use crate::*;` in that file to `use crate::*;`. This requires a lot of `use` items in other crates to be adjusted, because everything defined within `rustc_span::*` was also available via `rustc_span::source_map::*`, which is bizarre. The commit also removes `SourceMap::span_to_relative_line_string`, which is unused.
2023-10-29Auto merge of #116733 - compiler-errors:alias-liveness-but-this-time-sound, ↵bors-0/+124
r=aliemjay Consider alias bounds when computing liveness in NLL (but this time sound hopefully) This is a revival of #116040, except removing the changes to opaque lifetime captures check to make sure that we're not triggering any unsoundness due to the lack of general existential regions and the currently-existing `ReErased` hack we use instead. r? `@aliemjay` -- I appreciate you pointing out the unsoundenss in the previous iteration of this PR, and I'd like to hear that you're happy with this iteration of this PR before this goes back into FCP :> Fixes #116794 as well --- (mostly copied from #116040 and reworked slightly) # Background Right now, liveness analysis in NLL is a bit simplistic. It simply walks through all of the regions of a type and marks them as being live at points. This is problematic in the case of aliases, since it requires that we mark **all** of the regions in their args[^1] as live, leading to bugs like #42940. In reality, we may be able to deduce that fewer regions are allowed to be present in the projected type (or "hidden type" for opaques) via item bounds or where clauses, and therefore ideally, we should be able to soundly require fewer regions to be live in the alias. For example: ```rust trait Captures<'a> {} impl<T> Captures<'_> for T {} fn capture<'o>(_: &'o mut ()) -> impl Sized + Captures<'o> + 'static {} fn test_two_mut(mut x: ()) { let _f1 = capture(&mut x); let _f2 = capture(&mut x); //~^ ERROR cannot borrow `x` as mutable more than once at a time } ``` In the example above, we should be able to deduce from the `'static` bound on `capture`'s opaque that even though `'o` is a captured region, it *can never* show up in the opaque's hidden type, and can soundly be ignored for liveness purposes. # The Fix We apply a simple version of RFC 1214's `OutlivesProjectionEnv` and `OutlivesProjectionTraitDef` rules to NLL's `make_all_regions_live` computation. Specifically, when we encounter an alias type, we: 1. Look for a unique outlives bound in the param-env or item bounds for that alias. If there is more than one unique region, bail, unless any of the outlives bound's regions is `'static`, and in that case, prefer `'static`. If we find such a unique region, we can mark that outlives region as live and skip walking through the args of the opaque. 2. Otherwise, walk through the alias's args recursively, as we do today. ## Limitation: Multiple choices This approach has some limitations. Firstly, since liveness doesn't use the same type-test logic as outlives bounds do, we can't really try several options when we're faced with a choice. If we encounter two unique outlives regions in the param-env or bounds, we simply fall back to walking the opaque via its args. I expect this to be mostly mitigated by the special treatment of `'static`, and can be fixed in a forwards-compatible by a more sophisticated analysis in the future. ## Limitation: Opaque hidden types Secondly, we do not employ any of these rules when considering whether the regions captured by a hidden type are valid. That causes this code (cc #42940) to fail: ```rust trait Captures<'a> {} impl<T> Captures<'_> for T {} fn a() -> impl Sized + 'static { b(&vec![]) } fn b<'o>(_: &'o Vec<i32>) -> impl Sized + Captures<'o> + 'static {} ``` We need to have existential regions to avoid [unsoundness](https://github.com/rust-lang/rust/pull/116040#issuecomment-1751628189) when an opaque captures a region which is not represented in its own substs but which outlives a region that does. ## Read more Context: https://github.com/rust-lang/rust/pull/115822#issuecomment-1731153952 (for the liveness case) More context: https://github.com/rust-lang/rust/issues/42940#issuecomment-455198309 (for the opaque capture case, which this does not fix) [^1]: except for bivariant region args in opaques, which will become less relevant when we move onto edition 2024 capture semantics for opaques.
2023-10-27Account for type param from other item in `note_and_explain`Esteban Küber-43/+61
Fix #89868.
2023-10-26Restrict param constraint suggestionEsteban Küber-4/+7
When encountering an associated item with a type param that could be constrained, do not look at the parent item if the type param comes from the associated item. Fix #117209.
2023-10-25Refactor away the need for some `descr` methods.Oli Scherer-10/+11
Instead we use `Display` impls and their `alternate` render scheme to decide whether we want backticks or not.
2023-10-24Get rid of 'tcx on ConstVid, EffectVidMichael Goulet-66/+78
2023-10-24Rollup merge of #117091 - compiler-errors:debug, r=lcnrMatthias Krüger-1/+3
`OptWithInfcx` naming nits, trait bound simplifications * Use an associated type `Interner` on `InferCtxtLike` to remove a redundant interner parameter (`I: Interner, Infcx: InferCtxtLike<I>` -> `Infcx: InferCtxtLike`). * Remove double-`Option` between `infcx: Option<Infcx>` and `fn universe_of_ty(&self, ty: ty::InferTy) -> Option<ty::UniverseIndex>`. We don't need the infcx to be optional if we can provide a "noop" (`NoInfcx`) implementation that just always returns `None` for universe index. * Also removes the `core::convert::Infallible` implementation which I found a bit weird... * Some naming nits with params. * I found `InferCtxt` + `InfCtx` and `Infcx` to be a lot of different ways to spell "inference context", so I got rid of the `InfCtx` type parameter name in favor of `Infcx` which is a more standard name. * I found `OptWithInfcx` to be a bit redundant -> `WithInfcx`. I'm making these changes because I intend to reuse the `InferCtxtLike` trait for uplifting the canonicalizer into a new trait -- conveniently, the information I need for uplifting the canonicalizer also is just the universe information of a type var, so it's super convenient 😸 r? `@BoxyUwU` or `@lcnr`
2023-10-23Rollup merge of #116859 - Nilstrieb:more-more-funny-pretty-printers, r=oli-obkMatthias Krüger-41/+51
Make `ty::print::Printer` take `&mut self` instead of `self` based on #116815 This simplifies the code by removing all the `self` assignments and makes the flow of data clearer - always into the printer. Especially in v0 mangling, which already used `&mut self` in some places, it gets a lot more uniform.
2023-10-23Remove redundant type parameterMichael Goulet-1/+3
2023-10-21Rollup merge of #106601 - estebank:match-semi, r=cjgillotMatthias Krüger-0/+13
Suggest `;` after bare `match` expression E0308 Fix #72634.
2023-10-21Make `ty::print::Printer` take `&mut self` instead of `self`Nilstrieb-41/+51
This simplifies the code by removing all the `self` assignments and makes the flow of data clearer - always into the printer. Especially in v0 mangling, which already used `&mut self` in some places, it gets a lot more uniform.
2023-10-20s/generator/coroutine/Oli Scherer-11/+11
2023-10-20s/Generator/Coroutine/Oli Scherer-11/+11
2023-10-19Rollup merge of #116908 - estebank:issue-78206, r=compiler-errorsLeón Orell Valerian Liehr-4/+19
Tweak wording of type errors involving type params Fix #78206.
2023-10-18Tweak wording of type errors involving type paramsEsteban Küber-4/+19
Fix #78206.
2023-10-18Don't ICE when encountering unresolved regions in fully_resolveMichael Goulet-7/+20
2023-10-18Auto merge of #116885 - aliemjay:rollup-plbeppt, r=aliemjaybors-63/+59
Rollup of 5 pull requests Successful merges: - #116812 (Disable missing_copy_implementations lint on non_exhaustive types) - #116856 (Disable effects in libcore again) - #116865 (Suggest constraining assoc types in more cases) - #116870 (Don't compare host param by name) - #116879 (revert #114586) r? `@ghost` `@rustbot` modify labels: rollup
2023-10-18Rollup merge of #116879 - aliemjay:revert-opaque-bubble, r=oli-obkAli MJ Al-Nasrawy-19/+1
revert #114586 Reverts #114586. cc #116877 (not closing until this gets a beta backport) fixes #116684 fixes https://github.com/rust-lang/rust/pull/114586#issuecomment-1751967321 r? `@oli-obk` or `@lcnr`
2023-10-18revert rust-lang/rust#114586Ali MJ Al-Nasrawy-19/+1
2023-10-17Suggest constraining assoc types in more casesEsteban Küber-44/+58
Fix #46969.
2023-10-17Remove `Print::Error`Nilstrieb-2/+2
All printing goes through `fmt::Error` now.
2023-10-17Remove `Printer::Error`Nilstrieb-24/+20
It's always a `fmt::Error` except in some cases where it was `!`, but we're not really winning anything in that case.
2023-10-17Remove `Print::Output`Nilstrieb-2/+2
Now that `Printer` doesn't have subprinters anymore, the output of a printing operation is always the same.
2023-10-17Remove "subprinter" types from `Printer`Nilstrieb-25/+24
These are `Self` in almost all printers except one, which can just store the state as a field instead. This simplifies the printer and allows for further simplifications, for example using `&mut self` instead of passing around the printer.
2023-10-17Use a visitor that could be reused by opaque type capture check laterMichael Goulet-0/+124
2023-10-13Format all the let chains in compilerMichael Goulet-164/+248
2023-10-11Suggest `;` after bare `match` expression E0308Esteban Küber-0/+13
Fix #72634.
2023-10-11Rollup merge of #116219 - compiler-errors:relate-alias-ty-with-variance, r=lcnrMatthias Krüger-2/+2
Relate alias ty with variance In the new solver, turns out that the subst-relate branch of the alias-relate predicate was relating args invariantly even for opaques, which have variance :skull:. This change is a bit more invasive, but I'd rather not special-case it [here](https://github.com/rust-lang/rust/blob/aeaa5c30e5c9041264a2e8314b68ad84c2dc3169/compiler/rustc_trait_selection/src/solve/alias_relate.rs#L171-L190) and then have it break elsewhere. I'm doing a perf run to see if the extra call to `def_kind` is that expensive, if it is, I'll reconsider. r? ``@lcnr``
2023-10-08remove trailing dotsAli MJ Al-Nasrawy-1/+1
2023-10-08always show and explain sub regionAli MJ Al-Nasrawy-37/+23
2023-10-08improve the suggestion of generic_bound_failureAli MJ Al-Nasrawy-299/+201