Skip to content

Commit dd067a6

Browse files
committed
Lint against having both #[unstable_feature_bound] and #[stable] on the same item
1 parent ab29256 commit dd067a6

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed

compiler/rustc_attr_parsing/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ attr_parsing_unrecognized_repr_hint =
136136
attr_parsing_unstable_cfg_target_compact =
137137
compact `cfg(target(..))` is experimental and subject to change
138138
139+
attr_parsing_unstable_feature_bound_incompatible_stability = Item annotated with `#[unstable_feature_bound]` should not be stable
140+
.help = If this item is meant to be stable, do not use any functions annotated with `#[unstable_feature_bound]`. Otherwise, mark this item as unstable with `#[unstable]`
141+
139142
attr_parsing_unsupported_literal_cfg_boolean =
140143
literal in `cfg` predicate value must be a boolean
141144
attr_parsing_unsupported_literal_cfg_string =

compiler/rustc_attr_parsing/src/attributes/stability.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ impl<S: Stage> AttributeParser<S> for StabilityParser {
9898
}
9999
}
100100

101+
if let Some((Stability { level: StabilityLevel::Stable { .. }, .. }, _)) = self.stability {
102+
for other_attr in cx.all_attrs {
103+
if other_attr.word_is(sym::unstable_feature_bound) {
104+
cx.emit_err(session_diagnostics::UnstableFeatureBoundIncompatibleStability {
105+
span: cx.target_span,
106+
});
107+
}
108+
}
109+
}
110+
101111
let (stability, span) = self.stability?;
102112

103113
Some(AttributeKind::Stability { stability, span })

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,14 @@ pub(crate) struct UnrecognizedReprHint {
503503
pub span: Span,
504504
}
505505

506+
#[derive(Diagnostic)]
507+
#[diag(attr_parsing_unstable_feature_bound_incompatible_stability)]
508+
#[help]
509+
pub(crate) struct UnstableFeatureBoundIncompatibleStability {
510+
#[primary_span]
511+
pub span: Span,
512+
}
513+
506514
#[derive(Diagnostic)]
507515
#[diag(attr_parsing_naked_functions_incompatible_attribute, code = E0736)]
508516
pub(crate) struct NakedFunctionIncompatibleAttribute {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![allow(internal_features)]
2+
#![feature(staged_api)]
3+
#![allow(dead_code)]
4+
#![stable(feature = "a", since = "1.1.1" )]
5+
6+
// Lint against the usage of both #[unstable_feature_bound] and #[stable] on the
7+
// same item.
8+
9+
#[stable(feature = "a", since = "1.1.1")]
10+
#[unstable_feature_bound(feat_bar)]
11+
fn bar() {}
12+
//~^ ERROR Item annotated with `#[unstable_feature_bound]` should not be stable
13+
14+
fn main() {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: Item annotated with `#[unstable_feature_bound]` should not be stable
2+
--> $DIR/unstable_feature_bound_incompatible_stability.rs:11:1
3+
|
4+
LL | fn bar() {}
5+
| ^^^^^^^^^^^
6+
|
7+
= help: If this item is meant to be stable, do not use any functions annotated with `#[unstable_feature_bound]`. Otherwise, mark this item as unstable with `#[unstable]`
8+
9+
error: aborting due to 1 previous error
10+

0 commit comments

Comments
 (0)