summaryrefslogtreecommitdiff
path: root/compiler/rustc_infer
Commit message (Collapse)AuthorAgeFilesLines
* Rollup merge of #111602 - tmiasko:erroneous-constant-used, r=oli-obkNilstrieb2023-05-161-1/+1
|\ | | | | | | | | | | | | | | | | | | Suppress "erroneous constant used" for constants tainted by errors When constant evaluation fails because its MIR is tainted by errors, suppress note indicating that erroneous constant was used, since those errors have to be fixed regardless of the constant being used or not. Fixes #110891.
| * Suppress "erroneous constant used" for constants tainted by errorsTomasz Miąsko2023-05-151-1/+1
| | | | | | | | | | | | When constant evaluation fails because its MIR is tainted by errors, suppress note indicating that erroneous constant was used, since those errors have to be fixed regardless of the constant being used or not.
* | Replace RelationDir with VarianceMichael Goulet2023-05-154-63/+29
| |
* | Rename super_relate_* to structurally_relate_*Michael Goulet2023-05-154-7/+7
| |
* | Tweaks and a testMichael Goulet2023-05-151-51/+52
| |
* | yeet ConstInferUnifierMichael Goulet2023-05-152-180/+63
| |
* | Simplify delegateMichael Goulet2023-05-153-69/+70
| |
* | Combine TypeGeneralizer and GeneralizerMichael Goulet2023-05-154-588/+467
|/
* Auto merge of #111570 - compiler-errors:ct-err, r=BoxyUwUbors2023-05-151-2/+2
|\ | | | | | | | | | | | | | | Rename const error methods for consistency renames `ty::Const`'s methods for creating a `ConstKind::Error` to be in the same naming style as `ty::Ty`'s equivalent methods. r? `@BoxyUwU`
| * Rename const error methods for consistencyMichael Goulet2023-05-141-2/+2
| |
* | Rollup merge of #110454 - oli-obk:limited_impl_trait_in_assoc_type, ↵Dylan DPC2023-05-132-3/+17
|\ \ | |/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | r=compiler-errors Require impl Trait in associated types to appear in method signatures This implements the limited version of TAIT that was proposed in https://github.com/rust-lang/rust/issues/107645#issuecomment-1477899536 Similar to `impl Trait` in return types, `impl Trait` in associated types may only be used within the impl block which it is a part of. To make everything simpler and forward compatible to getting desugared to a plain type alias impl trait in the future, we're requiring that any associated functions or constants that want to register hidden types must be using the associated type in their signature (type of the constant or argument/return type of the associated method. Where bounds mentioning the associated type are ignored). We have preexisting tests checking that this works transitively across multiple associated types in situations like ```rust impl Foo for Bar { type A = impl Trait; type B = impl Iterator<Item = Self::A>; fn foo() -> Self::B { ...... } } ```
| * Use the opaque_types_defined_by query to cheaply check for whether a hidden ↵Oli Scherer2023-05-122-124/+13
| | | | | | | | type may be registered for an opaque type
| * Require `impl Trait` in associated types to appear in method signaturesOli Scherer2023-05-122-10/+135
| |
* | Auto merge of #109732 - Urgau:uplift_drop_forget_ref_lints, r=davidtwcobors2023-05-121-1/+1
|\ \ | |/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Uplift `clippy::{drop,forget}_{ref,copy}` lints This PR aims at uplifting the `clippy::drop_ref`, `clippy::drop_copy`, `clippy::forget_ref` and `clippy::forget_copy` lints. Those lints are/were declared in the correctness category of clippy because they lint on useless and most probably is not what the developer wanted. ## `drop_ref` and `forget_ref` The `drop_ref` and `forget_ref` lint checks for calls to `std::mem::drop` or `std::mem::forget` with a reference instead of an owned value. ### Example ```rust let mut lock_guard = mutex.lock(); std::mem::drop(&lock_guard) // Should have been drop(lock_guard), mutex // still locked operation_that_requires_mutex_to_be_unlocked(); ``` ### Explanation Calling `drop` or `forget` on a reference will only drop the reference itself, which is a no-op. It will not call the `drop` or `forget` method on the underlying referenced value, which is likely what was intended. ## `drop_copy` and `forget_copy` The `drop_copy` and `forget_copy` lint checks for calls to `std::mem::forget` or `std::mem::drop` with a value that derives the Copy trait. ### Example ```rust let x: i32 = 42; // i32 implements Copy std::mem::forget(x) // A copy of x is passed to the function, leaving the // original unaffected ``` ### Explanation Calling `std::mem::forget` [does nothing for types that implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html) since the value will be copied and moved into the function on invocation. ----- Followed the instructions for uplift a clippy describe here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751 cc `@m-ou-se` (as T-libs-api leader because the uplifting was discussed in a recent meeting)
| * Remove and fix useless drop of referenceUrgau2023-05-101-1/+1
| |
* | add EarlyBinder to thir_abstract_const; remove tcx.bound_abstract_constKyle Matsuda2023-05-091-1/+1
|/
* Rollup merge of #109410 - fmease:iat-alias-kind-inherent, r=compiler-errorsMichael Goulet2023-05-084-5/+11
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Introduce `AliasKind::Inherent` for inherent associated types Allows us to check (possibly generic) inherent associated types for well-formedness. Type inference now also works properly. Follow-up to #105961. Supersedes #108430. Fixes #106722. Fixes #108957. Fixes #109768. Fixes #109789. Fixes #109790. ~Not to be merged before #108860 (`AliasKind::Weak`).~ CC `@jackh726` r? `@compiler-errors` `@rustbot` label T-types F-inherent_associated_types
| * IAT: Introduce AliasKind::InherentLeón Orell Valerian Liehr2023-05-044-5/+11
| |
* | Auto merge of #106621 - ozkanonur:enable-elided-lifetimes-for-doctests, ↵bors2023-05-086-9/+11
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | r=Mark-Simulacrum enable `rust_2018_idioms` lint group for doctests With this change, `rust_2018_idioms` lint group will be enabled for compiler/libstd doctests. Resolves #106086 Resolves #99144 Signed-off-by: ozkanonur <work@onurozkan.dev>
| * | enable `rust_2018_idioms` for doctestsozkanonur2023-05-076-9/+11
| | | | | | | | | | | | Signed-off-by: ozkanonur <work@onurozkan.dev>
* | | Auto merge of #111161 - compiler-errors:rtn-super, r=cjgillotbors2023-05-071-4/+4
|\ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | Support return-type bounds on associated methods from supertraits Support `T: Trait<method(): Bound>` when `method` comes from a supertrait, aligning it with the behavior of associated type bounds (both equality and trait bounds). The only wrinkle is that I have to extend `super_predicates_that_define_assoc_type` to look for *all* items, not just `AssocKind::Ty`. This will also be needed to support `feature(associated_const_equality)` as well, which is subtly broken when it comes to supertraits, though this PR does not fix those yet. There's a slight chance there's a perf regression here, in which case I guess I could split it out into a separate query.
| * | | Rename things to reflect that they're not item specificMichael Goulet2023-05-031-4/+4
| | | |
* | | | Rollup merge of #110577 - compiler-errors:drop-impl-fulfill, r=lcnrMatthias Krüger2023-05-061-0/+11
|\ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Use fulfillment to check `Drop` impl compatibility Use an `ObligationCtxt` to ensure that a `Drop` impl does not have stricter requirements than the ADT that it's implemented for, rather than using a `SimpleEqRelation` to (more or less) syntactically equate predicates on an ADT with predicates on an impl. r? types ### Some background The old code reads: ```rust // An earlier version of this code attempted to do this checking // via the traits::fulfill machinery. However, it ran into trouble // since the fulfill machinery merely turns outlives-predicates // 'a:'b and T:'b into region inference constraints. It is simpler // just to look for all the predicates directly. ``` I'm not sure what this means, but perhaps in the 8 years since that this comment was written (cc #23638) it's gotten easier to process region constraints after doing fulfillment? I don't know how this logic differs from anything we do in the `compare_impl_item` module. Ironically, later on it says: ```rust // However, it may be more efficient in the future to batch // the analysis together via the fulfill (see comment above regarding // the usage of the fulfill machinery), rather than the // repeated `.iter().any(..)` calls. ``` Also: * Removes `SimpleEqRelation` which was far too syntactical in its relation. * Fixes #110557
| * | | | Use fulfillment to check Drop impl compatibilityMichael Goulet2023-05-041-0/+11
| | |_|/ | |/| |
* | | | forbid escaping bound vars in combinelcnr2023-05-051-14/+8
| | | | | | | | | | | | | | | | | | | | removes the `CollectAllMismatches` in favor of a slightly more manual approach.
* | | | Rollup merge of #111132 - lcnr:nll-generalize, r=b-naberYuki Okushi2023-05-054-105/+7
|\ \ \ \ | |/ / / |/| | | | | | | | | | | | | | | cleanup nll generalizer followup to #108861
| * | | remove `inside_canonicalization_ctxt` flaglcnr2023-05-033-37/+0
| | | | | | | | | | | | | | | | | | | | | | | | we never reach the code checking for this flag while the flag is enabled, so it does not change the behavior of the code.
| * | | cleanup nll generalizerlcnr2023-05-031-68/+7
| |/ /
* | | Auto merge of #110806 - WaffleLapkin:unmkI, r=lcnrbors2023-05-042-6/+11
|\ \ \ | | | | | | | | | | | | | | | | | | | | | | | | Replace `tcx.mk_trait_ref` with `TraitRef::new` First step in implementing https://github.com/rust-lang/compiler-team/issues/616 r? `@lcnr`
| * | | Replace `tcx.mk_trait_ref` with `ty::TraitRef::new`Maybe Waffle2023-04-252-6/+11
| | | |
* | | | Rollup merge of #110791 - compiler-errors:negative-bounds, r=oli-obkDylan DPC2023-05-041-0/+4
|\ \ \ \ | |_|/ / |/| | | | | | | | | | | | | | | | | | | | | | | Implement negative bounds for internal testing purposes Implements partial support the `!` negative polarity on trait bounds. This is incomplete, but should allow us to at least be able to play with the feature. Not even gonna consider them as a public-facing feature, but I'm implementing them because would've been nice to have in UI tests, for example in #110671.
| * | | Make negative trait bounds work with the old trait solverMichael Goulet2023-05-021-0/+4
| | | |
* | | | Restrict `From<S>` for `{D,Subd}iagnosticMessage`.Nicholas Nethercote2023-05-0310-23/+23
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently a `{D,Subd}iagnosticMessage` can be created from any type that impls `Into<String>`. That includes `&str`, `String`, and `Cow<'static, str>`, which are reasonable. It also includes `&String`, which is pretty weird, and results in many places making unnecessary allocations for patterns like this: ``` self.fatal(&format!(...)) ``` This creates a string with `format!`, takes a reference, passes the reference to `fatal`, which does an `into()`, which clones the reference, doing a second allocation. Two allocations for a single string, bleh. This commit changes the `From` impls so that you can only create a `{D,Subd}iagnosticMessage` from `&str`, `String`, or `Cow<'static, str>`. This requires changing all the places that currently create one from a `&String`. Most of these are of the `&format!(...)` form described above; each one removes an unnecessary static `&`, plus an allocation when executed. There are also a few places where the existing use of `&String` was more reasonable; these now just use `clone()` at the call site. As well as making the code nicer and more efficient, this is a step towards possibly using `Cow<'static, str>` in `{D,Subd}iagnosticMessage::{Str,Eager}`. That would require changing the `From<&'a str>` impls to `From<&'static str>`, which is doable, but I'm not yet sure if it's worthwhile.
* | | Rollup merge of #110838 - nnethercote:more-Folder-Visitable-cleanups, r=lcnrMatthias Krüger2023-04-271-1/+1
|\ \ \ | | | | | | | | | | | | | | | | | | | | More `Typefoldable`/`TypeVisitable` cleanups r? ``@lcnr``
| * | | Remove unused `TypeFoldable`/`TypeVisitable` impls.Nicholas Nethercote2023-04-261-1/+1
| | |/ | |/|
* | | rename `needs_infer` to `has_infer`Boxy2023-04-275-9/+9
|/ /
* | Rollup merge of #110556 - kylematsuda:earlybinder-explicit-item-bounds, ↵Matthias Krüger2023-04-252-2/+2
|\ \ | |/ |/| | | | | | | | | | | | | | | | | | | r=compiler-errors Switch to `EarlyBinder` for `explicit_item_bounds` Part of the work to finish https://github.com/rust-lang/rust/issues/105779. This PR adds `EarlyBinder` to the return type of the `explicit_item_bounds` query and removes `bound_explicit_item_bounds`. r? `@compiler-errors` (hope it's okay to request you, since you reviewed #110299 and #110498 :smiley:)
| * add EarlyBinder to output of explicit_item_bounds; replace ↵Kyle Matsuda2023-04-202-2/+2
| | | | | | | | bound_explicit_item_bounds usages; remove bound_explicit_item_bounds query
* | Rollup merge of #110563 - ↵Matthias Krüger2023-04-251-1/+1
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | bryangarza:refactor-trait-selection-error-reporting, r=compiler-errors Break up long function in trait selection error reporting + clean up nearby code - Move blocks of code into their own functions - Replace a few function argument types with their type aliases - Create "AppendConstMessage" enum to replace a nested `Option`.
| * | Break up long function in trait selection error reportingBryan Garza2023-04-211-1/+1
| | | | | | | | | | | | | | | - Move blocks of code into their own functions - Replace a few function argument types with their type aliases
* | | Split `{Idx, IndexVec, IndexSlice}` into their own modulesMaybe Waffle2023-04-247-8/+8
| | |
* | | Auto merge of #109753 - compiler-errors:replenish-region-constraints, r=aliemjaybors2023-04-221-2/+2
|\ \ \ | |/ / |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Clone region var origins instead of taking them in borrowck Fixes an issue with the new solver where reporting a borrow-checker error ICEs because it calls `InferCtxt::evaluate_obligation`. This also removes a handful of unnecessary `tcx.infer_ctxt().build()` calls that are only there to mitigate this same exact issue, but with the old solver. Fixes compiler-errors/next-solver-hir-issues#12. ---- This implements `@aliemjay's` solution where we just don't *take* the region constraints, but clone them. This potentially makes it easier to write a bug about taking region constraints twice or never at all, but again, not many folks are touching this code.
| * | Clone region var origins instead of taking in borrowckMichael Goulet2023-04-211-2/+2
| |/
* | Remove WithOptconstParam.Camille GILLOT2023-04-201-3/+3
|/
* Auto merge of #110527 - nnethercote:lazy-graph, r=lqdbors2023-04-201-4/+7
|\ | | | | | | | | | | | | | | In `LexicalResolver`, don't construct graph unless necessary. A small but easy perf win. r? `@jackh726`
| * In `LexicalResolver`, don't construct graph unless necessary.Nicholas Nethercote2023-04-191-4/+7
| | | | | | | | A small but easy perf win.
* | Auto merge of #110399 - cjgillot:infer-variance, r=aliemjaybors2023-04-203-13/+65
|\ \ | | | | | | | | | | | | | | | | | | | | | Account for opaque variance in outlives Fixes https://github.com/rust-lang/rust/issues/108591 Fixes https://github.com/rust-lang/rust/issues/108592 cc `@aliemjay`
| * | Account for variance in outlives verification.Camille GILLOT2023-04-162-4/+45
| | |
| * | Account for variance in outlives obligations.Camille GILLOT2023-04-161-9/+20
| | |
* | | Auto merge of #110407 - Nilstrieb:fluent-macro, r=davidtwcobors2023-04-192-1/+2
|\ \ \ | | | | | | | | | | | | | | | | | | | | Add `rustc_fluent_macro` to decouple fluent from `rustc_macros` Fluent, with all the icu4x it brings in, takes quite some time to compile. `fluent_messages!` is only needed in further downstream rustc crates, but is blocking more upstream crates like `rustc_index`. By splitting it out, we allow `rustc_macros` to be compiled earlier, which speeds up `x check compiler` by about 5 seconds (and even more after the needless dependency on `serde_json` is removed from `rustc_data_structures`).