about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src
AgeCommit message (Collapse)AuthorLines
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
2023-06-19allow caller to force proof tree generationBoxy-72/+89
2023-06-19show normalizes-to hack and response instantiation goalsBoxy-16/+43
2023-06-19introduce a separate set of types for finalized proof treesBoxy-160/+296
2023-06-19dont use a traitBoxy-139/+116
2023-06-19say what kind of cache hitBoxy-8/+14
2023-06-19add -Z flagBoxy-3/+11
2023-06-19initial info dumpBoxy-406/+763
2023-06-19Don't ICE on bound var in reject_fn_ptr_implsMichael Goulet-5/+3
2023-06-18Continue folding in query normalizer on weak aliasesMichael Goulet-2/+6
2023-06-17Move ConstEvaluatable to ClauseMichael Goulet-19/+20
2023-06-17Move WF goal to clauseMichael Goulet-20/+26
2023-06-17Remove even more redundant builtin candidatesMichael Goulet-15/+27
2023-06-17Simplify even more candidatesMichael Goulet-27/+36
2023-06-17Simplify an ObjectData fieldMichael Goulet-4/+8
2023-06-17Simplify some impl source candidatesMichael Goulet-19/+15