-
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.
Suggest associated const on capitalization error
- Loading branch information
1 parent
bdbe392
commit 20052c8
Showing
5 changed files
with
178 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
struct MyS; | ||
|
||
impl MyS { | ||
const FOO: i32 = 1; | ||
fn foo() -> MyS { | ||
MyS | ||
} | ||
} | ||
|
||
fn main() { | ||
let x: i32 = MyS::foo; | ||
//~^ ERROR mismatched types | ||
//~| HELP try referring to the | ||
|
||
let z: i32 = i32::max; | ||
//~^ ERROR mismatched types | ||
//~| HELP try referring to the | ||
|
||
// This example is still broken though... This is a hard suggestion to make, | ||
// because we don't have access to the associated const probing code to make | ||
// this suggestion where it's emitted, i.e. in trait selection. | ||
let y: i32 = i32::max - 42; | ||
//~^ ERROR cannot subtract | ||
//~| HELP use parentheses | ||
} |
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,47 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/assoc-ct-for-assoc-method.rs:11:18 | ||
| | ||
LL | let x: i32 = MyS::foo; | ||
| --- ^^^^^^^^ expected `i32`, found fn item | ||
| | | ||
| expected due to this | ||
| | ||
= note: expected type `i32` | ||
found fn item `fn() -> MyS {MyS::foo}` | ||
help: try referring to the associated const `FOO` instead | ||
| | ||
LL | let x: i32 = MyS::FOO; | ||
| ~~~ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/assoc-ct-for-assoc-method.rs:15:18 | ||
| | ||
LL | let z: i32 = i32::max; | ||
| --- ^^^^^^^^ expected `i32`, found fn item | ||
| | | ||
| expected due to this | ||
| | ||
= note: expected type `i32` | ||
found fn item `fn(i32, i32) -> i32 {<i32 as Ord>::max}` | ||
help: try referring to the associated const `MAX` instead | ||
| | ||
LL | let z: i32 = i32::MAX; | ||
| ~~~ | ||
|
||
error[E0369]: cannot subtract `{integer}` from `fn(i32, i32) -> i32 {<i32 as Ord>::max}` | ||
--> $DIR/assoc-ct-for-assoc-method.rs:22:27 | ||
| | ||
LL | let y: i32 = i32::max - 42; | ||
| -------- ^ -- {integer} | ||
| | | ||
| fn(i32, i32) -> i32 {<i32 as Ord>::max} | ||
| | ||
help: use parentheses to call this associated function | ||
| | ||
LL | let y: i32 = i32::max(/* i32 */, /* i32 */) - 42; | ||
| ++++++++++++++++++++++ | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
Some errors have detailed explanations: E0308, E0369. | ||
For more information about an error, try `rustc --explain E0308`. |