-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Provide suggestion when trying to use method on numeric literal #47171
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
96bca24
to
87242f3
Compare
The help message is not good. The number of "as" cast should be minimized in good Rust code. So instead of this:
It's better to suggest something like:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code seems fine; I agree that 2.0_f32
is probably a better suggestion though.
This error can also be triggered by fn main() {
let y = 2.0;
let x = y.powi(2);
println!("{:?}", x);
} Granted, in that case the suggestion |
Both literals and local bindings are now handled correctly. |
19e6a5e
to
4cd6c04
Compare
4cd6c04
to
f7aed3e
Compare
@bors r=nikomatsakis |
📌 Commit f7aed3e has been approved by |
…sakis Provide suggestion when trying to use method on numeric literal New output: ``` error[E0688]: can't call method `powi` on ambiguous numeric type `{float}` --> $DIR/method-on-ambiguous-numeric-type.rs:12:17 | 12 | let x = 2.0.powi(2); | ^^^^ help: you must specify a concrete type for this numeric value, like `f32` | 12 | let x = 2.0_f32.powi(2); | ^^^^^^^ ``` Previous output: ``` error[E0599]: no method named `powi` found for type `{float}` in the current scope --> src/main.rs:12:17 | 12 | let x = 2.0.powi(2); | ^^^^ | = help: items from traits can only be used if the trait is in scope help: the following trait is implemented but not in scope, perhaps add a `use` for it: | 11 | use core::num::Float; | ``` Fix #40985.
💔 Test failed - status-appveyor |
⌛ Testing commit f7aed3e with merge 9c663205a2b984f635c577d17a5729c9e1754843... |
💔 Test failed - status-appveyor |
@bors retry |
…sakis Provide suggestion when trying to use method on numeric literal New output: ``` error[E0688]: can't call method `powi` on ambiguous numeric type `{float}` --> $DIR/method-on-ambiguous-numeric-type.rs:12:17 | 12 | let x = 2.0.powi(2); | ^^^^ help: you must specify a concrete type for this numeric value, like `f32` | 12 | let x = 2.0_f32.powi(2); | ^^^^^^^ ``` Previous output: ``` error[E0599]: no method named `powi` found for type `{float}` in the current scope --> src/main.rs:12:17 | 12 | let x = 2.0.powi(2); | ^^^^ | = help: items from traits can only be used if the trait is in scope help: the following trait is implemented but not in scope, perhaps add a `use` for it: | 11 | use core::num::Float; | ``` Fix #40985.
☀️ Test successful - status-appveyor, status-travis |
New output:
Previous output:
Fix #40985.