about summary refs log tree commit diff
path: root/compiler/rustc_hir_analysis/src
AgeCommit message (Collapse)AuthorLines
2024-04-15Validation and other thingsMichael Goulet-4/+140
2024-04-15Lower and resolve precise captures in HIRMichael Goulet-0/+25
2024-04-15Rollup merge of #123924 - compiler-errors:tuple-sugg, r=estebankMichael Goulet-65/+9
Fix various bugs in `ty_kind_suggestion` Consolidates two implementations of `ty_kind_suggestion` Fixes some misuse of the empty param-env Fixes a problem where we suggested `(42)` instead of `(42,)` for tuple suggestions Suggest a value when `return;`, making it consistent with `break;` Fixes #123906
2024-04-14Don't leak unnameable types in -> _ recoverMichael Goulet-17/+12
2024-04-14Consolidate two copies of ty_kind_suggestionMichael Goulet-65/+9
2024-04-14Rollup merge of #123898 - fmease:gci-cmp-impl-item-lt-params, r=compiler-errorsMatthias Krüger-4/+2
Generic associated consts: Check regions earlier when comparing impl with trait item def Fixes #123836. r? compiler-errors or compiler
2024-04-13Check regions earlier when comparing impl with trait item defLeón Orell Valerian Liehr-4/+2
2024-04-13remove some ancient debug output, looks unused?klensy-3/+0
2024-04-11remove some things that do not need to beMatthias Krüger-1/+1
2024-04-11Rollup merge of #123774 - Lee-Janggun:master, r=lqdMatthias Krüger-1/+1
Fix typo MaybeUnit -> MaybeUninit
2024-04-11Rollup merge of #123738 - spastorino:reuse-lower-const-param, r=compiler-errorsMatthias Krüger-5/+6
Call lower_const_param instead of duplicating the code Follow up of #123689 r? `@oli-obk` I had this commit in my old branch that I had forgotten about, `@fmease` pointed about this in #123689 I've left the branches that are not `Range` as do nothing as that's what we are currently doing but maybe we want to err or something.
2024-04-11Call lower_const_param instead of duplicating the codeSantiago Pastorino-5/+6
2024-04-11Rollup merge of #123704 - estebank:diag-changes, r=compiler-errorsMatthias Krüger-11/+62
Tweak value suggestions in `borrowck` and `hir_analysis` Unify the output of `suggest_assign_value` and `ty_kind_suggestion`. Ideally we'd make these a single function, but doing so would likely require modify the crate dependency tree.
2024-04-11Fix small typoJanggun Lee-1/+1
2024-04-10Handle more cases of "values to suggest" given a typeEsteban Küber-0/+12
Add handling for `String`, `Box`, `Option` and `Result`.
2024-04-10Use suggest_impl_trait in return type suggestionMichael Goulet-42/+56
2024-04-10Handle more cases of value suggestionsEsteban Küber-10/+38
2024-04-10Auto merge of #121346 - m-ou-se:temp-lifetime-if-else-match, r=compiler-errorsbors-0/+13
Propagate temporary lifetime extension into if and match. This PR makes this work: ```rust let a = if true { ..; &temp() // used to error, but now gets lifetime extended } else { ..; &temp() // used to error, but now gets lifetime extended }; ``` and ```rust let a = match () { _ => { ..; &temp() // used to error, but now gets lifetime extended } }; ``` to make it consistent with: ```rust let a = { ..; &temp() // lifetime is extended }; ``` This is one small part of [the temporary lifetimes work](https://github.com/rust-lang/lang-team/issues/253). This part is backwards compatible (so doesn't need be edition-gated), because all code affected by this change previously resulted in a hard error.
2024-04-10Rollup merge of #123689 - spastorino:pattern_types_const_generics, r=oli-obkGuillaume Gomez-0/+18
Add const generics support for pattern types r? `@oli-obk`
2024-04-09Tweak value suggestions in `borrowck` and `hir_analysis`Esteban Küber-5/+16
Unify the output of `suggest_assign_value` and `ty_kind_suggestion`. Ideally we'd make these a single function, but doing so would likely require modify the crate dependency tree.
2024-04-09Handle const generic pattern typesSantiago Pastorino-0/+18
2024-04-09Clarifying commentMichael Goulet-3/+9
2024-04-09Split back out unused_lifetimes -> redundant_lifetimesMichael Goulet-2/+2
2024-04-09Lint redundant lifetimes in impl headerMichael Goulet-5/+6
2024-04-09Move check to wfcheckMichael Goulet-0/+128
2024-04-09Actually, just reuse the UNUSED_LIFETIMES lintMichael Goulet-26/+0
2024-04-09Silence some follow-up errors on trait impls in case the trait has ↵Oli Scherer-2/+8
conflicting or otherwise incoherent impls
2024-04-09Auto merge of #123631 - oli-obk:fail_slow, r=jieyouxubors-7/+4
Ensure we do not accidentally insert new early aborts in the analysis passes pulling the infallible part out into a separate function makes sure that someone needs to change the signature in order to regress this. We only want to stop compilation in the presence of errors after all analyses are done, but before we start running lints. per-item we can still stop doing work if previous queries returned errors, but that's a separate story.
2024-04-09Rollup merge of #123648 - oli-obk:pattern_types_syntax, r=compiler-errorsMatthias Krüger-1/+5
Avoid ICEing without the pattern_types feature gate fixes #123643
2024-04-08Auto merge of #122077 - oli-obk:eager_opaque_checks4, r=lcnrbors-6/+3
Pass list of defineable opaque types into canonical queries This eliminates `DefiningAnchor::Bubble` for good and brings the old solver closer to the new one wrt cycles and nested obligations. At that point the difference between `DefiningAnchor::Bind([])` and `DefiningAnchor::Error` was academic. We only used the difference for some sanity checks, which actually had to be worked around in places, so I just removed `DefiningAnchor` entirely and just stored the list of opaques that may be defined. fixes #108498 fixes https://github.com/rust-lang/rust/issues/116877 * [x] run crater - https://github.com/rust-lang/rust/pull/122077#issuecomment-2013293931
2024-04-08Avoid ICEing without the `pattern_types` feature gateOli Scherer-1/+5
2024-04-08Eliminate `DefiningAnchor` now that is just a single-variant enumOli Scherer-6/+3
2024-04-08Ensure we do not accidentally insert new early aborts in the analysis passesOli Scherer-7/+4
2024-04-08Actually create ranged int types in the type system.Oli Scherer-10/+92
2024-04-08Start handling pattern types at the HIR -> Ty conversion boundaryOli Scherer-2/+21
2024-04-08Thread pattern types through the HIROli Scherer-0/+1
2024-04-04cache type info for ParamEnvLukas Markeffsky-7/+4
2024-04-04Auto merge of #123240 - compiler-errors:assert-args-compat, r=fmeasebors-17/+27
Assert that args are actually compatible with their generics, rather than just their count Right now we just check that the number of args is right, rather than actually checking the kinds. Uplift a helper fn that I wrote from trait selection to do just that. Found a couple bugs along the way. r? `@lcnr` or `@fmease` (or anyone really lol)
2024-04-03Rollup merge of #123419 - petrochenkov:zeroindex, r=compiler-errorsMatthias Krüger-7/+7
rustc_index: Add a `ZERO` constant to index types It is commonly used.
2024-04-03Rollup merge of #122964 - joboet:pointer_expose, r=AmanieuMatthias Krüger-1/+1
Rename `expose_addr` to `expose_provenance` `expose_addr` is a bad name, an address is just a number and cannot be exposed. The operation is actually about the provenance of the pointer. This PR thus changes the name of the method to `expose_provenance` without changing its return type. There is sufficient precedence for returning a useful value from an operation that does something else without the name indicating such, e.g. [`Option::insert`](https://doc.rust-lang.org/nightly/std/option/enum.Option.html#method.insert) and [`MaybeUninit::write`](https://doc.rust-lang.org/nightly/std/mem/union.MaybeUninit.html#method.write). Returning the address is merely convenient, not a fundamental part of the operation. This is implied by the fact that integers do not have provenance since ```rust let addr = ptr.addr(); ptr.expose_provenance(); let new = ptr::with_exposed_provenance(addr); ``` must behave exactly like ```rust let addr = ptr.expose_provenance(); let new = ptr::with_exposed_provenance(addr); ``` as the result of `ptr.expose_provenance()` and `ptr.addr()` is the same integer. Therefore, this PR removes the `#[must_use]` annotation on the function and updates the documentation to reflect the important part. ~~An alternative name would be `expose_provenance`. I'm not at all opposed to that, but it makes a stronger implication than we might want that the provenance of the pointer returned by `ptr::with_exposed_provenance`[^1] is the same as that what was exposed, which is not yet specified as such IIUC. IMHO `expose` does not make that connection.~~ A previous version of this PR suggested `expose` as name, libs-api [decided on](https://github.com/rust-lang/rust/pull/122964#issuecomment-2033194319) `expose_provenance` to keep the symmetry with `with_exposed_provenance`. CC `@RalfJung` r? libs-api [^1]: I'm using the new name for `from_exposed_addr` suggested by #122935 here.
2024-04-03rustc_index: Add a `ZERO` constant to index typesVadim Petrochenkov-7/+7
It is commonly used.
2024-04-03Don't fill non-ty args with ty::ErrorMichael Goulet-17/+27
2024-04-03Rollup merge of #123382 - compiler-errors:assert-fndef-kind, r=fmeaseMatthias Krüger-2/+2
Assert `FnDef` kind Only found one bug, where we were using the variant def id rather than its ctor def id to make the `FnDef` for a `type_of` r? fmease
2024-04-03rename `expose_addr` to `expose_provenance`joboet-1/+1
2024-04-02Rollup merge of #122935 - RalfJung:with-exposed-provenance, r=AmanieuJacob Pratt-1/+1
rename ptr::from_exposed_addr -> ptr::with_exposed_provenance As discussed on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/To.20expose.20or.20not.20to.20expose/near/427757066). The old name, `from_exposed_addr`, makes little sense as it's not the address that is exposed, it's the provenance. (`ptr.expose_addr()` stays unchanged as we haven't found a better option yet. The intended interpretation is "expose the provenance and return the address".) The new name nicely matches `ptr::without_provenance`.
2024-04-02Rollup merge of #122865 - surechen:refactor_astconv_error_report_20240321, ↵Jacob Pratt-342/+448
r=lcnr Split hir ty lowerer's error reporting code in check functions to mod errors. Move some error report codes to mod `astconv/errors.rs` r? `@lcnr`
2024-04-02Auto merge of #123385 - matthiaskrgr:rollup-v69vjbn, r=matthiaskrgrbors-5/+10
Rollup of 8 pull requests Successful merges: - #123198 (Add fn const BuildHasherDefault::new) - #123226 (De-LLVM the unchecked shifts [MCP#693]) - #123302 (Make sure to insert `Sized` bound first into clauses list) - #123348 (rustdoc: add a couple of regression tests) - #123362 (Check that nested statics in thread locals are duplicated per thread.) - #123368 (CFI: Support non-general coroutines) - #123375 (rustdoc: synthetic auto trait impls: accept unresolved region vars for now) - #123378 (Update sysinfo to 0.30.8) Failed merges: - #123349 (Fix capture analysis for by-move closure bodies) r? `@ghost` `@rustbot` modify labels: rollup
2024-04-02Rollup merge of #123302 - compiler-errors:sized-bound-first, r=estebankMatthias Krüger-2/+8
Make sure to insert `Sized` bound first into clauses list #120323 made it so that we don't insert an implicit `Sized` bound whenever we see an *explicit* `Sized` bound. However, since the code that inserts implicit sized bounds puts the bound as the *first* in the list, that means that it had the **side-effect** of possibly meaning we check `Sized` *after* checking other trait bounds. If those trait bounds result in ambiguity or overflow or something, it may change how we winnow candidates. (**edit: SEE** #123303) This is likely the cause for the regression in https://github.com/rust-lang/rust/issues/123279#issuecomment-2028899598, since the impl... ```rust impl<T: Job + Sized> AsJob for T { // <----- changing this to `Sized + Job` or just `Job` (which turns into `Sized + Job`) will FIX the issue. } ``` ...looks incredibly suspicious. Fixes [after beta-backport] #123279. Alternative is to revert #120323. I don't have a strong opinion about this, but think it may be nice to keep the diagnostic changes around.
2024-04-02Rollup merge of #123226 - scottmcm:u32-shifts, r=WaffleLapkinMatthias Krüger-3/+2
De-LLVM the unchecked shifts [MCP#693] This is just one part of the MCP (https://github.com/rust-lang/compiler-team/issues/693), but it's the one that IMHO removes the most noise from the standard library code. Seems net simpler this way, since MIR already supported heterogeneous shifts anyway, and thus it's not more work for backends than before. r? WaffleLapkin
2024-04-02Auto merge of #118310 - scottmcm:three-way-compare, r=davidtwcobors-0/+5
Add `Ord::cmp` for primitives as a `BinOp` in MIR Update: most of this OP was written months ago. See https://github.com/rust-lang/rust/pull/118310#issuecomment-2016940014 below for where we got to recently that made it ready for review. --- There are dozens of reasonable ways to implement `Ord::cmp` for integers using comparison, bit-ops, and branches. Those differences are irrelevant at the rust level, however, so we can make things better by adding `BinOp::Cmp` at the MIR level: 1. Exactly how to implement it is left up to the backends, so LLVM can use whatever pattern its optimizer best recognizes and cranelift can use whichever pattern codegens the fastest. 2. By not inlining those details for every use of `cmp`, we drastically reduce the amount of MIR generated for `derive`d `PartialOrd`, while also making it more amenable to MIR-level optimizations. Having extremely careful `if` ordering to μoptimize resource usage on broadwell (#63767) is great, but it really feels to me like libcore is the wrong place to put that logic. Similarly, using subtraction [tricks](https://graphics.stanford.edu/~seander/bithacks.html#CopyIntegerSign) (#105840) is arguably even nicer, but depends on the optimizer understanding it (https://github.com/llvm/llvm-project/issues/73417) to be practical. Or maybe [bitor is better than add](https://discourse.llvm.org/t/representing-in-ir/67369/2?u=scottmcm)? But maybe only on a future version that [has `or disjoint` support](https://discourse.llvm.org/t/rfc-add-or-disjoint-flag/75036?u=scottmcm)? And just because one of those forms happens to be good for LLVM, there's no guarantee that it'd be the same form that GCC or Cranelift would rather see -- especially given their very different optimizers. Not to mention that if LLVM gets a spaceship intrinsic -- [which it should](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Suboptimal.20inlining.20in.20std.20function.20.60binary_search.60/near/404250586) -- we'll need at least a rustc intrinsic to be able to call it. As for simplifying it in Rust, we now regularly inline `{integer}::partial_cmp`, but it's quite a large amount of IR. The best way to see that is with https://github.com/rust-lang/rust/commit/8811efa88b25b5e41d63850e6047e8257c677858#diff-d134c32d028fbe2bf835fef2df9aca9d13332dd82284ff21ee7ebf717bfa4765R113 -- I added a new pre-codegen MIR test for a simple 3-tuple struct, and this PR change it from 36 locals and 26 basic blocks down to 24 locals and 8 basic blocks. Even better, as soon as the construct-`Some`-then-match-it-in-same-BB noise is cleaned up, this'll expose the `Cmp == 0` branches clearly in MIR, so that an InstCombine (#105808) can simplify that to just a `BinOp::Eq` and thus fix some of our generated code perf issues. (Tracking that through today's `if a < b { Less } else if a == b { Equal } else { Greater }` would be *much* harder.) --- r? `@ghost` But first I should check that perf is ok with this ~~...and my true nemesis, tidy.~~