about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection
AgeCommit message (Collapse)AuthorLines
2023-05-25Strongly prefer alias and param-env boundsMichael Goulet-5/+9
2023-05-25Pre-populate MIR with opaques, prefer subst-relate candidateMichael Goulet-28/+25
2023-05-25Check that opaque is a defining use, prefer pre-defined opaquesMichael Goulet-14/+91
2023-05-25Prepopulate opaques in canonical inputMichael Goulet-77/+170
2023-05-25Move DefiningAnchorMichael Goulet-1/+2
2023-05-25Pull out logic from #111131, plus some new logic in ↵Michael Goulet-6/+60
EvalCtxt::normalize_opaque_type Co-authored-by: lcnr <rust@lcnr.de>
2023-05-24Safe Transmute: Update definition of Condition typeBryan Garza-17/+20
- Change `Condition` to not contain `Answer`s but instead just contain other `Condition`s directly. - Also improve error reporting for `DstHasStricterAlignment`
2023-05-24Rollup merge of #111912 - WaffleLapkin:is_some_and_in_the_compiler, ↵Manish Goregaokar-7/+7
r=petrochenkov Use `Option::is_some_and` and `Result::is_ok_and` in the compiler `.is_some_and(..)`/`.is_ok_and(..)` replace `.map_or(false, ..)` and `.map(..).unwrap_or(false)`, making the code more readable. This PR is a sibling of https://github.com/rust-lang/rust/pull/111873#issuecomment-1561316515
2023-05-24Safe Transmute: Check mutability before creating dst -> src obligationBryan Garza-5/+15
- Only create dst -> src obligation if Dst is mutable - Add some long comments to explain parts of the transmutability code that were unclear to me when reading - Update/add tests
2023-05-24Safe Transmute: Fix propagation of errorsBryan Garza-3/+3
- Make sure that the most specific Reason is the one that bubbles up when we are folding over the `Answer` tree. `Reason::DstIsBitIncompatible` is the least specific, so that should be used only when there isn't anything else available. - Small fixes where we used the wrong Reason variant. - Tiny cleanups
2023-05-24Safe Transmute: Change Answer type to ResultBryan Garza-23/+23
This patch updates the `Answer` type from `rustc_transmute` so that it just a type alias to `Result`. This makes it so that the standard methods for `Result` can be used to process the `Answer` tree, including being able to make use of the `?` operator on `Answer`s. Also, remove some unused functions
2023-05-24Safe Transmute: Enable handling references, including recursive typesBryan Garza-6/+65
This patch enables support for references in Safe Transmute, by generating nested obligations during trait selection. Specifically, when we call `confirm_transmutability_candidate(...)`, we now recursively traverse the `rustc_transmute::Answer` tree and create obligations for all the `Answer` variants, some of which include multiple nested `Answer`s. Also, to handle recursive types, enable support for coinduction for the Safe Transmute trait (`BikeshedIntrinsicFrom`) by adding the `#[rustc_coinduction]` annotation. Also fix some small logic issues when reducing the `or` and `and` combinations in `rustc_transmute`, so that we don't end up with additional redundant `Answer`s in the tree. Co-authored-by: Jack Wrenn <jack@wrenn.fyi>
2023-05-24Use ObligationCtxt in custom type opsMichael Goulet-27/+27
2023-05-24Use `Option::is_some_and` and `Result::is_ok_and` in the compilerMaybe Waffle-7/+7
2023-05-24Rollup merge of #111880 - compiler-errors:pointer-like-param-env, r=jackh726Matthias Krüger-10/+16
Don't ICE when computing PointerLike trait when region vars are in param-env Fixes #111877
2023-05-23Don't ICE when computing PointerLike trait when region vars are in param-envMichael Goulet-10/+16
2023-05-23Rollup merge of #111704 - compiler-errors:sized-return-cleanup, r=oli-obkDylan DPC-230/+49
Remove return type sized check hack from hir typeck Remove a bunch of special-cased suggestions when someone returns `-> dyn Trait` that checks for type equality, etc. This was a pretty complex piece of code that also relied on a hack in hir typeck (see changes to `compiler/rustc_hir_typeck/src/check.rs`), and I'm not convinced that it's necessary to maintain, when all we really need to tell the user is that they should return `-> impl Trait` or `-> Box<dyn Trait>`, depending on their specific use-case. This is necessary because we may need to move the "return type is sized" check from hir typeck to wfcheck, which does not have access to typeck results. This is a prerequisite for that, and I'm fairly confident that the diagnostics "regressions" here are not a big deal.
2023-05-23Auto merge of #110204 - compiler-errors:new-solver-hir-typeck-hacks, r=lcnrbors-0/+57
Deal with unnormalized projections when structurally resolving types with new solver 1. Normalize types in `structurally_resolved_type` when the new solver is enabled 2. Normalize built-in autoderef targets in `Autoderef` when the new solver is enabled 3. Normalize-erasing-regions in `resolve_type` in writeback This is motivated by the UI test provided, which currently fails with: ``` error[E0609]: no field `x` on type `<usize as SliceIndex<[Foo]>>::Output` --> <source>:9:11 | 9 | xs[0].x = 1; | ^ ``` I'm pretty happy with the approach in (1.) and (2.) and think we'll inevitably need something like this in the long-term, but (3.) seems like a hack to me. It's a *lot* of work to add tons of new calls to every user of these typeck results though (mir build, late lints, etc). Happy to discuss further. r? `@lcnr`
2023-05-22Structurally normalize in the new solverMichael Goulet-0/+57
2023-05-22Auto merge of #111848 - Dylan-DPC:rollup-7jqydzg, r=Dylan-DPCbors-0/+8
Rollup of 6 pull requests Successful merges: - #111501 (MIR drive-by cleanups) - #111609 (Mark internal functions and traits unsafe to reflect preconditions) - #111612 (Give better error when collecting into `&[T]`) - #111756 (Rename `{drop,forget}_{copy,ref}` lints to more consistent naming) - #111843 (move lcnr to only review types stuff) - #111844 (Migrate GUI colors test to original CSS color format) r? `@ghost` `@rustbot` modify labels: rollup
2023-05-23Rollup merge of #111612 - ChayimFriedman2:collect-into-slice-ref, r=petrochenkovDylan DPC-0/+8
Give better error when collecting into `&[T]` The detection of slice reference of `{integral}` in `rustc_on_unimplemented` is hacky, but a proper solution requires changing `FmtPrinter` to add a parameter to print integers as `{integral}` and I didn't want to change it just for `rustc_on_unimplemented`. I can do that if requested, though. I'm open to better wording; this is the best I could come up with.
2023-05-19update recursion depth in `confirm_candidate`lcnr-0/+6
2023-05-19Auto merge of #110100 - compiler-errors:no-infer-pred-must-hold, r=jackh726bors-23/+32
do not allow inference in `predicate_must_hold` (alternative approach) See the FCP description for more info, but tl;dr is that we should not return `EvaluatedToOkModuloRegions` if an obligation may hold only with some choice of inference vars being constrained. Attempts to solve this in the approach laid out by lcnr here: https://github.com/rust-lang/rust/pull/109558#discussion_r1147318134, rather than by eagerly replacing infer vars with placeholders which is a bit too restrictive. r? `@ghost`
2023-05-18Rollup merge of #111695 - fmease:dont-lump-together-alias-tys, r=compiler-errorsDylan DPC-5/+16
Exclude inherent projections from some alias type `match`es Updating (hopefully) all remaining `match`es which I overlooked to update when adding `AliasKind::Inherent` in #109410. Fixes #111399. Sadly the regression test is a clippy test instead of a rustc one as I don't know of another way to test that a trait bound like `Ty::InhProj: Trait` doesn't cause a crash without reaching a cycle error first (this is getting old ^^'). `@rustbot` label F-inherent_associated_types r? `@compiler-errors`
2023-05-18Rollup merge of #111633 - nnethercote:avoid-ref-format, r=WaffleLapkinDylan DPC-1/+1
Avoid `&format("...")` calls in error message code. Some error message cleanups. Best reviewed one commit at a time. r? `@davidtwco`
2023-05-18Simplify suggestion when returning bare dyn traitMichael Goulet-230/+49
2023-05-17Exclude inherent projections from some alias ty matchesLeón Orell Valerian Liehr-5/+16
2023-05-16suggest `Option::as_deref(_mut)`y21-9/+96
2023-05-16Rollup merge of #111533 - clubby789:drop-tracking-error, r=oli-obkMatthias Krüger-2/+1
Handle error body in generator layout Fixes #111468 I feel like making this query return `Option<GeneratorLayout>` might be better but had some issues with that approach
2023-05-16Use error term if missing associated item in new solverMichael Goulet-1/+15
2023-05-16Rollup merge of #111602 - tmiasko:erroneous-constant-used, r=oli-obkNilstrieb-4/+4
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-16Avoid `&format("...")` calls in error message code.Nicholas Nethercote-1/+1
Error message all end up passing into a function as an `impl Into<{D,Subd}iagnosticMessage>`. If an error message is creatd as `&format("...")` that means we allocate a string (in the `format!` call), then take a reference, and then clone (allocating again) the reference to produce the `{D,Subd}iagnosticMessage`, which is silly. This commit removes the leading `&` from a lot of these cases. This means the original `String` is moved into the `{D,Subd}iagnosticMessage`, avoiding the double allocations. This requires changing some function argument types from `&str` to `String` (when all arguments are `String`) or `impl Into<{D,Subd}iagnosticMessage>` (when some arguments are `String` and some are `&str`).
2023-05-15Give better error when collecting into `&[T]`Chayim Refael Friedman-0/+8
2023-05-15Move expansion of query macros in rustc_middle to rustc_middle::queryJohn Kåre Alsaker-7/+9
2023-05-15Suppress "erroneous constant used" for constants tainted by errorsTomasz Miąsko-4/+4
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-13Handle error body when in generator layoutclubby789-2/+1
2023-05-12do not allow inference in `pred_known_to_hold_modulo_regions`Michael Goulet-21/+23
2023-05-12EvaluateToAmbig if evaluate_root_obligation does inferenceMichael Goulet-3/+10
2023-05-12Note base types of coercionMichael Goulet-51/+50
2023-05-11Auto merge of #111029 - Nilstrieb:when-the-errs-are-too-big, r=petrochenkovbors-7/+19
Shrink `SelectionError` a lot `SelectionError` used to be 80 bytes (on 64 bit). That's quite big. Especially because the selection cache contained `Result<_, SelectionError>. The Ok type is only 32 bytes, so the 80 bytes significantly inflate the size of the cache. Most variants of the `SelectionError` seem to be hard errors, only `Unimplemented` shows up in practice (for cranelift-codegen, it occupies 23.4% of all cache entries). We can just box away the biggest variant, `OutputTypeParameterMismatch`, to get the size down to 16 bytes, well within the size of the Ok type inside the cache.
2023-05-09Consolidate the 'match assumption' type methods in GoalKindMichael Goulet-140/+47
2023-05-09Make alias bounds sound in the new solverMichael Goulet-2/+162
2023-05-09Rename `expected_trait_ref` to `self_ty_trait_ref`Nilstrieb-2/+2
This trait ref is derived from the self type and then equated to the trait ref from the obligation. For example, for `fn(): Fn(u32)`, `self_ty_trait_ref` is `Fn()`, which is then equated to `Fn(u32)` (which will fail, causing the obligation to fail).
2023-05-09Shrink `SelectionError` a lotNilstrieb-5/+17
`SelectionError` used to be 80 bytes (on 64 bit). That's quite big. Especially because the selection cache contained `Result<_, SelectionError>. The Ok type is only 32 bytes, so the 80 bytes significantly inflate the size of the cache. Most variants of the `SelectionError` seem to be hard errors, only `Unimplemented` shows up in practice (for cranelift-codegen, it occupies 23.4% of all cache entries). We can just box away the biggest variant, `OutputTypeParameterMismatch`, to get the size down to 16 bytes, well within the size of the Ok type inside the cache.
2023-05-09Rollup merge of #111252 - matthewjasper:min-spec-improvements, r=compiler-errorsDylan DPC-22/+59
Min specialization improvements - Don't allow specialization impls with no items, such implementations are probably not correct and only occur as mistakes in the compiler and standard library - Fix a missing normalization call - Adds spans for lifetime errors from overly general specializations Closes #79457 Closes #109815
2023-05-08Rollup merge of #109410 - fmease:iat-alias-kind-inherent, r=compiler-errorsMichael Goulet-52/+254
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-07Auto merge of #111161 - compiler-errors:rtn-super, r=cjgillotbors-1/+1
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-06Rollup merge of #110577 - compiler-errors:drop-impl-fulfill, r=lcnrMatthias Krüger-1/+2
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-05Report nicer lifetime errors for specializationMatthew Jasper-7/+39
Add an obligation cause for these error so that the error points to the implementations that caused the error.
2023-05-05Normalize consistently for specializationsMatthew Jasper-17/+22