Skip to content

Add support for stability attributes on foreign types #158200

@carbotaniuman

Description

@carbotaniuman

When implementing the FnPtr trait in #156176, I tried to implement Code as an extern type, however the stability infrastructure does not allow stability markers on extern types.

extern "C" {
    #[unstable(feature = "fn_static", issue = "148768")]
    type Opaque;
}

Gives the following error:

error: foreign type has missing stability attribute
   --> library/core/src/ops/function.rs:318:5
    |
318 |     pub type Code;
    |     ^^^^^^^^^^^^^

And if I try to put a stability marker on it I get this:

error: `#[unstable]` attribute cannot be used on foreign types
   --> library/core/src/ops/function.rs:318:5
    |
318 |     #[unstable(feature = "fn_static", issue = "148768")]
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: `#[unstable]` can be applied to associated consts, associated types, constants, crates, data types, enum variants, extern crates, foreign statics, functions, impl blocks, macro defs, modules, statics, struct fields, trait aliases, traits, type aliases, type parameters, and use statements

Metadata

Metadata

Assignees

Labels

A-attributesArea: Attributes (`#[…]`, `#![…]`)A-stabilityArea: `#[stable]`, `#[unstable]` etc.C-bugCategory: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.F-staged_api`#![feature(staged_api)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions