about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/traits/mod.rs
AgeCommit message (Collapse)AuthorLines
2023-08-14Point at return type when it influences non-first `match` armEsteban Küber-1/+1
When encountering code like ```rust fn foo() -> i32 { match 0 { 1 => return 0, 2 => "", _ => 1, } } ``` Point at the return type and not at the prior arm, as that arm has type `!` which isn't influencing the arm corresponding to arm `2`. Fix #78124.
2023-08-14Remove constness from `ImplSource::Param`Deadbeef-5/+5
2023-07-30inline format!() args up to and including rustc_middleMatthias Krüger-21/+18
2023-07-25Make everything builtin!Michael Goulet-52/+28
2023-07-25Restore tuple unsizing feature gateMichael Goulet-3/+9
2023-07-24Improve diagnostic for const ctors in array repeat expressionsclubby789-3/+23
2023-07-14refactor(rustc_middle): Substs -> GenericArgMahdi Dibaiee-4/+4
2023-07-05Add some extra information to opaque type cycle errorsOli Scherer-0/+4
2023-07-03Remove chalk from the compilerMichael Goulet-5/+0
2023-06-20yeet upcast_trait_def_id from ImplSourceObjectDataMichael Goulet-4/+0
2023-06-20yeet ImplSource::TraitAlias tooMichael Goulet-19/+0
2023-06-20cleanup importslcnr-6/+0
2023-06-19show normalizes-to hack and response instantiation goalsBoxy-0/+6
2023-06-19initial info dumpBoxy-1/+1
2023-06-17Remove even more redundant builtin candidatesMichael Goulet-36/+3
2023-06-17Simplify even more candidatesMichael Goulet-75/+26
2023-06-17Simplify an ObjectData fieldMichael Goulet-4/+4
2023-06-17Simplify some impl source candidatesMichael Goulet-37/+0
2023-06-17Remove some ImplSource candidatesMichael Goulet-22/+7
2023-06-16Add `AliasKind::Weak` for type aliases.Oli Scherer-0/+3
Only use it when the type alias contains an opaque type. Also does wf-checking on such type aliases.
2023-06-01Implement custom diagnostic for ConstParamTyMichael Goulet-0/+3
2023-05-25Move DefiningAnchorMichael Goulet-0/+11
2023-05-19update recursion depth in `confirm_candidate`lcnr-3/+20
2023-05-12Note base types of coercionMichael Goulet-3/+0
2023-05-09Shrink `SelectionError` a lotNilstrieb-5/+8
`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-04Use fulfillment to check Drop impl compatibilityMichael Goulet-0/+4
2023-05-03Restrict `From<S>` for `{D,Subd}iagnosticMessage`.Nicholas Nethercote-5/+2
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-04-28Rollup merge of #110927 - nnethercote:Encoder-Decoder-cleanups, r=scottmcmMatthias Krüger-7/+7
Encoder/decoder cleanups Best reviewed one commit at a time. r? ``@scottmcm``
2023-04-28Remove some unnecessary derives.Nicholas Nethercote-7/+7
I was curious about how many `Encodable`/`Decodable` derives we have. Some grepping revealed that it's over 500 of each, but the number of `Encodable` ones was higher, which was weird. Most of the `Encodable`-only ones were in `hir.rs`. This commit removes them all, plus some other unnecessary derives in that file and others that I found via trial and error.
2023-04-26Remove unused `TypeFoldable`/`TypeVisitable` impls.Nicholas Nethercote-1/+1
2023-04-09Fix some clippy::complexityNilstrieb-1/+1
2023-03-20Enforce non-lifetime-binders in supertrait preds are not object safeMichael Goulet-2/+11
2023-03-14Remove box expressions from HIRclubby789-2/+0
2023-02-16Clarify `DerivedObligationCause` may hold alias idAlan Egerton-1/+5
2023-02-06Rollup merge of #106477 - ↵Matthias Krüger-0/+2
Nathan-Fenner:nathanf/refined-error-span-trait-impl, r=compiler-errors Refine error spans for "The trait bound `T: Trait` is not satisfied" when passing literal structs/tuples This PR adds a new heuristic which refines the error span reported for "`T: Trait` is not satisfied" errors, by "drilling down" into individual fields of structs/enums/tuples to point to the "problematic" value. Here's a self-contained example of the difference in error span: ```rs struct Burrito<Filling> { filling: Filling, } impl <Filling: Delicious> Delicious for Burrito<Filling> {} fn eat_delicious_food<Food: Delicious>(food: Food) {} fn will_type_error() { eat_delicious_food(Burrito { filling: Kale }); // ^~~~~~~~~~~~~~~~~~~~~~~~~ (before) The trait bound `Kale: Delicious` is not satisfied // ^~~~ (after) The trait bound `Kale: Delicious` is not satisfied } ``` (kale is fine, this is just a silly food-based example) Before this PR, the error span is identified as the entire argument to the generic function `eat_delicious_food`. However, since only `Kale` is the "problematic" part, we can point at it specifically. In particular, the primary error message itself mentions the missing `Kale: Delicious` trait bound, so it's much clearer if this part is called out explicitly. --- The _existing_ heuristic tries to label the right function argument in `point_at_arg_if_possible`. It goes something like this: - Look at the broken base trait `Food: Delicious` and find which generics it mentions (in this case, only `Food`) - Look at the parameter type definitions and find which of them mention `Filling` (in this case, only `food`) - If there is exactly one relevant parameter, label the corresponding argument with the error span, instead of the entire call This PR extends this heuristic by further refining the resulting expression span in the new `point_at_specific_expr_if_possible` function. For each `impl` in the (broken) chain, we apply the following strategy: The strategy to determine this span involves connecting information about our generic `impl` with information about our (struct) type and the (struct) literal expression: - Find the `impl` (`impl <Filling: Delicious> Delicious for Burrito<Filling>`) that links our obligation (`Kale: Delicious`) with the parent obligation (`Burrito<Kale>: Delicious`) - Find the "original" predicate constraint in the impl (`Filling: Delicious`) which produced our obligation. - Find all of the generics that are mentioned in the predicate (`Filling`). - Examine the `Self` type in the `impl`, and see which of its type argument(s) mention any of those generics. - Examing the definition for the `Self` type, and identify (for each of its variants) if there's a unique field which uses those generic arguments. - If there is a unique field mentioning the "blameable" arguments, use that field for the error span. Before we do any of this logic, we recursively call `point_at_specific_expr_if_possible` on the parent obligation. Hence we refine the `expr` "outwards-in" and bail at the first kind of expression/impl we don't recognize. This function returns a `Result<&Expr, &Expr>` - either way, it returns the `Expr` whose span should be reported as an error. If it is `Ok`, then it means it refined successfull. If it is `Err`, then it may be only a partial success - but it cannot be refined even further. --- I added a new test file which exercises this new behavior. A few existing tests were affected, since their error spans are now different. In one case, this leads to a different code suggestion for the autofix - although the new suggestion isn't _wrong_, it is different from what used to be. This change doesn't create any new errors or remove any existing ones, it just adjusts the spans where they're presented. --- Some considerations: right now, this check occurs in addition to some similar logic in `adjust_fulfillment_error_for_expr_obligation` function, which tidies up various kinds of error spans (not just trait-fulfillment error). It's possible that this new code would be better integrated into that function (or another one) - but I haven't looked into this yet. Although this code only occurs when there's a type error, it's definitely not as efficient as possible. In particular, there are definitely some cases where it degrades to quadratic performance (e.g. for a trait `impl` with 100+ generic parameters or 100 levels deep nesting of generic types). I'm not sure if these are realistic enough to worry about optimizing yet. There's also still a lot of repetition in some of the logic, where the behavior for different types (namely, `struct` vs `enum` variant) is _similar_ but not the same. --- I think the biggest win here is better targeting for tuples; in particular, if you're using tuples + traits to express variadic-like functions, the compiler can't tell you which part of a tuple has the wrong type, since the span will cover the entire argument. This change allows the individual field in the tuple to be highlighted, as in this example: ``` // NEW LL | want(Wrapper { value: (3, q) }); | ---- ^ the trait `T3` is not implemented for `Q` // OLD LL | want(Wrapper { value: (3, q) }); | ---- ^~~~~~~~~~~~~~~~~~~~~~~~~ the trait `T3` is not implemented for `Q` ``` Especially with large tuples, the existing error spans are not very effective at quickly narrowing down the source of the problem.
2023-02-03intern external constraintsMichael Goulet-0/+1
2023-01-27Impl HashStable/Encodable/Decodable for ObligationCause.Camille GILLOT-10/+18
2023-01-23Point at specific field in struct literal when trait fulfillment failsNathan Fenner-0/+2
2023-01-23fix: use LocalDefId instead of HirId in trait resVincenzo Palazzo-5/+6
use LocalDefId instead of HirId in trait resolution to simplify the obligation clause resolution Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2022-12-13squash OpaqueTy and ProjectionTy into AliasTyMichael Goulet-1/+1
2022-11-27Prefer doc comments over `//`-comments in compilerMaybe Waffle-1/+1
2022-11-25move 2 candidates into builtin candidatelcnr-23/+0
2022-11-24Avoid `GenFuture` shim when compiling async constructsArpad Borsos-0/+20
Previously, async constructs would be lowered to "normal" generators, with an additional `from_generator` / `GenFuture` shim in between to convert from `Generator` to `Future`. The compiler will now special-case these generators internally so that async constructs will *directly* implement `Future` without the need to go through the `from_generator` / `GenFuture` shim. The primary motivation for this change was hiding this implementation detail in stack traces and debuginfo, but it can in theory also help the optimizer as there is less abstractions to see through.
2022-11-19Improve spans for RPITIT object-safety errorsMichael Goulet-2/+8
2022-11-08selection failure: recompute applicable implslcnr-3/+0
2022-11-05Enforce rust-check ABI in signatures, callsMichael Goulet-0/+2
2022-11-03CleanupsBoxy-1/+8
2022-10-27Revert "Make ClosureOutlivesRequirement not rely on an unresolved type"Michael Goulet-1/+1
This reverts commit a6b5f95fb028f9feb4a2957c06b35035be2c6155.
2022-10-19Make ClosureOutlivesRequirement not rely on an unresolved typeMichael Goulet-1/+1
2022-10-17Duplicate comment in mod.rsSamuel Moelius-5/+0