about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src/traits
AgeCommit message (Collapse)AuthorLines
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-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-50/+242
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
2023-05-05forbid escaping bound vars in combinelcnr-117/+38
removes the `CollectAllMismatches` in favor of a slightly more manual approach.
2023-05-04Use fulfillment to check Drop impl compatibilityMichael Goulet-1/+2
2023-05-04IAT: Proper WF computationLeón Orell Valerian Liehr-54/+99
2023-05-04IAT: Introduce AliasKind::InherentLeón Orell Valerian Liehr-21/+168
2023-05-04Auto merge of #110806 - WaffleLapkin:unmkI, r=lcnrbors-51/+60
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-1/+1
2023-05-04Rollup merge of #110791 - compiler-errors:negative-bounds, r=oli-obkDylan DPC-0/+24
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-03Restrict `From<S>` for `{D,Subd}iagnosticMessage`.Nicholas Nethercote-90/+88
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/+20
2023-05-02Implement negative boundsMichael Goulet-0/+4
2023-05-02Rollup merge of #108161 - WaffleLapkin:const_param_ty, r=BoxyUwUDylan DPC-15/+86
Add `ConstParamTy` trait This is a bit sketch, but idk. r? `@BoxyUwU` Yet to be done: - [x] ~~Figure out if it's okay to implement `StructuralEq` for primitives / possibly remove their special casing~~ (it should be okay, but maybe not in this PR...) - [ ] Maybe refactor the code a little bit - [x] Use a macro to make impls a bit nicer Future work: - [ ] Actually™ use the trait when checking if a `const` generic type is allowed - [ ] _Really_ refactor the surrounding code - [ ] Refactor `marker.rs` into multiple modules for each "theme" of markers
2023-04-27Make async removal span more resilient to macro expansionsMichael Goulet-6/+8
2023-04-27tweak removal spanMichael Goulet-1/+8
2023-04-27Tweak await spanMichael Goulet-41/+45
2023-04-27Impl `StructuralEq` & `ConstParamTy` for `str`, `&T`, `[T; N]` and `[T]`Maybe Waffle-1/+8
2023-04-27Check the correct trait when checking `ConstParamTy` implsMaybe Waffle-1/+1
2023-04-27Add a `ConstParamTy` traitMaybe Waffle-15/+79
2023-04-27rename `needs_subst` to `has_param`Boxy-3/+3
2023-04-27rename `needs_infer` to `has_infer`Boxy-15/+16
2023-04-26Don't return a `Binder` from `TraitRef::identity`Maybe Waffle-6/+7
2023-04-26Add new `ToPredicate` impls and `TraitRef` methods to remove some ↵Maybe Waffle-21/+11
`ty::Binber::dummy` calls
2023-04-26Switch `ty::TraitRef::from_lang_item` from using `TyCtxtAt` to `TyCtxt` and ↵Maybe Waffle-8/+11
a `Span`
2023-04-26Remove some more useless `ty::Binder::dummy` callsMaybe Waffle-5/+2
2023-04-26Make some region folders a little stricter.Nicholas Nethercote-4/+4
Because certain regions cannot occur in them.
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-25Remove some useless `ty::Binder::dummy` callsMaybe Waffle-6/+3
2023-04-25Replace `tcx.mk_trait_ref` with `ty::TraitRef::new`Maybe Waffle-41/+62
2023-04-25Rollup merge of #110563 - ↵Matthias Krüger-438/+678
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`.
2023-04-24Rollup merge of #110566 - compiler-errors:bad-projection-term, ↵Matthias Krüger-8/+23
r=cjgillot,BoxyUwU Don't create projection ty for const projection Fixes #110549
2023-04-24Rollup merge of #110514 - compiler-errors:remove-find_map_relevant_impl, ↵Matthias Krüger-71/+96
r=b-naber Remove `find_map_relevant_impl` Fixes #108895
2023-04-23Don't create projection ty for const projectionMichael Goulet-8/+23
2023-04-21Create "AppendConstMessage" enumBryan Garza-18/+28
This patch creates an enum to replace a nested `Option`.
2023-04-21Break up long function in trait selection error reportingBryan Garza-427/+657
- Move blocks of code into their own functions - Replace a few function argument types with their type aliases
2023-04-20add subst_identity_iter and subst_identity_iter_copied methods on ↵Kyle Matsuda-2/+1
EarlyBinder; use this to simplify some EarlyBinder noise around explicit_item_bounds calls
2023-04-20add EarlyBinder to output of explicit_item_bounds; replace ↵Kyle Matsuda-1/+1
bound_explicit_item_bounds usages; remove bound_explicit_item_bounds query
2023-04-20change usages of explicit_item_bounds to bound_explicit_item_boundsKyle Matsuda-2/+3
2023-04-20Remove WithOptconstParam.Camille GILLOT-14/+10
2023-04-19Rollup merge of #110531 - lcnr:type-system-stuff, r=aliemjayMatthias Krüger-20/+11
small type system cleanup