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

Compile message contains reference to an identifier not used by the erraneous code #63852

Closed
svenschmidt75 opened this issue Aug 24, 2019 · 7 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-inference Area: Type inference C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@svenschmidt75
Copy link

rustc 1.37.0 (eae3437 2019-08-13)

Repo: https://github.com/svenschmidt75/Rust
Commit: svenschmidt75/Rust@23ec342

When building, I get error message

   Compiling ann v0.1.0 (/home/svenschmidt75/Develop/Rust/NeuralNetwork/lib/ann)
error[E0282]: type annotations needed
  --> lib/ann/src/ann/cost_function.rs:25:9
   |
25 |         diff2.iter().sum() as f64 / 2.0
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for `S`
   |
   = note: type must be known at this point

error: aborting due to previous error

For more information about this error, try `rustc --explain E0282`.
error: Could not compile `ann`.
warning: build failed, waiting for other jobs to finish...
error[E0282]: type annotations needed
  --> lib/ann/src/ann/cost_function.rs:25:9
   |
25 |         diff2.iter().sum() as f64 / 2.0
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for `S`
   |
   = note: type must be known at this point

error: aborting due to previous error

For more information about this error, try `rustc --explain E0282`.
error: Could not compile `ann`.

To learn more, run the command again with --verbose.

Process finished with exit code 101

Where does S come from?

Thanks,

@jonas-schievink
Copy link
Contributor

S is the generic parameter of Iterator::sum().

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-inference Area: Type inference labels Aug 24, 2019
@estebank
Copy link
Contributor

@svenschmidt75 would the following output be enough for you to understand what was happening?

error[E0282]: type annotations needed
  --> lib/ann/src/ann/cost_function.rs:25:9
   |
25 |         diff2.iter().sum() as f64 / 2.0
   |                      ^^^ cannot infer type for `S`
   |
   = note: type must be known at this point

@ghost
Copy link

ghost commented Aug 25, 2019

IMO it is better to see where the problem is coming from. But there is still no obvious connection between 'S' and sum().
But the explanation from @jonas-schievink and the doc does explain it good.

fn sum<S>(self) -> S

@jonas-schievink
Copy link
Contributor

It would probably help a lot if the message tells you what S is. Something like

error[E0282]: type annotations needed
  --> lib/ann/src/ann/cost_function.rs:25:9
   |
25 |         diff2.iter().sum() as f64 / 2.0
   |                      ^^^ cannot infer type of type parameter `S`
   |
   = note: type must be known at this point

@svenschmidt75
Copy link
Author

@estebank It is definitely an improvement. Is there any way that the trait can be mentioned as well? I agree with @BO41...

@estebank
Copy link
Contributor

@svenschmidt75 I've been looking at doing that but will require a much larger refactor to mention either Iterator::sum or Sum<Iterator::Item>. I'll leave this ticket open, but I feel that the small PR I put together is a good stop gap to marginally improve things.

bors added a commit that referenced this issue Aug 26, 2019
Point at method call on missing annotation error

Make it clearer where the type name that couldn't be inferred comes from.

Before:

```
error[E0282]: type annotations needed
 --> src/test/ui/span/type-annotations-needed-expr.rs:2:13
  |
2 |     let _ = (vec![1,2,3]).into_iter().sum() as f64; //~ ERROR E0282
  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for `S`
  |
  = note: type must be known at this point
```
after
```
error[E0282]: type annotations needed
 --> src/test/ui/span/type-annotations-needed-expr.rs:2:39
  |
2 |     let _ = (vec![1,2,3]).into_iter().sum() as f64; //~ ERROR E0282
  |                                       ^^^ cannot infer type for `S`
  |
  = note: type must be known at this point
```

CC #63852.
@compiler-errors
Copy link
Member

This has improved in the mean time slightly:

error[[E0282]](https://doc.rust-lang.org/stable/error-index.html#E0282): type annotations needed
 --> src/lib.rs:2:18
  |
2 |     diff2.iter().sum() as f64 / 2.0
  |                  ^^^ cannot infer type of the type parameter `S` declared on the associated function `sum`
  |
help: consider specifying the generic argument
  |
2 |     diff2.iter().sum::<S>() as f64 / 2.0
  |                     +++++

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

I'm probably gonna close this because it suggests the turbofish and mentions that S is a parameter of sum

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 C-enhancement Category: An issue proposing an enhancement or a PR with one. 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

4 participants