Closed
Description
This wrong code:
fn foo<T>(x: T) {
let _ = x.overflowing_add(1);
}
fn main() {
foo(1);
}
Gives (rustc 1.44.0-nightly (3712e11 2020-04-12)):
error[E0599]: no method named `overflowing_add` found for type parameter `T` in the current scope
--> C:\lavoro\bugs\bug.rs:2:15
|
2 | let _ = x.overflowing_add(1);
| ^^^^^^^^^^^^^^^ method not found in `T`
|
= help: items from traits can only be used if the type parameter is bounded by the trait
help: the following trait defines an item `overflowing_add`, perhaps you need to restrict type parameter `T` with it:
|
1 | fn foo<T: compiler_builtins::int::Int>(x: T) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I think it's better to omit the second part of the error message, with the compiler_builtins::int::Int ghost trait.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Suggestions generated by the compiler applied by `cargo fix`Category: This is a bug.Diagnostics: A structured suggestion resulting in incorrect code.Diagnostics: An error or lint that needs small tweaks.Relevant to the compiler team, which will review and decide on the PR/issue.