rust/compiler/rustc_attr_data_structures/src
bors 014bd8290f 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`
2025-07-17 01:57:55 +00:00
..
attributes.rs Auto merge of #140399 - tiif:unstable_impl, r=lcnr,BoxyUwU 2025-07-17 01:57:55 +00:00
encode_cross_crate.rs Auto merge of #140399 - tiif:unstable_impl, r=lcnr,BoxyUwU 2025-07-17 01:57:55 +00:00
lib.rs Port #[rustc_layout_scalar_valid_range_start/end] to the new attribute parsing infrastructure 2025-06-27 09:08:21 +02:00
lints.rs Rewrite empty attribute lint 2025-07-06 09:51:35 +02:00
stability.rs Tracking the old name of renamed unstable library attribute 2025-06-12 19:24:11 +08:00
version.rs Make #[cfg(version)] respect RUSTC_OVERRIDE_VERSION_STRING 2025-05-24 23:54:17 +02:00