-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #47171 - estebank:numeric-literal-suggestion, r=nikomat…
…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.
- Loading branch information
Showing
9 changed files
with
199 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,12 @@ | ||
error[E0599]: no method named `f` found for type `{integer}` in the current scope | ||
error[E0689]: can't call method `f` on ambiguous numeric type `{integer}` | ||
--> $DIR/issue_41652.rs:19:11 | ||
| | ||
19 | 3.f() | ||
| ^ | ||
help: you must specify a concrete type for this numeric value, like `i32` | ||
| | ||
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter | ||
= help: try with `{integer}::f` | ||
note: candidate #1 is defined in the trait `issue_41652_b::Tr` | ||
--> $DIR/auxiliary/issue_41652_b.rs:14:5 | ||
| | ||
14 | / fn f() | ||
15 | | where Self: Sized; | ||
| |__________________________^ | ||
= help: to disambiguate the method call, write `issue_41652_b::Tr::f(3)` instead | ||
19 | 3_i32.f() | ||
| ^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/test/ui/suggestions/method-on-ambiguous-numeric-type.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
fn main() { | ||
let x = 2.0.powi(2); | ||
//~^ ERROR can't call method `powi` on ambiguous numeric type `{float}` | ||
let y = 2.0; | ||
let x = y.powi(2); | ||
//~^ ERROR can't call method `powi` on ambiguous numeric type `{float}` | ||
println!("{:?}", x); | ||
} |
22 changes: 22 additions & 0 deletions
22
src/test/ui/suggestions/method-on-ambiguous-numeric-type.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
error[E0689]: 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); | ||
| ^^^^^^^ | ||
|
||
error[E0689]: can't call method `powi` on ambiguous numeric type `{float}` | ||
--> $DIR/method-on-ambiguous-numeric-type.rs:15:15 | ||
| | ||
15 | let x = y.powi(2); | ||
| ^^^^ | ||
help: you must specify a type for this binding, like `f32` | ||
| | ||
14 | let y: f32 = 2.0; | ||
| ^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|