Commit Graph

75 Commits

Author SHA1 Message Date
Esteban Küber 049c32797b On E0277, point at type that doesn't implement bound
When encountering an unmet trait bound, point at local type that doesn't implement the trait:

```
error[E0277]: the trait bound `Bar<T>: Foo` is not satisfied
  --> $DIR/issue-64855.rs:9:19
   |
LL | pub struct Bar<T>(<Self as Foo>::Type) where Self: ;
   |                   ^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
   |
help: the trait `Foo` is not implemented for `Bar<T>`
  --> $DIR/issue-64855.rs:9:1
   |
LL | pub struct Bar<T>(<Self as Foo>::Type) where Self: ;
   | ^^^^^^^^^^^^^^^^^
```
2025-08-22 17:55:15 +00:00
lcnr 4eee55691a borrowck: defer opaque type errors 2025-08-08 19:24:53 +02:00
Michael Goulet e9765781b2 Remove the witness type from coroutine args 2025-07-31 17:38:28 +00:00
Michael Goulet d525e79157 Stall coroutines based off of ty::Coroutine, not ty::CoroutineWitness 2025-07-31 17:31:51 +00:00
Michael Goulet 216cdb7b22 Eagerly unify coroutine witness in old solver 2025-07-17 17:42:28 +00:00
Esteban Küber 8c3a033d7f Add edition checks for some tests that had divergent output
In order to expose edition dependent divergences in some tests in the test suite, add explicit `edition` annotations. Some of these tests might require additional work to *avoid* the divergences, as they might have been unintentional. These are not exhaustive changes, purely opportunistic while looking at something else.
2025-06-25 17:02:26 +00:00
Michael Goulet 7e7c2c3947 Just error on recursive opaque ty in HIR typeck 2025-05-20 10:08:56 +00:00
lcnr 9eac7a3e04 move (and remove) impl Trait tests 2025-05-09 02:35:18 +00:00
Vadim Petrochenkov b3f75353a2 UI tests: add missing diagnostic kinds where possible 2025-04-08 23:06:31 +03:00
lcnr 509a144eed add TypingMode::Borrowck 2025-04-03 11:13:10 +02:00
lcnr cfc78cec79 merge opaque types of nested bodies 2025-03-19 17:52:53 +01:00
Oli Scherer cb4751d4b8 Implement #[define_opaque] attribute for functions. 2025-03-11 12:05:02 +00:00
lcnr 83a02619d5 fallout :skull_emoji: 2025-02-14 00:37:23 +01:00
Michael Goulet 2d602ea793 Do not project when there are unconstrained impl params 2025-01-03 05:01:14 +00:00
Michael Goulet d714a22e7b (Re-)Implement impl_trait_in_bindings 2024-12-14 03:21:24 +00:00
Oli Scherer a91c36139a Avoid opaque type not constrained errors in the presence of other errors 2024-12-04 10:16:04 +00:00
Eric Huss 31c9222639 Stabilize the 2024 edition 2024-11-22 11:12:15 -08:00
Esteban Küber b7fc1a7431 Add trait diff highlighting logic and use it in E0277
When a trait is not implemented for a type, but there *is* an `impl`
for another type or different trait params, we format the output to
use highlighting in the same way that E0308 does for types.

The logic accounts for 3 cases:
- When both the type and trait in the expected predicate and the candidate are different
- When only the types are different
- When only the trait generic params are different

For each case, we use slightly different formatting and wording.
2024-11-02 03:08:04 +00:00
León Orell Valerian Liehr 442f39582d Move an impl-Trait check from AST validation to AST lowering 2024-10-27 07:41:52 +01:00
Michael Goulet 99d5f3b280 Stop inverting expectation in normalization errors 2024-10-16 13:44:56 -04:00
Camille GILLOT d9f15faf3a Bless ui tests. 2024-10-04 23:38:41 +00:00
Michael Goulet 05483d5602 Relate receiver invariantly in method probe for Mode::Path 2024-09-16 10:55:07 -04:00
Michael Goulet 789ee88bd0 Tighten spans for async blocks 2024-06-27 15:19:08 -04:00
Oli Scherer 0bc2001879 Require any function with a tait in its signature to actually constrain a hidden type 2024-06-12 08:53:59 +00:00
Oli Scherer 39b39da40b Stop proving outlives constraints on regions we already reported errors on 2024-05-29 09:27:07 +00:00
lcnr 24ee32cf70 borrowck: more eagerly prepopulate opaques 2024-05-06 16:04:57 +00:00
Oli Scherer aef0f4024a Error on using yield without also using #[coroutine] on the closure
And suggest adding the `#[coroutine]` to the closure
2024-04-24 08:05:29 +00:00
Michael Goulet 8995c2c4a2 Use sup instead of eq when unifying self type 2024-04-21 20:10:12 -04:00
Michael Goulet ff4653a08f Use fulfillment, not evaluate, during method probe 2024-04-21 20:10:12 -04:00
Michael Goulet ce5f8c93fa Bless test fallout (duplicate diagnostics) 2024-03-20 13:00:34 -04:00
Oli Scherer 40d5609548 Make DefiningAnchor::Bind only store the opaque types that may be constrained, instead of the current infcx root item.
This makes `Bind` almost always be empty, so we can start forwarding it to queries, allowing us to remove `Bubble` entirely
2024-03-11 17:19:37 +00:00
Michael Goulet ffd30e0a69 Improve error message for opaque captures 2024-03-08 19:08:13 +00:00
Oli Scherer ae50e36dfa Merge collect_mod_item_types query into check_well_formed 2024-03-07 14:26:31 +00:00
Oli Scherer 8206cffc48 Merge check_mod_impl_wf and check_mod_type_wf 2024-03-07 06:27:09 +00:00
bors 09bc67b915 Auto merge of #121679 - lcnr:opaque-wf-check-2, r=oli-obk
stricter hidden type wf-check [based on #115008]

Original work by `@aliemjay` in #115008. A huge thanks to them for originally figuring out this approach ❤️

Fixes https://github.com/rust-lang/rust/issues/114728
Fixes https://github.com/rust-lang/rust/issues/114572

Instead of adding the `WellFormed` obligations when relating opaque types, we now always emit such an obligation when defining the hidden type.

This causes nested opaque types which aren't wf to error, see the comment below for the described impact. I believe this change to be desirable as it significantly reduces complexity by removing special-cases.

It also caused an issue with RPITIT: in defaulted trait methods, we add a `Projection(synthetic_assoc, rpit_of_trait_method)` clause to the `param_env`. This clause is not added to the `ParamEnv` of the nested coroutines. This caused a normalization failure in `fn check_coroutine_obligations` with the new solver. I fixed that by using the env of the typeck root instead.

r? `@oli-obk`
2024-03-06 10:04:26 +00:00
Esteban Küber f0c93117ed Use root obligation on E0277 for some cases
When encountering trait bound errors that satisfy some heuristics that
tell us that the relevant trait for the user comes from the root
obligation and not the current obligation, we use the root predicate for
the main message.

This allows to talk about "X doesn't implement Pattern<'_>" over the
most specific case that just happened to fail, like  "char doesn't
implement Fn(&mut char)" in
`tests/ui/traits/suggest-dereferences/root-obligation.rs`

The heuristics are:

 - the type of the leaf predicate is (roughly) the same as the type
   from the root predicate, as a proxy for "we care about the root"
 - the leaf trait and the root trait are different, so as to avoid
   talking about `&mut T: Trait` and instead remain talking about
   `T: Trait` instead
 - the root trait is not `Unsize`, as to avoid talking about it in
   `tests/ui/coercion/coerce-issue-49593-box-never.rs`.

```
error[E0277]: the trait bound `&char: Pattern<'_>` is not satisfied
  --> $DIR/root-obligation.rs:6:38
   |
LL |         .filter(|c| "aeiou".contains(c))
   |                             -------- ^ the trait `Fn<(char,)>` is not implemented for `&char`, which is required by `&char: Pattern<'_>`
   |                             |
   |                             required by a bound introduced by this call
   |
   = note: required for `&char` to implement `FnOnce<(char,)>`
   = note: required for `&char` to implement `Pattern<'_>`
note: required by a bound in `core::str::<impl str>::contains`
  --> $SRC_DIR/core/src/str/mod.rs:LL:COL
help: consider dereferencing here
   |
LL |         .filter(|c| "aeiou".contains(*c))
   |                                      +
```

Fix #79359, fix #119983, fix #118779, cc #118415 (the suggestion needs
to change).
2024-03-03 18:53:35 +00:00
lcnr 71d82c2899 when defining opaques, require the hidden type to be well-formed 2024-02-27 15:57:49 +01:00
lcnr c71484eefd change error messages to be incorrect, but more helpful 2024-02-22 18:18:33 +01:00
lcnr 49dc0f22f4 do not use <: in subtyping overflow msg 2024-02-22 17:43:59 +01:00
lcnr f7cdff825c overflow errors: change source to a concrete enum 2024-02-22 17:43:57 +01:00
lcnr f392a870e9 freshen: resolve root vars
Without doing so we use the same candidate cache entry
for `?0: Trait<?1>` and `?0: Trait<?0>`. These goals are different
and we must not use the same entry for them.
2024-02-22 17:29:26 +01:00
lcnr 91535ad026 remove sub_relations from infcx, recompute in diagnostics
we don't track them when canonicalizing or when freshening,
resulting in instable caching in the old solver, and issues when
instantiating query responses in the new one.
2024-02-22 17:29:25 +01:00
许杰友 Jieyou Xu (Joe) ec2cc761bc [AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
Matthias Krüger 73256c68b8 Rollup merge of #119818 - oli-obk:even_more_follow_up_errors3, r=compiler-errors
Silence some follow-up errors [3/x]

this is one piece of the requested cleanups from https://github.com/rust-lang/rust/pull/117449

Keep error types around, even in obligations.

These help silence follow-up errors, as we now figure out that some types (most notably inference variables) are equal to an error type.

But it also allows figuring out more types in the presence of errors, possibly causing more errors.
2024-01-15 08:44:46 +01:00
George-lewis d56cdd48cb Bless tests
Update tests
2024-01-13 12:46:58 -05:00
Oli Scherer fb44c848c3 Keep error types around, even in obligations.
These help silence follow up errors
2024-01-11 09:52:25 +00:00
Nicholas Nethercote 2aac288c18 Use the right level with -Ztreat-err-as-bug.
Errors in `DiagCtxtInner::emit_diagnostic` are never set to
`Level::Bug`, because the condition never succeeds, because
`self.treat_err_as_bug()` is called *before* the error counts are
incremented.

This commit switches to `self.treat_next_err_as_bug()`, fixing the
problem. This changes the error message output to actually say "internal
compiler error".
2024-01-11 16:55:10 +11:00
Oli Scherer 0978f6e010 Avoid silencing relevant follow-up errors 2024-01-09 21:08:16 +00:00
Michael Goulet 7e38b70cc0 Split note, fix const/static impl trait error 2024-01-07 18:00:03 +00:00
Oli Scherer cd4c352fb4 Reorder check_item_type diagnostics so they occur next to the corresponding check_well_formed diagnostics 2024-01-02 14:17:56 +00:00