Skip to content

Commit 0bc5160

Browse files
committed
Setup feature gate and attribute
1 parent 6de3a73 commit 0bc5160

File tree

7 files changed

+49
-1
lines changed

7 files changed

+49
-1
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ pub enum AttributeKind {
162162
// tidy-alphabetical-start
163163
AllowConstFnUnstable(ThinVec<Symbol>),
164164
AllowInternalUnstable(ThinVec<(Symbol, Span)>),
165+
AllowUnstableFeature(ThinVec<(Symbol, Span)>),
165166
BodyStability {
166167
stability: DefaultBodyStability,
167168
/// Span of the `#[rustc_default_body_unstable(...)]` attribute

compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ impl CombineAttributeParser for AllowInternalUnstableParser {
2222
}
2323
}
2424

25+
pub(crate) struct AllowUnstableFeatureParser;
26+
impl CombineAttributeParser for AllowUnstableFeatureParser {
27+
const PATH: &'static [rustc_span::Symbol] = &[sym::unstable_feature_bound];
28+
type Item = (Symbol, Span);
29+
const CONVERT: ConvertFn<Self::Item> = AttributeKind::AllowUnstableFeature;
30+
31+
fn extend<'a>(
32+
cx: &'a AcceptContext<'a>,
33+
args: &'a ArgParser<'a>,
34+
) -> impl IntoIterator<Item = Self::Item> + 'a {
35+
parse_unstable(cx, args, Self::PATH[0]).into_iter().zip(iter::repeat(cx.attr_span))
36+
}
37+
}
38+
2539
pub(crate) struct AllowConstFnUnstableParser;
2640
impl CombineAttributeParser for AllowConstFnUnstableParser {
2741
const PATH: &'static [Symbol] = &[sym::rustc_allow_const_fn_unstable];

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ use rustc_hir::{AttrArgs, AttrItem, AttrPath, Attribute, HashIgnoredAttrId};
1111
use rustc_session::Session;
1212
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym};
1313

14-
use crate::attributes::allow_unstable::{AllowConstFnUnstableParser, AllowInternalUnstableParser};
14+
use crate::attributes::allow_unstable::{
15+
AllowConstFnUnstableParser, AllowInternalUnstableParser, AllowUnstableFeatureParser,
16+
};
1517
use crate::attributes::confusables::ConfusablesParser;
1618
use crate::attributes::deprecation::DeprecationParser;
1719
use crate::attributes::repr::ReprParser;
@@ -75,6 +77,7 @@ attribute_groups!(
7577
// tidy-alphabetical-start
7678
Combine<AllowConstFnUnstableParser>,
7779
Combine<AllowInternalUnstableParser>,
80+
Combine<AllowUnstableFeatureParser>,
7881
Combine<ReprParser>,
7982
// tidy-alphabetical-end
8083

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,11 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
655655
DuplicatesOk, EncodeCrossCrate::Yes,
656656
"allow_internal_unstable side-steps feature gating and stability checks",
657657
),
658+
gated!(
659+
unstable_feature_bound, Normal, template!(Word, List: "feat1, feat2, ..."),
660+
DuplicatesOk, EncodeCrossCrate::No, impl_stability,
661+
"used internally to mark impl as unstable",
662+
),
658663
gated!(
659664
allow_internal_unsafe, Normal, template!(Word), WarnFollowing,
660665
EncodeCrossCrate::No, "allow_internal_unsafe side-steps the unsafe_code lint",

compiler/rustc_feature/src/unstable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ declare_features! (
213213
(internal, custom_mir, "1.65.0", None),
214214
/// Outputs useful `assert!` messages
215215
(unstable, generic_assert, "1.63.0", None),
216+
/// Allow declaring an impl as unstable.
217+
(internal, impl_stability, "CURRENT_RUSTC_VERSION", None),
216218
/// Allows using the #[rustc_intrinsic] attribute.
217219
(internal, intrinsics, "1.0.0", None),
218220
/// Allows using `#[lang = ".."]` attribute for linking items to special compiler logic.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// Test for impl_stability gate.
2+
3+
trait Foo{}
4+
struct Bar;
5+
6+
#[unstable_feature_bound(feat_foo)]
7+
//~^ ERROR: used internally to mark impl as unstable
8+
impl Foo for Bar{}
9+
10+
fn main() {
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0658]: used internally to mark impl as unstable
2+
--> $DIR/feature-gate-impl-stability.rs:6:1
3+
|
4+
LL | #[unstable_feature_bound(feat_foo)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: add `#![feature(impl_stability)]` to the crate attributes to enable
8+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
9+
10+
error: aborting due to 1 previous error
11+
12+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)