about summary refs log tree commit diff
path: root/compiler/rustc_middle/src
AgeCommit message (Collapse)AuthorLines
2023-10-28Rollup merge of #117256 - dtolnay:currentversion, r=compiler-errorsJubilee-15/+12
Parse rustc version at compile time This PR eliminates a couple awkward codepaths where it was not clear how the compiler should proceed if its own version number is incomprehensible. https://github.com/rust-lang/rust/blob/dab715641e96a61a534587fda9de1128b75b34dc/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs#L385 https://github.com/rust-lang/rust/blob/dab715641e96a61a534587fda9de1128b75b34dc/compiler/rustc_attr/src/builtin.rs#L630 We can guarantee that every compiled rustc comes with a working version number, so the ICE codepaths above shouldn't need to be written.
2023-10-27Apply suggestions from code reviewCamille Gillot-4/+7
Co-authored-by: Ralf Jung <post@ralfj.de>
2023-10-27Propagate half-open ranges through THIRNadrieril-23/+49
2023-10-27Abstract over `PatRange` boundary valueNadrieril-45/+256
2023-10-27Rollup merge of #117246 - estebank:issue-117209, r=petrochenkovMatthias Krüger-0/+28
Fix ICE: Restrict param constraint suggestion 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, fix #89868.
2023-10-27Account for type param from other item in `note_and_explain`Esteban Küber-0/+28
Fix #89868.
2023-10-27Fuse `gen` blocksOli Scherer-2/+3
2023-10-27Basic generators workOli Scherer-2/+3
2023-10-27Make `gen` blocks implement the `Iterator` traitOli Scherer-0/+15
2023-10-27Rollup merge of #117241 - compiler-errors:auto-trait-leak-cycle, r=oli-obkMatthias Krüger-0/+1
Stash and cancel cycle errors for auto trait leakage in opaques We don't need to emit a traditional cycle error when we have a selection error that explains what's going on but in more detail. We may want to augment this error to actually point out the cycle, now that the cycle error is not being emitted. We could do that by storing the set of opaques that was in the `CyclePlaceholder` that gets returned from `type_of_opaque`. r? `@oli-obk` cc `@estebank` #117235
2023-10-26Parse rustc version at compile timeDavid Tolnay-15/+12
2023-10-26Stash and cancel cycle errors for auto trait leakage in opaquesMichael Goulet-0/+1
2023-10-26Replace type flag HAS_TY_GENERATOR with HAS_TY_COROUTINELeón Orell Valerian Liehr-2/+2
2023-10-26Auto merge of #112875 - compiler-errors:negative-coherence-rework, r=lcnrbors-0/+1
Rework negative coherence to properly consider impls that only partly overlap This PR implements a modified negative coherence that handles impls that only have partial overlap. It does this by: 1. taking both impl trait refs, instantiating them with infer vars 2. equating both trait refs 3. taking the equated trait ref (which represents the two impls' intersection), and resolving any vars 4. plugging all remaining infer vars with placeholder types these placeholder-plugged trait refs can then be used normally with the new trait solver, since we no longer have to worry about the issue with infer vars in param-envs. We use the **new trait solver** to reason correctly about unnormalized trait refs (due to deferred projection equality), since this avoid having to normalize anything under param-envs with infer vars in them. This PR then additionally: * removes the `FnPtr` knowable hack by implementing proper negative `FnPtr` trait bounds for rigid types. --- An example: Consider these two partially overlapping impls: ``` impl<T, U> PartialEq<&U> for &T where T: PartialEq<U> {} impl<F> PartialEq<F> for F where F: FnPtr {} ``` Under the old algorithm, we would take one of these impls and replace it with infer vars, then try unifying it with the other impl under identity substitutions. This is not possible in either direction, since it either sets `T = U`, or tries to equate `F = &?0`. Under the new algorithm, we try to unify `?0: PartialEq<?0>` with `&?1: PartialEq<&?2>`. This gives us `?0 = &?1 = &?2` and thus `?1 = ?2`. The intersection of these two trait refs therefore looks like: `&?1: PartialEq<&?1>`. After plugging this with placeholders, we get a trait ref that looks like `&!0: PartialEq<&!0>`, with the first impl having substs `?T = ?U = !0` and the second having substs `?F = &!0`[^1]. Then we can take the param-env from the first impl, and try to prove the negated where clause of the second. We know that `&!0: !FnPtr` never holds, since it's a rigid type that is also not a fn ptr, we successfully detect that these impls may never overlap. [^1]: For the purposes of this example, I just ignored lifetimes, since it doesn't really matter.
2023-10-26Add hir::GeneratorKind::GenOli Scherer-0/+12
2023-10-25Rollup merge of #117175 - oli-obk:gen_fn_split, r=compiler-errorsMatthias Krüger-2/+6
Rename AsyncCoroutineKind to CoroutineSource pulled out of https://github.com/rust-lang/rust/pull/116447 Also refactors the printing infra of `CoroutineSource` to be ready for easily extending it with a `Gen` variant for `gen` blocks
2023-10-25Rollup merge of #117008 - compiler-errors:canonical, r=lcnrMatthias Krüger-93/+29
Uplift `Canonical` to `rustc_type_ir` I plan on moving the new trait solver's canonicalizer into either `rustc_type_ir` or a child crate. One dependency on this is lifting `Canonical<V>` to `rustc_type_ir` so we can actually name the canonicalized values. I may also later lift `CanonicalVarInfo` into the new trait solver. I can't really tell what other changes need to be done, but I'm just putting this up sooner than later since I'm almost certain it'll need to be done regardless of other design choices. There are a couple of warts introduced by this PR, since we no longer can define inherent `Canonical` impls in `rustc_middle` -- see the changes to: * `compiler/rustc_trait_selection/src/traits/query/normalize.rs` * `compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs` r? lcnr
2023-10-25Rename has_provance and tweaks comments.Camille GILLOT-8/+11
2023-10-25Refactor away the need for some `descr` methods.Oli Scherer-2/+6
Instead we use `Display` impls and their `alternate` render scheme to decide whether we want backticks or not.
2023-10-25Add a IsIdentity extension trait for CanonicalUserTypeMichael Goulet-5/+9
2023-10-25Uplift Canonical to rustc_type_irMichael Goulet-91/+23
2023-10-25Rollup merge of #117136 - compiler-errors:defid-list, r=oli-obkMatthias Krüger-1/+11
Intern `LocalDefId` list from `opaque_types_defined_by` query r? oli-obk
2023-10-25Valtrees for primitive types are fine.Camille GILLOT-2/+3
2023-10-25Complete comments.Camille GILLOT-8/+5
2023-10-25Disambiguate non-deterministic constants.Camille GILLOT-0/+34
2023-10-25Evaluate computed values to constants.Camille GILLOT-0/+12
2023-10-25Auto merge of #116993 - compiler-errors:clause-kind, r=jackh726bors-183/+78
Uplift `ClauseKind` and `PredicateKind` into `rustc_type_ir` Uplift `ClauseKind` and `PredicateKind` into `rustc_type_ir`. Blocked on #116951 r? `@ghost`
2023-10-25Auto merge of #117139 - compiler-errors:vid-lifetimes, r=BoxyUwUbors-60/+67
Get rid of `'tcx` lifetime on `ConstVid`, `EffectVid` These are simply newtyped numbers, so don't really have a reason (per se) to have a lifetime -- `TyVid` and `RegionVid` do not, for example. The only consequence of this is that we need to use a new key type for `UnifyKey` that mentions `'tcx`. This is already done for `RegionVid`, with `RegionVidKey<'tcx>`, but this `UnifyKey` trait implementation may have been the original reason to give `ConstVid` a lifetime. See the changes to `compiler/rustc_middle/src/infer/unify_key.rs` specifically. I consider the code cleaner this way, though -- we removed quite a few unnecessary `'tcx` in the process. This also makes it easier to uplift these two ids to `rustc_type_ir`, which I plan on doing in a follow-up PR. r? `@BoxyUwU`
2023-10-25Auto merge of #116482 - matthewjasper:thir-unsafeck-inline-constants, r=b-naberbors-4/+25
Fix inline const pattern unsafety checking in THIR Fix THIR unsafety checking of inline constants. - Steal THIR in THIR unsafety checking (if enabled) instead of MIR lowering. - Represent inline constants in THIR patterns.
2023-10-24Get rid of 'tcx on ConstVid, EffectVidMichael Goulet-60/+67
2023-10-24Intern LocalDefId list from opaque queryMichael Goulet-1/+11
2023-10-24Rollup merge of #117091 - compiler-errors:debug, r=lcnrMatthias Krüger-36/+36
`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-23pre-cleanupsMichael Goulet-0/+1
2023-10-23Auto merge of #117103 - matthiaskrgr:rollup-96zuuom, r=matthiaskrgrbors-316/+329
Rollup of 6 pull requests Successful merges: - #107159 (rand use getrandom for freebsd (available since 12.x)) - #116859 (Make `ty::print::Printer` take `&mut self` instead of `self`) - #117046 (return unfixed len if pat has reported error) - #117070 (rustdoc: wrap Type with Box instead of Generics) - #117074 (Remove smir from triage and add me to stablemir) - #117086 (Update .mailmap to promote my livename) r? `@ghost` `@rustbot` modify labels: rollup
2023-10-23Rollup merge of #116859 - Nilstrieb:more-more-funny-pretty-printers, r=oli-obkMatthias Krüger-316/+329
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-23Auto merge of #116033 - bvanjoi:fix-116032, r=petrochenkovbors-4/+0
report `unused_import` for empty reexports even it is pub Fixes #116032 An easy fix. r? `@petrochenkov` (Discovered this issue while reviewing #115993.)
2023-10-23Remove redundant type parameterMichael Goulet-36/+36
2023-10-23Naming nitsMichael Goulet-26/+26
2023-10-23Auto merge of #107009 - cjgillot:jump-threading, r=pnkfelixbors-0/+9
Implement jump threading MIR opt This pass is an attempt to generalize `ConstGoto` and `SeparateConstSwitch` passes into a more complete jump threading pass. This pass is rather heavy, as it performs a truncated backwards DFS on MIR starting from each `SwitchInt` terminator. This backwards DFS remains very limited, as it only walks through `Goto` terminators. It is build to support constants and discriminants, and a propagating through a very limited set of operations. The pass successfully manages to disentangle the `Some(x?)` use case and the DFA use case. It still needs a few tests before being ready.
2023-10-23Auto merge of #116849 - oli-obk:error_shenanigans, r=cjgillotbors-18/+97
Avoid a `track_errors` by bubbling up most errors from `check_well_formed` I believe `track_errors` is mostly papering over issues that a sufficiently convoluted query graph can hit. I made this change, while the actual change I want to do is to stop bailing out early on errors, and instead use this new `ErrorGuaranteed` to invoke `check_well_formed` for individual items before doing all the `typeck` logic on them. This works towards resolving https://github.com/rust-lang/rust/issues/97477 and various other ICEs, as well as allowing us to use parallel rustc more (which is currently rather limited/bottlenecked due to the very sequential nature in which we do `rustc_hir_analysis::check_crate`) cc `@SparrowLii` `@Zoxc` for the new `try_par_for_each_in` function
2023-10-23Allow `ensure` queries to return `Result<(), ErrorGuaranteed>`Oli Scherer-4/+60
2023-10-22use visibility to check unused imports and delete some stmtsbohan-4/+0
2023-10-21Auto merge of #116922 - Zalathar:unused, r=cjgillotbors-6/+0
coverage: Emit mappings for unused functions without generating stubs For a while I've been annoyed by the fact that generating coverage maps for unused functions involves generating a stub function at the LLVM level. As I suspected, generating that stub function isn't actually necessary, as long as we specifically tell LLVM about the symbol names of all the functions that have coverage mappings but weren't codegenned (due to being unused). --- There is some helper code that gets moved around in the follow-up patches, so look at the first patch to see the most important functional changes. --- `@rustbot` label +A-code-coverage
2023-10-21Rollup merge of #106601 - estebank:match-semi, r=cjgillotMatthias Krüger-0/+1
Suggest `;` after bare `match` expression E0308 Fix #72634.
2023-10-21Make `ty::print::Printer` take `&mut self` instead of `self`Nilstrieb-316/+329
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-21Implement JumpThreading pass.Camille GILLOT-0/+9
2023-10-21coverage: Change query `codegened_and_inlined_items` to a plain functionZalathar-6/+0
This query has a name that sounds general-purpose, but in fact it has coverage-specific semantics, and (fortunately) is only used by coverage code. Because it is only ever called once (from one designated CGU), it doesn't need to be a query, and we can change it to a regular function instead.
2023-10-20Uplift ClauseKind and PredicateKindMichael Goulet-183/+78
2023-10-20Rename `CoroutineKind::Gen` to `::Coroutine`Oli Scherer-7/+11
2023-10-20s/generator/coroutine/Oli Scherer-178/+179