about summary refs log tree commit diff
path: root/compiler/rustc_infer/src
AgeCommit message (Collapse)AuthorLines
2023-05-30leak_check: remove unused codepathlcnr-26/+6
2023-05-29Rename `tcx.mk_re_*` => `Region::new_*`Maybe Waffle-25/+28
2023-05-29Use `Cow` in `{D,Subd}iagnosticMessage`.Nicholas Nethercote-26/+30
Each of `{D,Subd}iagnosticMessage::{Str,Eager}` has a comment: ``` // FIXME(davidtwco): can a `Cow<'static, str>` be used here? ``` This commit answers that question in the affirmative. It's not the most compelling change ever, but it might be worth merging. This requires changing the `impl<'a> From<&'a str>` impls to `impl From<&'static str>`, which involves a bunch of knock-on changes that require/result in call sites being a little more precise about exactly what kind of string they use to create errors, and not just `&str`. This will result in fewer unnecessary allocations, though this will not have any notable perf effects given that these are error paths. Note that I was lazy within Clippy, using `to_string` in a few places to preserve the existing string imprecision. I could have used `impl Into<{D,Subd}iagnosticMessage>` in various places as is done in the compiler, but that would have required changes to *many* call sites (mostly changing `&format("...")` to `format!("...")`) which didn't seem worthwhile.
2023-05-28Make EarlyBinder's inner value private; and fix all of the resulting errorsKyle Matsuda-1/+1
2023-05-25Fallible<_> -> Result<_, NoSolution>Michael Goulet-2/+2
2023-05-25Add InferCtxt::register_hidden_type_in_new_solverMichael Goulet-0/+23
2023-05-25Move DefiningAnchorMichael Goulet-14/+3
2023-05-25Pull out logic from #111131, plus some new logic in ↵Michael Goulet-26/+57
EvalCtxt::normalize_opaque_type Co-authored-by: lcnr <rust@lcnr.de>
2023-05-24Use `Option::is_some_and` and `Result::is_ok_and` in the compilerMaybe Waffle-7/+7
2023-05-20Rollup merge of #111450 - compiler-errors:opaque-ty-key, r=oli-obkGuillaume Gomez-6/+22
Use `OpaqueTypeKey` in query response Makes it a bit clearer that at least one of the types being returned from a canonical query is an opaque.
2023-05-18do not overwrite obligationslcnr-7/+6
2023-05-16Rollup merge of #111602 - tmiasko:erroneous-constant-used, r=oli-obkNilstrieb-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.
2023-05-15Replace RelationDir with VarianceMichael Goulet-63/+29
2023-05-15Rename super_relate_* to structurally_relate_*Michael Goulet-7/+7
2023-05-15Tweaks and a testMichael Goulet-51/+52
2023-05-15yeet ConstInferUnifierMichael Goulet-180/+63
2023-05-15Simplify delegateMichael Goulet-69/+70
2023-05-15Combine TypeGeneralizer and GeneralizerMichael Goulet-588/+467
2023-05-15Auto merge of #111570 - compiler-errors:ct-err, r=BoxyUwUbors-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`
2023-05-15Suppress "erroneous constant used" for constants tainted by errorsTomasz Miąsko-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.
2023-05-14Rename const error methods for consistencyMichael Goulet-2/+2
2023-05-13Rollup merge of #110454 - oli-obk:limited_impl_trait_in_assoc_type, ↵Dylan DPC-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 { ...... } } ```
2023-05-12Auto merge of #109732 - Urgau:uplift_drop_forget_ref_lints, r=davidtwcobors-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)
2023-05-12Use the opaque_types_defined_by query to cheaply check for whether a hidden ↵Oli Scherer-124/+13
type may be registered for an opaque type
2023-05-12Require `impl Trait` in associated types to appear in method signaturesOli Scherer-10/+135
2023-05-10Use OpaqueTypeKey in query responseMichael Goulet-6/+22
2023-05-10Remove and fix useless drop of referenceUrgau-1/+1
2023-05-09add EarlyBinder to thir_abstract_const; remove tcx.bound_abstract_constKyle Matsuda-1/+1
2023-05-08Rollup merge of #109410 - fmease:iat-alias-kind-inherent, r=compiler-errorsMichael Goulet-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
2023-05-08Auto merge of #106621 - ozkanonur:enable-elided-lifetimes-for-doctests, ↵bors-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>
2023-05-07Auto merge of #111161 - compiler-errors:rtn-super, r=cjgillotbors-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.
2023-05-07enable `rust_2018_idioms` for doctestsozkanonur-9/+11
Signed-off-by: ozkanonur <work@onurozkan.dev>
2023-05-06Rollup merge of #110577 - compiler-errors:drop-impl-fulfill, r=lcnrMatthias Krüger-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
2023-05-05forbid escaping bound vars in combinelcnr-14/+8
removes the `CollectAllMismatches` in favor of a slightly more manual approach.
2023-05-05Rollup merge of #111132 - lcnr:nll-generalize, r=b-naberYuki Okushi-105/+7
cleanup nll generalizer followup to #108861
2023-05-04Use fulfillment to check Drop impl compatibilityMichael Goulet-0/+11
2023-05-04IAT: Introduce AliasKind::InherentLeón Orell Valerian Liehr-5/+11
2023-05-04Auto merge of #110806 - WaffleLapkin:unmkI, r=lcnrbors-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`
2023-05-03Rename things to reflect that they're not item specificMichael Goulet-4/+4
2023-05-03remove `inside_canonicalization_ctxt` flaglcnr-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.
2023-05-04Rollup merge of #110791 - compiler-errors:negative-bounds, r=oli-obkDylan DPC-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.
2023-05-03cleanup nll generalizerlcnr-68/+7
2023-05-03Restrict `From<S>` for `{D,Subd}iagnosticMessage`.Nicholas Nethercote-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.
2023-05-02Make negative trait bounds work with the old trait solverMichael Goulet-0/+4
2023-04-27Rollup merge of #110838 - nnethercote:more-Folder-Visitable-cleanups, r=lcnrMatthias Krüger-1/+1
More `Typefoldable`/`TypeVisitable` cleanups r? ``@lcnr``
2023-04-27rename `needs_infer` to `has_infer`Boxy-9/+9
2023-04-26Remove unused `TypeFoldable`/`TypeVisitable` impls.Nicholas Nethercote-1/+1
2023-04-25Rollup merge of #110556 - kylematsuda:earlybinder-explicit-item-bounds, ↵Matthias Krüger-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:)
2023-04-25Replace `tcx.mk_trait_ref` with `ty::TraitRef::new`Maybe Waffle-6/+11
2023-04-25Rollup merge of #110563 - ↵Matthias Krüger-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`.