Skip to content

Spurious compiler_builtins::int in error message #71090

Closed
@leonardo-m

Description

@leonardo-m

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

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.D-papercutDiagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions