about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection
AgeCommit message (Collapse)AuthorLines
2023-07-03Remove chalk from the compilerMichael Goulet-163/+6
2023-07-03add flag for disabling global cache and printing proof trees on errorBoxy-46/+149
2023-07-03Helpers for creating EvalCtxts, some commentsMichael Goulet-153/+174
2023-07-03Implement selection in new trait solverMichael Goulet-21/+352
2023-07-03rebaselcnr-2/+2
2023-07-03reviewlcnr-16/+25
2023-07-03`deeply_normalize` pass in fulfill cx for old solverlcnr-12/+15
2023-07-03use `deeply_normalize` for `assumed_wf_types`lcnr-10/+26
2023-07-03add deep normalization via the new solverlcnr-6/+280
2023-07-03add instrument to `register_predicate_obligation`lcnr-0/+1
2023-07-01Auto merge of #113154 - lcnr:better-probe-check, r=compiler-errorsbors-82/+59
change snapshot tracking in fulfillment contexts use the exact snapshot number to prevent misuse even when created inside of a snapshot
2023-06-30assemble_candidates_after_normalizing_self_ty docslcnr-4/+13
2023-06-29Auto merge of #113108 - ↵bors-11/+2
compiler-errors:normalize-opaques-with-late-bound-vars-again, r=jackh726 Normalize opaques with late-bound vars again We have a hack in the compiler where if an opaque has escaping late-bound vars, we skip revealing it even though we *could* reveal it from a technical perspective. First of all, this is weird, since we really should be revealing all opaques in `Reveal::All` mode. Second of all, it causes subtle bugs (linked below). I attempted to fix this in #100980, which was unfortunately reverted due to perf regressions on codebases that used really deeply nested futures in some interesting ways. The worst of which was #103423, which caused the project to hang on build. Another one was #104842, which was just a slow-down, but not a hang. I took some time afterwards to investigate how to rework `normalize_erasing_regions` to take advantage of better caching, but that effort kinda fizzled out (#104133). However, recently, I was made aware of more bugs whose root cause is not revealing opaques during codegen. That made me want to fix this again -- in the process, interestingly, I took the the minimized example from https://github.com/rust-lang/rust/issues/103423#issuecomment-1292947043, and it doesn't seem to hang any more... Thinking about this harder, there have been some changes to the way we lower and typecheck async futures that may have reduced the pathologically large number of outlives obligations (see description of #103423) that we were encountering when normalizing opaques with bound vars the last time around: * #104321 (lower `async { .. }` directly as a generator that implements `Future`, removing the `from_generator` shim) * #104833 (removing an `identity_future` fn that was wrapping desugared future generators) ... so given that I can see: * No significant regression on rust perf bot (https://github.com/rust-lang/rust/pull/107620#issuecomment-1600070317) * No timeouts in crater run I did (https://github.com/rust-lang/rust/pull/107620#issuecomment-1605428952, rechecked failing crates in https://github.com/rust-lang/rust/pull/107620#issuecomment-1605973434) ... and given that this PR: * Fixes #104601 * Fixes #107557 * Fixes #109464 * Allows us to remove a `DefiningAnchor::Bubble` from codegen (75a8f681837c70051e0200a14f58ae07dbe58e66) I'm inclined to give this another shot at landing this. Best case, it just works -- worst case, we get more examples to study how we need to improve the compiler to make this work. r? types
2023-06-29change snapshot tracking in fulfillment contextslcnr-82/+59
2023-06-28convert to fluent, make plurals workMichael Goulet-11/+48
2023-06-28Do not suggest adjusting trait signature on type mismatchMichael Goulet-0/+4
2023-06-28reword message to be less vagueMichael Goulet-2/+2
2023-06-28Rollup merge of #112867 - compiler-errors:more-impl-source-nits, r=lcnrDylan DPC-66/+43
More `ImplSource` nits Even more clean-ups, I'll put this up in parallel with the `select_in_new_trait_solver` PR. r? ``@lcnr``
2023-06-27Don't sort strings right after we just sorted by typesMichael Goulet-27/+31
2023-06-27Normalize opaques with escaping bound varsMichael Goulet-11/+2
2023-06-26TypeWellFormedInEnvMichael Goulet-16/+20
2023-06-26Migrate predicates_of and caller_bounds to ClauseMichael Goulet-134/+90
2023-06-24use Const::eval instead of QueryNormalize in error reportingMichael Goulet-25/+23
2023-06-23Rollup merge of #112965 - compiler-errors:circular-wf, r=aliemjayMichael Goulet-2/+10
Don't emit same goal as input during `wf::unnormalized_obligations` r? `@aliemjay` cc `@lcnr` I accidentally pruned the logic to handle `WF(?0)` when writing `wf::unnormalized_obligations`. idk if you wanted to construct a test first, but this is an obvious fix. Copied the comment from above. Fixes rust-lang/trait-system-refactor-initiative#36
2023-06-23Rollup merge of #112870 - compiler-errors:clause-2, r=oli-obkMatthias Krüger-15/+15
Migrate `item_bounds` to `ty::Clause` Should be simpler than the next PR that's coming up. Last three commits are the relevant ones. r? ``@oli-obk`` or ``@lcnr``
2023-06-23Resolve vars when reporting WF errorMichael Goulet-0/+1
2023-06-23Don't emit same goal as input during wf obligationsMichael Goulet-2/+9
2023-06-22Avoid guessing unknown trait impl in suggestionsAlexander Zhang-6/+10
When a trait is used without specifying the implementation (e.g. calling a non-member associated function without fully-qualified syntax) and there are multiple implementations available, use a placeholder comment for the implementation type in the suggestion instead of picking a random implementation. Example: ``` fn main() { let _ = Default::default(); } ``` Previous output: ``` error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type --> test.rs:2:13 | 2 | let _ = Default::default(); | ^^^^^^^^^^^^^^^^ cannot call associated function of trait | help: use a fully-qualified path to a specific available implementation (273 found) | 2 | let _ = <FileTimes as Default>::default(); | +++++++++++++ + ``` New output: ``` error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type --> test.rs:2:13 | 2 | let _ = Default::default(); | ^^^^^^^^^^^^^^^^ cannot call associated function of trait | help: use a fully-qualified path to a specific available implementation (273 found) | 2 | let _ = </* self type */ as Default>::default(); | +++++++++++++++++++ + ```
2023-06-22Migrate item_bounds to ty::ClauseMichael Goulet-15/+15
2023-06-22Auto merge of #112686 - estebank:sealed-traits, r=petrochenkovbors-0/+26
Account for sealed traits in privacy and trait bound errors On trait bound errors caused by super-traits, identify if the super-trait is publicly accessibly and if not, explain "sealed traits". ``` error[E0277]: the trait bound `S: Hidden` is not satisfied --> $DIR/sealed-trait-local.rs:17:20 | LL | impl a::Sealed for S {} | ^ the trait `Hidden` is not implemented for `S` | note: required by a bound in `Sealed` --> $DIR/sealed-trait-local.rs:3:23 | LL | pub trait Sealed: self::b::Hidden { | ^^^^^^^^^^^^^^^ required by this bound in `Sealed` = note: `Sealed` is a "sealed trait", because to implement it you also need to implelement `a::b::Hidden`, which is not accessible; this is usually done to force you to use one of the provided types that already implement it ``` Deduplicate privacy errors that point to the same path segment even if their deduplication span are different. When encountering a path that is not reachable due to privacy constraints path segments other than the last, keep metadata for the last path segment's `Res` in order to look for alternative import paths for that item to suggest. If there are none, be explicit that the item is not accessible. ``` error[E0603]: module `b` is private --> $DIR/re-exported-trait.rs:11:9 | LL | impl a::b::Trait for S {} | ^ private module | note: the module `b` is defined here --> $DIR/re-exported-trait.rs:5:5 | LL | mod b { | ^^^^^ help: consider importing this trait through its public re-export instead | LL | impl a::Trait for S {} | ~~~~~~~~ ``` ``` error[E0603]: module `b` is private --> $DIR/private-trait.rs:8:9 | LL | impl a::b::Hidden for S {} | ^ ------ trait `b` is not publicly reachable | | | private module | note: the module `b` is defined here --> $DIR/private-trait.rs:2:5 | LL | mod b { | ^^^^^ ```
2023-06-22Account for sealed traits in trait bound errorsEsteban Küber-0/+26
When implementing a public trait with a private super-trait, we now emit a note that the missing bound is not going to be able to be satisfied, and we explain the concept of a sealed trait.
2023-06-21Don't substitute a GAT that has mismatched generics in OpaqueTypeCollectorMichael Goulet-45/+46
2023-06-21Rollup merge of #112772 - compiler-errors:clauses-1, r=lcnrNilstrieb-136/+145
Add a fully fledged `Clause` type, rename old `Clause` to `ClauseKind` Does two basic things before I put up a more delicate set of PRs (along the lines of #112714, but hopefully much cleaner) that migrate existing usages of `ty::Predicate` to `ty::Clause` (`predicates_of`/`item_bounds`/`ParamEnv::caller_bounds`). 1. Rename `Clause` to `ClauseKind`, so it's parallel with `PredicateKind`. 2. Add a new `Clause` type which is parallel to `Predicate`. * This type exposes `Clause::kind(self) -> Binder<'tcx, ClauseKind<'tcx>>` which is parallel to `Predicate::kind` 😸 The new `Clause` type essentially acts as a newtype wrapper around `Predicate` that asserts that it is specifically a `PredicateKind::Clause`. Turns out from experimentation[^1] that this is not negative performance-wise, which is wonderful, since this a much simpler design than something that requires encoding the discriminant into the alignment bits of a predicate kind, or something else like that... r? ``@lcnr`` or ``@oli-obk`` [^1]: https://github.com/rust-lang/rust/pull/112714#issuecomment-1595653910
2023-06-20yeet upcast_trait_def_id from ImplSourceObjectDataMichael Goulet-6/+2
2023-06-20yeet ImplSource::TraitAlias tooMichael Goulet-11/+7
2023-06-20Remove unnecessary call to select_from_obligationMichael Goulet-49/+34
The only regression is one ambiguity in the new trait solver, having to do with two param-env candidates that may apply. I think this is fine, since the error message already kinda sucks.
2023-06-20Auto merge of #112835 - lcnr:proof-tree-nits, r=BoxyUwUbors-287/+298
proof tree nits r? `@BoxyUwU`
2023-06-20inspect nitslcnr-147/+158
2023-06-20cleanup importslcnr-13/+8
2023-06-20split probe into 2 functions for better readabilitylcnr-127/+132
2023-06-20Auto merge of #112320 - compiler-errors:do-not-impl-via-obj, r=lcnrbors-1/+13
Add `implement_via_object` to `rustc_deny_explicit_impl` to control object candidate assembly Some built-in traits are special, since they are used to prove facts about the program that are important for later phases of compilation such as codegen and CTFE. For example, the `Unsize` trait is used to assert to the compiler that we are able to unsize a type into another type. It doesn't have any methods because it doesn't actually *instruct* the compiler how to do this unsizing, but this is later used (alongside an exhaustive match of combinations of unsizeable types) during codegen to generate unsize coercion code. Due to this, these built-in traits are incompatible with the type erasure provided by object types. For example, the existence of `dyn Unsize<T>` does not mean that the compiler is able to unsize `Box<dyn Unsize<T>>` into `Box<T>`, since `Unsize` is a *witness* to the fact that a type can be unsized, and it doesn't actually encode that unsizing operation in its vtable as mentioned above. The old trait solver gets around this fact by having complex control flow that never considers object bounds for certain built-in traits: https://github.com/rust-lang/rust/blob/2f896da247e0ee8f0bef7cd7c54cfbea255b9f68/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs#L61-L132 However, candidate assembly in the new solver is much more lovely, and I'd hate to add this list of opt-out cases into the new solver. Instead of maintaining this complex and hard-coded control flow, instead we can make this a property of the trait via a built-in attribute. We already have such a build attribute that's applied to every single trait that we care about: `rustc_deny_explicit_impl`. This PR adds `implement_via_object` as a meta-item to that attribute that allows us to opt a trait out of object-bound candidate assembly as well. r? `@lcnr`
2023-06-20Merge attrs, better validationMichael Goulet-0/+8
2023-06-20Add rustc_do_not_implement_via_objectMichael Goulet-1/+5
2023-06-19Rollup merge of #112781 - compiler-errors:new-solver-tait-overlaps-hidden, ↵Michael Goulet-8/+29
r=lcnr Don't consider TAIT normalizable to hidden ty if it would result in impossible item bounds See test for example where we shouldn't consider it possible to alias-relate a TAIT and hidden type. r? `@lcnr`
2023-06-19Rollup merge of #112783 - compiler-errors:nlb-fnptr-reject-ice, r=fee1-deadMatthias Krüger-5/+3
Don't ICE on bound var in `reject_fn_ptr_impls` We may try to use an impl like `impl<T: FnPtr> PartialEq {}` to satisfy a predicate like `for<T> T: PartialEq` -- don't ICE in that case. Fixes #112735
2023-06-19Rollup merge of #112777 - compiler-errors:normalize-weak-more, r=oli-obkMatthias Krüger-2/+6
Continue folding in query normalizer on weak aliases Fixes #112752 Fixes #112731 (same root cause, so didn't make a test for it) fixes #112776 r? ```@oli-obk```
2023-06-19Fully fledged Clause typeMichael Goulet-6/+6
2023-06-19s/Clause/ClauseKindMichael Goulet-136/+145
2023-06-19Don't consider TAIT normalizable to hidden ty if it would result in ↵Michael Goulet-8/+29
impossible item bounds
2023-06-19create module so that RUSTC_LOG can filter to just proof treesBoxy-1/+9