Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc reports misc message with impl conflict of trait with AFIT and assoc type. #116982

Closed
Berrysoft opened this issue Oct 20, 2023 · 2 comments · Fixed by #117133
Closed

rustc reports misc message with impl conflict of trait with AFIT and assoc type. #116982

Berrysoft opened this issue Oct 20, 2023 · 2 comments · Fixed by #117133
Assignees
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. F-async_fn_in_trait Static async fn in traits T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Berrysoft
Copy link
Contributor

Code

trait Foo {
    type T;
    
    async fn foo(&self) -> Self::T;
}

struct Bar;

impl Foo for Bar {
    type T = ();

    async fn foo(&self) {}
}

impl Foo for Bar {
    type T = ();

    async fn foo(&self) {}
}

Current output

error[E0284]: type annotations needed: cannot satisfy `<Bar as Foo>::T == ()`
  --> src/main.rs:12:5
   |
12 |     async fn foo(&self) {}
   |     ^^^^^^^^^^^^^^^^^^^ cannot satisfy `<Bar as Foo>::T == ()`

error[E0284]: type annotations needed: cannot satisfy `<Bar as Foo>::T == ()`
  --> src/main.rs:18:5
   |
18 |     async fn foo(&self) {}
   |     ^^^^^^^^^^^^^^^^^^^ cannot satisfy `<Bar as Foo>::T == ()`

For more information about this error, try `rustc --explain E0284`.

Desired output

error[E0119]: conflicting implementations of trait `Foo` for type `Bar`
  --> src/main.rs:11:1
   |
9  | impl Foo for Bar {
   | ---------------- first implementation here
...
15 | impl Foo for Bar {
   | ^^^^^^^^^^^^^^^^ conflicting implementation for `Bar`

For more information about this error, try `rustc --explain E0119`.

Rationale and extra context

No response

Other cases

No response

Anything else?

No response

@Berrysoft Berrysoft added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 20, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 20, 2023
@compiler-errors compiler-errors self-assigned this Oct 20, 2023
@Noratrieb Noratrieb removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 20, 2023
@fmease fmease added D-confusing Diagnostics: Confusing error or lint that should be reworked. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. A-async-await Area: Async & Await labels Oct 20, 2023
@compiler-errors compiler-errors added the F-async_fn_in_trait Static async fn in traits label Oct 20, 2023
@compiler-errors
Copy link
Member

(for compiler people:) We could fix this by merging the impl WF and coherence checks into one compiler stage. I'll put up a PR and see what T-types thinks.

@traviscross
Copy link
Contributor

@rustbot labels +AsyncAwait-Triaged

We discussed this in a WG-async meeting and are deferring to the resolution @compiler-errors suggested above. He noted that this is a fix to the diagnostics only. That fact that this is an error is correct.

@rustbot rustbot added the AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. label Oct 23, 2023
@bors bors closed this as completed in 96074be Oct 25, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 25, 2023
Rollup merge of rust-lang#117133 - compiler-errors:coherence-constrained, r=oli-obk

Merge `impl_wf_inference` (`check_mod_impl_wf`) check into coherence checking

Problem here is that we call `collect_impl_trait_in_trait_types` when checking `check_mod_impl_wf` which is performed before coherence. Due to the `tcx.sess.track_errors`, since we end up reporting an error, we never actually proceed to coherence checking, where we would be emitting a more useful impl overlap error.

This change means that we may report more errors in some cases, but can at least proceed far enough to leave a useful message for overlapping traits with RPITITs in them.

Fixes rust-lang#116982

r? types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. F-async_fn_in_trait Static async fn in traits T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants