Skip to content

rustc recommends specialization for type parameters inside an extern block #45092

Closed

Description

@MaikKlein
extern {
    fn sqrt<T>(f: T) -> T;
}

fn main(){}

playground

help: consider using specialization instead of type parameters

Activity

  1. MaikKlein commented on Oct 7, 2017

    @MaikKlein
    ContributorAuthor

    I just realized that rustc doesn't refer to the feature specialization but to 'manual' specialization.

    rustc --explain E0044


    You can't use type parameters on foreign items. Example of erroneous code:

    extern { fn some_func<T>(x: T); }
    

    To fix this, replace the type parameter with the specializations that you
    need:

    extern { fn some_func_i32(x: i32); }
    extern { fn some_func_i64(x: i64); } 
    
  2. added
    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
    on Oct 7, 2017
  3. added
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    on Oct 10, 2017
  4. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    and removed
    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
    on Jan 8, 2019
  5. added
    A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`
    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
    P-lowLow priority
    and removed on May 24, 2019
  6. oli-obk commented on May 24, 2019

    @oli-obk
    Contributor

    Diagnostics triage: just needs changing the wording to something that gives a clearer message.

  7. iluuu1994 commented on Jul 25, 2019

    @iluuu1994
    Contributor

    E0044 has been reworded in #48138.

    error[E0044]: foreign items may not have type parameters
     --> src/main.rs:2:5
      |
    2 |     fn sqrt<T>(f: T) -> T;
      |     ^^^^^^^^^^^^^^^^^^^^^^ can't have type parameters
      |
      = help: use specialization instead of type parameters by replacing them with concrete types like `u32`
    

    This can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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-enhancementCategory: An issue proposing an enhancement or a PR with one.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.P-lowLow priorityT-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