Skip to content

Cannot infer type should state how to specify the type #61152

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

Open
czipperz opened this issue May 25, 2019 · 2 comments
Open

Cannot infer type should state how to specify the type #61152

czipperz opened this issue May 25, 2019 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-inference Area: Type inference A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@czipperz
Copy link
Contributor

czipperz commented May 25, 2019

For example:

error[E0282]: type annotations needed
  --> src/os_str_join.rs:54:43
   |
54 |         assert_eq!(OsString::from(""), [].join("-".as_ref()));
   |                                           ^^^^ cannot infer type

Without googling, I have no way of understanding how to annotate my empty array with a type.

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. labels May 25, 2019
@estebank estebank added D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 7, 2019
@estebank
Copy link
Contributor

CC #45164

@estebank estebank added the A-inference Area: Type inference label Oct 29, 2019
@estebank
Copy link
Contributor

Current output:

error[E0282]: type annotations needed
 --> src/main.rs:4:39
  |
4 |     assert_eq!(OsString::from(""), [].join("-".as_ref()));
  |                                       ^^^^ cannot infer type

error[E0283]: type annotations needed
 --> src/main.rs:4:39
  |
4 |     assert_eq!(OsString::from(""), [].join("-".as_ref()));
  |                                       ^^^^ cannot infer type for slice `[_]`
  |
  = note: multiple `impl`s satisfying `[_]: Join<&_>` found in the following crates: `alloc`, `std`:
          - impl<S> Join<&OsStr> for [S]
            where S: Borrow<OsStr>;
          - impl<S> Join<&str> for [S]
            where S: Borrow<str>;
          - impl<T, V> Join<&T> for [V]
            where T: Clone, V: Borrow<[T]>;
          - impl<T, V> Join<&[T]> for [V]
            where T: Clone, V: Borrow<[T]>;
note: required by a bound in `slice::<impl [T]>::join`
 --> /rustc/88c58e3c2c097ebffac425d9e080dcb1aadf790e/library/alloc/src/slice.rs:571:5

error[E0283]: type annotations needed
 --> src/main.rs:4:39
  |
4 |     assert_eq!(OsString::from(""), [].join("-".as_ref()));
  |                                       ^^^^     ------ type must be known at this point
  |                                       |
  |                                       cannot infer type of the type parameter `Separator` declared on the associated function `join`
  |
  = note: multiple `impl`s satisfying `str: AsRef<_>` found in the following crates: `core`, `std`:
          - impl AsRef<OsStr> for str;
          - impl AsRef<Path> for str;
          - impl AsRef<[u8]> for str;
          - impl AsRef<str> for str;
help: consider specifying the generic argument
  |
4 |     assert_eq!(OsString::from(""), [].join::<&T>("-".as_ref()));
  |                                           ++++++

@estebank estebank added D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. and removed D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. labels Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-inference Area: Type inference A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. 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

2 participants