summary refs log tree commit diff
path: root/compiler/rustc_hir_analysis/src/check
AgeCommit message (Collapse)AuthorLines
2022-12-26Make fast-path for implied wf lint betterMichael Goulet-71/+92
2022-12-26Add IMPLIED_BOUNDS_ENTAILMENT lintMichael Goulet-5/+70
2022-12-07Auto merge of #104799 - pcc:linkage-fn, r=tmiaskobors-1/+34
Support Option and similar enums as type of static variable with linkage attribute Compiler MCP: rust-lang/compiler-team#565
2022-12-05On E0195 point at where clause lifetime boundsEsteban Küber-11/+40
Fix #104733
2022-12-05Support Option and similar enums as type of static variable with linkage ↵Peter Collingbourne-1/+20
attribute. Compiler MCP: https://github.com/rust-lang/compiler-team/issues/565
2022-12-05Move linkage type check to HIR analysis and fix semantics issues.Peter Collingbourne-0/+14
This ensures that the error is printed even for unused variables, as well as unifying the handling between the LLVM and GCC backends. This also fixes unusual behavior around exported Rust-defined variables with linkage attributes. With the previous behavior, it appears to be impossible to define such a variable such that it can actually be imported and used by another crate. This is because on the importing side, the variable is required to be a pointer, but on the exporting side, the type checker rejects static variables of pointer type because they do not implement `Sync`. Even if it were possible to import such a type, it appears that code generation on the importing side would add an unexpected additional level of pointer indirection, which would break type safety. This highlighted that the semantics of linkage on Rust-defined variables is different to linkage on foreign items. As such, we now model the difference with two different codegen attributes: linkage for Rust-defined variables, and import_linkage for foreign items. This change gives semantics to the test src/test/ui/linkage-attr/auxiliary/def_illtyped_external.rs which was previously expected to fail to compile. Therefore, convert it into a test that is expected to successfully compile. The update to the GCC backend is speculative and untested.
2022-12-04Auto merge of #105261 - matthiaskrgr:rollup-9ghhc9c, r=matthiaskrgrbors-17/+16
Rollup of 6 pull requests Successful merges: - #101975 (Suggest to use . instead of :: when accessing a method of an object) - #105141 (Fix ICE on invalid variable declarations in macro calls) - #105224 (Properly substitute inherent associated types.) - #105236 (Add regression test for #47814) - #105247 (Use parent function WfCheckingContext to check RPITIT.) - #105253 (Update a couple of rustbuild deps) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-12-04Use parent function WfCheckingContext to check RPITIT.Camille GILLOT-17/+16
2022-12-04Also avoid creating a terminating scope in mixed chainsest31-13/+13
This avoids creation of a terminating scope in chains that contain both && and ||, because also there we know that a terminating scope is not neccessary: all the chain members are already in such terminating scopes. Also add a mixed && / || test.
2022-12-04Improve commentsest31-6/+18
2022-12-03Remove drop order twist of && and || and make them associativeest31-4/+21
Previously a short circuiting && chain would drop the first element after all the other elements, and otherwise follow evaluation order, so code like: f(1).g() && f(2).g() && f(3).g() && f(4).g() would drop the temporaries in the order 2,3,4,1. This made && and || non-associative regarding drop order, so adding ()'s to the expression would change drop order: f(1).g() && (f(2).g() && f(3).g()) && f(4).g() for example would drop in the order 3,2,4,1. As, except for the bool result, there is no data returned by the sub-expressions of the short circuiting binops, we can safely discard of any temporaries created by the sub-expr. Previously, code was already putting the rhs's into terminating scopes, but missed it for the lhs's. This commit addresses this "twist". In the expression, we now also put the lhs into a terminating scope. The drop order for the above expressions is 1,2,3,4 now.
2022-12-02Check lifetime param count in collect_trait_impl_trait_tysMichael Goulet-21/+18
2022-11-28Make ObligationCtxt::normalize take cause by borrowMichael Goulet-11/+11
2022-11-28FnCtxt normalization stuffMichael Goulet-0/+2
2022-11-27Prefer doc comments over `//`-comments in compilerMaybe Waffle-3/+4
2022-11-25Introduce PredicateKind::ClauseSantiago Pastorino-19/+31
2022-11-25Simplify a bunch of trait ref obligation creationsOli Scherer-1/+1
2022-11-23Use ObligationCtxt::normalizeSantiago Pastorino-17/+4
2022-11-22Rollup merge of #103488 - oli-obk:impl_trait_for_tait, r=lcnrManish Goregaokar-0/+8
Allow opaque types in trait impl headers and rely on coherence to reject unsound cases r? ````@lcnr```` fixes #99840
2022-11-22Auto merge of #104711 - Dylan-DPC:rollup-gkw1qr8, r=Dylan-DPCbors-43/+37
Rollup of 6 pull requests Successful merges: - #104295 (Check generics parity before collecting return-position `impl Trait`s in trait) - #104464 (Reduce exceptions overallocation on non Windows x86_64) - #104615 (Create def_id for async fns during lowering) - #104669 (Only declare bindings for if-let guards once per arm) - #104701 (Remove a lifetime resolution hack from `compare_predicate_entailment`) - #104710 (disable strict-provenance-violating doctests in Miri) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-11-22Rollup merge of #104701 - compiler-errors:rpitit-remove-reempty-hack, r=TaKO8KiDylan DPC-11/+1
Remove a lifetime resolution hack from `compare_predicate_entailment` This is not needed anymore, probably due to #102334 equating the function signatures fully in `collect_trait_impl_trait_tys`. Also, the assertion in in #102903 makes sure that this is actually fixed, so I'm pretty confident this isn't needed.
2022-11-22Auto merge of #103578 - petrochenkov:nofict, r=nagisabors-1/+1
Unreserve braced enum variants in value namespace With this PR braced enum variants (`enum E { V { /*...*/ } }`) no longer take a slot in value namespace, so the special case mentioned in the note in https://github.com/rust-lang/rfcs/blob/master/text/1506-adt-kinds.md#braced-structs is removed. Report - https://github.com/rust-lang/rust/pull/103578#issuecomment-1292594900.
2022-11-22Remove a hack from compare_predicate_entailmentMichael Goulet-11/+1
2022-11-22Delay bug to deduplicate diagnosticsMichael Goulet-8/+10
2022-11-22drive-by: style nitsMichael Goulet-25/+19
2022-11-22Check generics parity between impl and trait before collecting RPITITsMichael Goulet-3/+11
2022-11-21Stop passing the self-type as a separate argument.Oli Scherer-1/+1
2022-11-21Add helper to create the trait ref for a lang itemOli Scherer-1/+1
2022-11-21Allow iterators instead of requiring slices that will get turned into iteratorsOli Scherer-1/+1
2022-11-21Assert that various types have the right amount of generic args and fix the ↵Oli Scherer-4/+1
sites that used the wrong amount
2022-11-21Unreserve braced enum variants in value namespaceVadim Petrochenkov-1/+1
2022-11-21Add an always-ambiguous predicate to make sure that we don't accidentlally ↵Oli Scherer-0/+4
allow trait resolution to prove false things during coherence
2022-11-21Treat different opaque types of the same def id as equal during coherenceOli Scherer-0/+4
2022-11-21Auto merge of #103491 - cjgillot:self-rpit, r=oli-obkbors-63/+57
Support using `Self` or projections inside an RPIT/async fn I reuse the same idea as https://github.com/rust-lang/rust/pull/103449 to use variances to encode whether a lifetime parameter is captured by impl-trait. The current implementation of async and RPIT replace all lifetimes from the parent generics by `'static`. This PR changes the scheme ```rust impl<'a> Foo<'a> { fn foo<'b, T>() -> impl Into<Self> + 'b { ... } } opaque Foo::<'_a>::foo::<'_b, T>::opaque<'b>: Into<Foo<'_a>> + 'b; impl<'a> Foo<'a> { // OLD fn foo<'b, T>() -> Foo::<'static>::foo::<'static, T>::opaque::<'b> { ... } ^^^^^^^ the `Self` becomes `Foo<'static>` // NEW fn foo<'b, T>() -> Foo::<'a>::foo::<'b, T>::opaque::<'b> { ... } ^^ the `Self` stays `Foo<'a>` } ``` There is the same issue with projections. In the example, substitute `Self` by `<T as Trait<'b>>::Assoc` in the sugared version, and `Foo<'_a>` by `<T as Trait<'_b>>::Assoc` in the desugared one. This allows to support `Self` in impl-trait, since we do not replace lifetimes by `'static` any more. The same trick allows to use projections like `T::Assoc` where `Self` is allowed. The feature is gated behind a `impl_trait_projections` feature gate. The implementation relies on 2 tweaking rules for opaques in 2 places: - we only relate substs that correspond to captured lifetimes during TypeRelation; - we only list captured lifetimes in choice region computation. For simplicity, I encoded the "capturedness" of lifetimes as a variance, `Bivariant` vs `Invariant` for unused vs captured lifetimes. The `variances_of` query used to ICE for opaques. Impl-trait that do not reference `Self` or projections will have their variances as: - `o` (invariant) for each parent type or const; - `*` (bivariant) for each parent lifetime --> will not participate in borrowck; - `o` (invariant) for each own lifetime. Impl-trait that does reference `Self` and/or projections will have some parent lifetimes marked as `o` (as the example above), and participate in type relation and borrowck. In the example above, `variances_of(opaque) = ['_a: o, '_b: *, T: o, 'b: o]`. r? types cc `@compiler-errors` , as you asked about the issue with `Self` and projections.
2022-11-19Rollup merge of #104593 - compiler-errors:rpitit-object-safety-spans, ↵Matthias Krüger-3/+1
r=fee1-dead Improve spans for RPITIT object-safety errors No reason why we can't point at the `impl Trait` that causes the object-safety violation. Also [drive-by: Add is_async fn to hir::IsAsync](https://github.com/rust-lang/rust/pull/104593/commits/c4165f3a965e258531928180195637455299c6f3), which touches clippy too.
2022-11-19Rollup merge of #104411 - lcnr:bivariance-nll, r=compiler-errorsDylan DPC-10/+6
nll: correctly deal with bivariance fixes #104409 when in a bivariant context, relating stuff should always trivially succeed. Also changes the mir validator to correctly deal with higher ranked regions. r? types cc ``@RalfJung``
2022-11-19drive-by: Add is_async fn to hir::IsAsyncMichael Goulet-3/+1
2022-11-17Rollup merge of #104483 - oli-obk:santa-clauses-make-goals, r=compiler-errorsMatthias Krüger-17/+16
Convert predicates into Predicate in the Obligation constructor instead of having almost all callers do that. This reduces a bit of boilerplate, and also paves the way for my work towards https://github.com/rust-lang/compiler-team/issues/531 (as it makes it easier to accept both goals and clauses where right now it only accepts predicates).
2022-11-17Rollup merge of #103852 - compiler-errors:rpitit-early-from-impl, r=lcnrMatthias Krüger-1/+7
Don't remap early-bound regions for return-position `impl Trait` in trait originating from `impl` long title :sweat: We don't want to remap early-bound regions that originate from the `impl`s themselves, since they have no corresponding region in the trait. Not sure if there's a better condition than checking if the EBR's def-id's parent is the impl -- maybe we should be checking if the region comes from the method or RPITIT... :shrug: r? types Fixes #103850
2022-11-17Auto merge of #104170 - cjgillot:hir-def-id, r=fee1-deadbors-1/+1
Record `LocalDefId` in HIR nodes instead of a side table This is part of an attempt to remove the `HirId -> LocalDefId` table from HIR. This attempt is a prerequisite to creation of `LocalDefId` after HIR lowering (https://github.com/rust-lang/rust/pull/96840), by controlling how `def_id` information is accessed. This first part adds the information to HIR nodes themselves instead of a table. The second part is https://github.com/rust-lang/rust/pull/103902 The third part will be to make `hir::Visitor::visit_fn` take a `LocalDefId` as last parameter. The fourth part will be to completely remove the side table.
2022-11-16Convert predicates into Predicate in the Obligation constructorOli Scherer-17/+16
2022-11-15Auto merge of #104054 - RalfJung:byte-provenance, r=oli-obkbors-1/+1
interpret: support for per-byte provenance Also factors the provenance map into its own module. The third commit does the same for the init mask. I can move it in a separate PR if you prefer. Fixes https://github.com/rust-lang/miri/issues/2181 r? `@oli-obk`
2022-11-15use `ocx` type relation routineslcnr-10/+6
2022-11-14Deduplicate visitor.Camille GILLOT-96/+19
2022-11-13Store a LocalDefId in hir::GenericParam.Camille GILLOT-1/+1
2022-11-13Create bidirectional bounds between original and duplicated parameters.Camille GILLOT-13/+16
2022-11-12Make impl_trait_projections a feature gate.Camille GILLOT-8/+11
2022-11-12Inherit generics for impl-trait.Camille GILLOT-14/+79
2022-11-12Auto merge of #104310 - Dylan-DPC:rollup-wgt1z4a, r=Dylan-DPCbors-105/+142
Rollup of 7 pull requests Successful merges: - #102049 (Add the `#[derive_const]` attribute) - #103970 (Unhide unknown spans) - #104206 (Remove `save_and_restore_in_snapshot_flag`, use `ObligationCtxt` more) - #104214 (Emit error in `collecting_trait_impl_trait_tys` on mismatched signatures) - #104267 (rustdoc: use checkbox instead of switch for settings toggles) - #104302 (Update cargo) - #104303 (UI tests can be assigned to T-compiler) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-11-12Rollup merge of #104214 - Nilstrieb:returns_impl_Ice, r=compiler-errorsDylan DPC-105/+142
Emit error in `collecting_trait_impl_trait_tys` on mismatched signatures Previously, a `delay_span_bug` was isssued, failing normalization. This create a `TyKind::Error` in the signature, which caused `compare_predicate_entailment` to swallow its signature mismatch error, causing ICEs because no error was emitted. fixes #104183 r? ``@compiler-errors``