about summary refs log tree commit diff
path: root/compiler/rustc_codegen_gcc/example/example.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-07-17 01:57:55 +0000
committerbors <bors@rust-lang.org>2025-07-17 01:57:55 +0000
commit014bd8290f084c714995205a9116e6c035419ae6 (patch)
tree70a98d65e3a93b13c6c896c708c4b66c373733c1 /compiler/rustc_codegen_gcc/example/example.rs
parentfd2eb391d032181459773f3498c17b198513e0d0 (diff)
parente331de149f4fe5ddafe7f4bad13acb1499a6108e (diff)
downloadrust-014bd8290f084c714995205a9116e6c035419ae6.tar.gz
rust-014bd8290f084c714995205a9116e6c035419ae6.zip
Auto merge of #140399 - tiif:unstable_impl, r=lcnr,BoxyUwU
Implement unstable trait impl

This PR allows marking impls of stable trait with stable type as unstable.

## Approach

In std/core, an impl can be marked as unstable by annotating it with ``#[unstable_feature_bound(feat_name)]``. This will add a ``ClauseKind::Unstable_Feature(feat_name)`` to the list of predicates in ``predicates_of`` .

When an unstable impl's function is called, we will first iterate through all the goals in ``param_env`` to check if there is any ``ClauseKind::UnstableFeature(feat_name)`` in ``param_env``.

The existence of ``ClauseKind::Unstable_Feature(feat_name)`` in ``param_env`` means an``#[unstable_feature_bound(feat_name)]`` is present at the call site of the function, so we allow the check to succeed in this case.

If ``ClauseKind::UnstableFeature(feat_name)`` does not exist in ``param_env``, we will still allow the check to succeed for either of the cases below:
1. The feature is enabled through ``#[feature(feat_name)]`` outside of std / core.
2. We are in codegen because we may be monomorphizing a body from an upstream crate which had an unstable feature enabled that the downstream crate do not.

For the rest of the case, it will fail with ambiguity.

## Limitation

In this PR, we do not support:
1. using items that need ``#[unstable_feature_bound]`` within stable APIs
2. annotate main function with ``#[unstable_feature_bound]``
3. annotate ``#[unstable_feature_bound]`` on items other than free function and impl

## Acknowledgement
The design and mentoring are done by `@BoxyUwU`
Diffstat (limited to 'compiler/rustc_codegen_gcc/example/example.rs')
0 files changed, 0 insertions, 0 deletions