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

More clearly Error Message: Calculating with different types #34698

Closed
StefanoD opened this issue Jul 7, 2016 · 3 comments
Closed

More clearly Error Message: Calculating with different types #34698

StefanoD opened this issue Jul 7, 2016 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@StefanoD
Copy link

StefanoD commented Jul 7, 2016

This yields with rust 1.9

let result = -0.25 % 2;

following error message:

:7:18: 7:27 error: the trait bound _: std::ops::Rem<_> is not satisfied [E0277]
:7 let result = -0.25 % 2;
^~~~~~~~~
:7:18: 7:27 help: see the detailed explanation for E0277
:7:18: 7:27 help: the following implementations were found:
:7:18: 7:27 help:
:7:18: 7:27 help: <&'a f64 as std::ops::Rem>
:7:18: 7:27 help: <f64 as std::ops::Rem<&'a f64>>
:7:18: 7:27 help: <&'b f64 as std::ops::Rem<&'a f64>>
:7:18: 7:27 help: and 54 others
error: aborting due to previous error

This is the fix:

let result = -0.25 % 2.0;

This is a really compilicated error message for the fact, that calucating with different types are not allowed.

@apasel422 apasel422 added the A-diagnostics Area: Messages for errors, warnings, and lints label Jul 7, 2016
@brson
Copy link
Contributor

brson commented Jul 8, 2016

cc @jonathandturner

@sophiajt
Copy link
Contributor

sophiajt commented Jul 8, 2016

cc @nikomatsakis - who was thinking about better type error reporting

@steveklabnik steveklabnik removed the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
bors added a commit that referenced this issue Apr 10, 2017
Explicit help message for binop type mismatch

When trying to do `1 + Some(2)`, or some other binary operation on two
types different types without an appropriate trait implementation, provide
an explicit help message:

```rust
help: `{integer} + std::option::Option<{integer}>` has no implementation
```

Re: #39579, #38564, #37626, #39942, #34698.
@Mark-Simulacrum
Copy link
Member

Fixed today, I think. We don't give a suggestion as to float % float but I don't really think that's feasible.

rustc 1.19.0-dev (5dfcd85fd 2017-05-19)
error[E0277]: the trait bound `{float}: std::ops::Rem<{integer}>` is not satisfied
 --> test.rs:2:14
  |
2 | let result = -0.25 % 2;}
  |              ^^^^^^^^^ the trait `std::ops::Rem<{integer}>` is not implemented for `{float}`
  |
  = note: no implementation for `{float} % {integer}`

error: aborting due to previous error

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
Projects
None yet
Development

No branches or pull requests

6 participants