about summary refs log tree commit diff
path: root/compiler/rustc_hir_analysis/src
AgeCommit message (Collapse)AuthorLines
2024-10-31Double check the lowered predicates in type_param_predicatesMichael Goulet-7/+24
2024-10-31Make SelfTraitThatDefines a tighter filterMichael Goulet-27/+55
2024-10-31Make predicate filter in `probe_ty_param_bounds_in_generics` more explicitMichael Goulet-17/+17
2024-10-31Auto merge of #131186 - compiler-errors:precise-capturing-borrowck, r=estebankbors-7/+17
Try to point out when edition 2024 lifetime capture rules cause borrowck issues Lifetime capture rules in 2024 are modified to capture more lifetimes, which sometimes lead to some non-local borrowck errors. This PR attempts to link these back together with a useful note pointing out the capture rule changes. This is not a blocking concern, but I'd appreciate feedback (though, again, I'd like to stress that I don't want to block this PR on this): I'm worried about this note drowning in the sea of other diagnostics that borrowck emits. I was tempted to change the level of the note to `.span_warn` just so it would show up in a different color. Thoughts? Fixes #130545 Opening as a draft first since it's stacked on #131183. r? `@ghost`
2024-10-31Encode cross-crate opaque type originMichael Goulet-7/+17
2024-10-31Auto merge of #132377 - matthiaskrgr:rollup-3p1c6hs, r=matthiaskrgrbors-9/+13
Rollup of 3 pull requests Successful merges: - #132368 (Remove `do_not_const_check` from `Iterator` methods) - #132373 (Make sure `type_param_predicates` resolves correctly for RPITIT) - #132374 (Remove dead code stemming from the old effects desugaring) r? `@ghost` `@rustbot` modify labels: rollup
2024-10-31Rollup merge of #132374 - fmease:rm-dead-eff-code, r=compiler-errorsMatthias Krüger-9/+3
Remove dead code stemming from the old effects desugaring r? project-const-traits
2024-10-31Rollup merge of #132373 - compiler-errors:rpitit-bound, r=fmeaseMatthias Krüger-0/+10
Make sure `type_param_predicates` resolves correctly for RPITIT After #132194, we end up lowering the item bounds for an RPITIT in an `ItemCtxt` whose def id is the *synthetic GAT*, not the opaque type from the HIR. This means that when we're resolving a shorthand projection like `T::Assoc`, we call the `type_param_predicates` function with the `item_def_id` of the *GAT* and not the opaque. That function operates on the HIR, and is not designed to work with the `Node::Synthetic` that gets fed for items synthesized by the compiler... This PR reuses the trick we use elsewhere in lowering, where we intercept whether an item comes from RPITIT lowering, and forwards the query off to the correct item. Fixes #132372
2024-10-31Validate associated type bounds on ?Michael Goulet-13/+25
2024-10-30Actually do validation for poly trait refs with ? modifierMichael Goulet-8/+11
2024-10-30Remove dead code stemming from the old effects desugaringLeón Orell Valerian Liehr-9/+3
2024-10-30Make sure type_param_predicates resolves correctly for RPITITMichael Goulet-0/+10
2024-10-30Rollup merge of #132344 - compiler-errors:same-thing, r=lcnrJubilee-16/+21
Merge `HostPolarity` and `BoundConstness` They're basically the same thing, and I think `BoundConstness` is easier to use. r? fee1-dead or reassign
2024-10-30Rollup merge of #129383 - cjgillot:opaque-noremap, ↵Jubilee-162/+323
r=compiler-errors,petrochenkov Remap impl-trait lifetimes on HIR instead of AST lowering Current AST->HIR lowering goes out of its way to remap lifetimes for opaque types. This is complicated and leaks into upstream and downstream code. This PR stops trying to be clever during lowering, and prefers to do this remapping during the HIR->ty lowering. The remapping computation easily fits into the bound var resolution code. Its result can be used in by `generics_of` and `hir_ty_lowering::new_opaque` to add the proper parameters and arguments. See an example on the doc for query `opaque_captured_lifetimes`. Based on https://github.com/rust-lang/rust/pull/129244/ Fixes https://github.com/rust-lang/rust/issues/125249 Fixes https://github.com/rust-lang/rust/issues/126850 cc `@compiler-errors` `@spastorino` r? `@petrochenkov`
2024-10-30Merge HostPolarity and BoundConstnessMichael Goulet-16/+21
2024-10-30Actually capture all in-scope lifetimes.Camille GILLOT-43/+29
2024-10-30Review comments.Camille GILLOT-1/+1
2024-10-30Adapt comments.Camille GILLOT-12/+12
2024-10-30Remap impl-trait lifetimes on HIR instead of AST lowering.Camille GILLOT-160/+335
2024-10-30Switch to comparing indices instead of names.Adrian Taylor-28/+11
2024-10-30Reject generic self types.Adrian Taylor-13/+83
The RFC for arbitrary self types v2 declares that we should reject "generic" self types. This commit does so. The definition of "generic" was unclear in the RFC, but has been explored in https://github.com/rust-lang/rust/issues/129147 and the conclusion is that "generic" means any `self` type which is a type parameter defined on the method itself, or references to such a type. This approach was chosen because other definitions of "generic" don't work. Specifically, * we can't filter out generic type _arguments_, because that would filter out Rc<Self> and all the other types of smart pointer we want to support; * we can't filter out all type params, because Self itself is a type param, and because existing Rust code depends on other type params declared on the type (as opposed to the method). This PR decides to make a new error code for this case, instead of reusing the existing E0307 error. This makes the code a bit more complex, but it seems we have an opportunity to provide specific diagnostics for this case so we should do so. This PR filters out generic self types whether or not the 'arbitrary self types' feature is enabled. However, it's believed that it can't have any effect on code which uses stable Rust, since there are no stable traits which can be used to indicate a valid generic receiver type, and thus it would have been impossible to write code which could trigger this new error case. It is however possible that this could break existing code which uses either of the unstable `arbitrary_self_types` or `receiver_trait` features. This breakage is intentional; as we move arbitrary self types towards stabilization we don't want to continue to support generic such types. This PR adds lots of extra tests to arbitrary-self-from-method-substs. Most of these are ways to trigger a "type mismatch" error which https://github.com/rust-lang/rust/blob/9b82580c7347f800c2550e6719e4218a60a80b28/compiler/rustc_hir_typeck/src/method/confirm.rs#L519 hopes can be minimized by filtering out generics in this way. We remove a FIXME from confirm.rs suggesting that we make this change. It's still possible to cause type mismatch errors, and a subsequent PR may be able to improve diagnostics in this area, but it's harder to cause these errors without contrived uses of the turbofish. This is a part of the arbitrary self types v2 project, https://github.com/rust-lang/rfcs/pull/3519 https://github.com/rust-lang/rust/issues/44874 r? @wesleywiser
2024-10-30Rollup merge of #131856 - lcnr:typing-mode, r=compiler-errorsMatthias Krüger-39/+47
TypingMode: merge intercrate, reveal, and defining_opaque_types This adds `TypingMode` and uses it in most places. We do not yet remove `Reveal` from `param_env`s. This and other future work as tracked in #132279 and via `FIXME`s. Fetching the `TypingMode` of the `InferCtxt` asserts that the `TypingMode` agrees with `ParamEnv::reveal` to make sure we don't introduce any subtle bugs here. This will be unnecessary once `ParamEnv::reveal` no longer exists. As the `TypingMode` is now a part of the query input, I've merged the coherence and non-coherence caches for the new solver. I've also enabled the local `infcx` cache during coherence by clearing the cache when forking it with a different `TypingMode`. #### `TypingMode::from_param_env` I am using this even in cases where I know that the `param_env` will always be `Reveal::UserFacing`. This is to make it easier to correctly refactor this code in the future, any time we use `Reveal::UserFacing` in a body while not defining its opaque types is incorrect and should use a `TypingMode` which only reveals opaques defined by that body instead, cc #124598 r? ``@compiler-errors``
2024-10-29Rollup merge of #131984 - dingxiangfei2009:stabilize-if-let-rescope, ↵Matthias Krüger-4/+2
r=traviscross,lcnr Stabilize if_let_rescope Close #131154 Tracked by #124085
2024-10-29TypingMode :thinking:lcnr-39/+47
2024-10-29Rollup merge of #132194 - compiler-errors:rpitit-super-wc, r=spastorinoJubilee-14/+2
Collect item bounds for RPITITs from trait where clauses just like associated types We collect item bounds from trait where clauses for *associated types*, i.e. this: ```rust trait Foo where Self::Assoc: Send { type Assoc; } ``` Becomes this: ```rust trait Foo { type Assoc: Send; } ``` Today, with RPITITs/AFIT and return-type notation, we don't do that, i.e.: ```rust trait Foo where Self::method(..): Send { fn method() -> impl Sized; } fn is_send(_: impl Send) {} fn test<T: Foo>() { is_send(T::method()); } ``` ...which fails on nightly today. Turns out it's super easy to fix this, and we just need to use the `associated_type_bounds` lowering function in `explicit_item_bounds_with_filter`, which has that logic baked in.
2024-10-29Rollup merge of #132119 - compiler-errors:effects-old-solver, r=lcnrJubilee-12/+0
Hack out effects support for old solver Opening this for vibes ✨ Turns out that a basic, somewhat incomplete implementation of host effects is achievable in the old trait solver pretty easily. This should be sufficient for us to use in the standard library itself. Regarding incompleteness, maybe we should always treat host predicates as ambiguous in intercrate mode (at least in the old solver) to avoid any worries about accidental impl overlap or something. r? ```@lcnr``` cc ```@fee1-dead```
2024-10-28Hack out effects support for old solverMichael Goulet-12/+0
2024-10-28Rollup merge of #132255 - workingjubilee:layout-is-🏚️, r=compiler-errorsJubilee-1/+1
Add `LayoutS::is_uninhabited` and use it Use accessors for the things that accessors are good at: reducing everyone's need to be nosy and peek at the internals of every data structure.
2024-10-28Rollup merge of #132249 - workingjubilee:add-rustc-abi, r=compiler-errorsJubilee-3/+3
compiler: Add rustc_abi dependence to the compiler Depend on rustc_abi in compiler crates that use it indirectly but have not yet taken on that dependency, and are not *significantly* entangled in my other PRs. This leaves an "excise rustc_target" step after the dust settles.
2024-10-28compiler: Add `is_uninhabited` and use LayoutS accessorsJubilee Young-1/+1
This reduces the need of the compiler to peek on the fields of LayoutS.
2024-10-28Rollup merge of #132243 - compiler-errors:no-span, r=jieyouxu许杰友 Jieyou Xu (Joe)-3/+3
Remove `ObligationCause::span()` method I think it's an incredibly confusing footgun to expose both `obligation_cause.span` and `obligation_cause.span()`. Especially because `ObligationCause::span()` (the method) seems to just be hacking around a single quirk in the way we set up obligation causes for match arms. First commit removes the need for that hack, with only one diagnostic span changing (but IMO not really getting worse -- I'd argue that it was already confusing).
2024-10-28Rollup merge of #132227 - compiler-errors:better-const-span, r=Nadrieril许杰友 Jieyou Xu (Joe)-16/+9
Pass constness with span into lower_poly_trait_ref Gives us a span to point at for ~const/const on non-const traits. Split from #132209. r? Nadrieril
2024-10-27compiler: Add rustc_abi dependence to the compilerJubilee Young-3/+3
Depend on rustc_abi in compiler crates that use it indirectly but have not yet taken on that dependency, and are not entangled in my other PRs. This leaves an "excise rustc_target" step after the dust settles.
2024-10-27Remove ObligationCause::span() methodMichael Goulet-3/+3
2024-10-27Rollup merge of #132214 - fmease:mv-impl-trait-val-paths, r=compiler-errorsMatthias Krüger-9/+0
Cleanup: Move an impl-Trait check from AST validation to AST lowering Namely the one that rejects `impl Trait` in qself types and non-final path segments. There's no good reason to perform this during AST validation. We have better infrastructure in place in the AST lowerer (`ImplTraitContext`). This shaves off a lot of code. We now lower `impl Trait` in bad positions to `{type error}` which allows us to remove a special case from HIR ty lowering. Coincidentally fixes #126725. Well, it only *masks* it by passing `{type error}` to HIR analysis instead of a "bad" opaque. I was able to find a new reproducer for it. See the issue.
2024-10-27Rollup merge of #132043 - compiler-errors:simplify-rbv, r=cjgillotMatthias Krüger-79/+75
Simplify param handling in `resolve_bound_vars` I always found the flow of the `ResolvedArg` constructors to be a bit confusing; turns out they're also kinda redundantly passing around their data, too. Also, deduplicate some code handling early-bound var to late-bound var conversion between return type notation's two styles: `where <T as Trait>::method(..): Bound` and `where T: Trait<method(..): Bound>`.
2024-10-27Move an impl-Trait check from AST validation to AST loweringLeón Orell Valerian Liehr-9/+0
2024-10-26Pass constness with span into lower_poly_trait_refMichael Goulet-16/+9
2024-10-26Collect item bounds for RPITITs from trait where clauses just like ↵Michael Goulet-14/+2
associated types
2024-10-26Rollup merge of #132168 - fee1-dead-contrib:fxclean, r=compiler-errorsMatthias Krüger-30/+10
Effects cleanup - removed extra bits from predicates queries that are no longer needed in the new system - removed the need for `non_erasable_generics` to take in tcx and DefId, removed unused arguments in callers r? compiler-errors
2024-10-26Effects cleanupDeadbeef-30/+10
- removed extra bits from predicates queries that are no longer needed in the new system - removed the need for `non_erasable_generics` to take in tcx and DefId, removed unused arguments in callers
2024-10-25tcx.is_const_fn doesn't work the way it is described, remove itRalf Jung-1/+1
Then we can rename the _raw functions to drop their suffix, and instead explicitly use is_stable_const_fn for the few cases where that is really what you want.
2024-10-24Auto merge of #132116 - matthiaskrgr:rollup-3a0ia4r, r=matthiaskrgrbors-3/+1
Rollup of 4 pull requests Successful merges: - #131790 (Document textual format of SocketAddrV{4,6}) - #131983 (Stabilize shorter-tail-lifetimes) - #132097 (sanitizer.md: LeakSanitizer is not supported on aarch64 macOS) - #132107 (Remove visit_expr_post from ast Visitor) r? `@ghost` `@rustbot` modify labels: rollup
2024-10-24Rollup merge of #131983 - dingxiangfei2009:stabilize-shorter-tail-lifetimes, ↵Matthias Krüger-3/+1
r=lcnr Stabilize shorter-tail-lifetimes Close #131445 Tracked by #123739 We found a test case `tests/ui/drop/drop_order.rs` that had not been covered by the change. The test fixture is fixed now with the correct expectation.
2024-10-24Be better at enforcing that const_conditions is only called on const itemsMichael Goulet-72/+37
2024-10-24Implement const effect predicate in new solverMichael Goulet-34/+503
2024-10-24Remove associated type based effects logicMichael Goulet-216/+7
2024-10-24Rollup merge of #131756 - compiler-errors:deeply-normalize-type-err, r=lcnrStuart Cook-8/+12
Deeply normalize `TypeTrace` when reporting type error in new solver Normalize the values that come from the `TypeTrace` for various type mismatches. Side-note: We can't normalize the `TypeError` itself bc it may come from instantiated binders, so it may reference values from within the probe... r? lcnr
2024-10-24Rollup merge of #130225 - adetaylor:rename-old-receiver, r=wesleywiserStuart Cook-1/+1
Rename Receiver -> LegacyReceiver As part of the "arbitrary self types v2" project, we are going to replace the current `Receiver` trait with a new mechanism based on a new, different `Receiver` trait. This PR renames the old trait to get it out the way. Naming is hard. Options considered included: * HardCodedReceiver (because it should only be used for things in the standard library, and hence is sort-of hard coded) * LegacyReceiver * TargetLessReceiver * OldReceiver These are all bad names, but fortunately this will be temporary. Assuming the new mechanism proceeds to stabilization as intended, the legacy trait will be removed altogether. Although we expect this trait to be used only in the standard library, we suspect it may be in use elsehwere, so we're landing this change separately to identify any surprising breakages. It's known that this trait is used within the Rust for Linux project; a patch is in progress to remove their dependency. This is a part of the arbitrary self types v2 project, https://github.com/rust-lang/rfcs/pull/3519 https://github.com/rust-lang/rust/issues/44874 r? `@wesleywiser`
2024-10-24Plumb through param_env to note_type_errMichael Goulet-8/+12