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

Confusing E0284 "type annotations needed" when trait method bound trait bound conflict in associated type. #105513

Open
zachs18 opened this issue Dec 9, 2022 · 0 comments
Labels
A-associated-items Area: Associated items (types, constants & functions) A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system 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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@zachs18
Copy link
Contributor

zachs18 commented Dec 9, 2022

Given the following code (playground link):

pub trait Extension: IntoIterator<Item = u32> + Sized {
    fn test(self) -> Vec<u64>
    where
        Self: IntoIterator<Item = u64>,
    {
        self.into_iter().collect()
    }
}

(i.e. the bound on fn test conflicts with the bound of its trait by way of associated types)

The current output is:

error[E0284]: type annotations needed: cannot satisfy `<Self as IntoIterator>::Item == u32`
  |
note: required by a bound in `Extension`
 --> src/lib.rs:1:35
  |
1 | pub trait Extension: IntoIterator<Item = u32> + Sized {
  |                                   ^^^^^^^^^^ required by this bound in `Extension`

For more information about this error, try `rustc --explain E0284`.
error: could not compile `playground` due to previous error

Ideally the output should look like: something mentioning the conflicting bounds. (Or under #![feature(trivial_bounds)], maybe it could just be a trivially false bound?).

error[E0000]: conflicting bounds: cannot satisfy both `<Self as IntoIterator>::Item == u32` and `<Self as IntoIterator>::Item == u64`
  |
note: bounds in `Extension` and `fn test`
 --> src/lib.rs:1:35
  |
1 | pub trait Extension: IntoIterator<Item = u32> + Sized {
  |                                   ^^^^^^^^^^ required by this bound in `Extension`
4 |         Self: IntoIterator<Item = u64>,
  |                            ^^^^^^^^^^ required by this bound in `fn test`

error: could not compile `playground` due to previous error

Same result on stable, beta, and nightly.

Related: #103292, (can't find the issue at the moment, but impl<T: Trait<Assoc = u32>> SecondTrait for T conflicting with impl<T: Trait<Assoc = u64>> SecondTrait for T when it shouldn't is related).

@rustbot modify labels +A-traits +D-confusing +A-associated-items

@zachs18 zachs18 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 Dec 9, 2022
@rustbot rustbot added A-associated-items Area: Associated items (types, constants & functions) A-trait-system Area: Trait system D-confusing Diagnostics: Confusing error or lint that should be reworked. labels Dec 9, 2022
@estebank estebank added the D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. label Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system 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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants