Skip to content

Commit 022d94a

Browse files
committed
Support using #[unstable_feature_bound] on trait
1 parent 5771665 commit 022d94a

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,7 +2294,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
22942294
match target {
22952295
// FIXME(staged_api): There's no reason we can't support more targets here. We're just
22962296
// being conservative to begin with.
2297-
Target::Fn | Target::Impl { .. } => {}
2297+
Target::Fn | Target::Impl { .. } | Target::Trait => {}
22982298
Target::ExternCrate
22992299
| Target::Use
23002300
| Target::Static
@@ -2309,7 +2309,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
23092309
| Target::Struct
23102310
| Target::Field
23112311
| Target::Union
2312-
| Target::Trait
23132312
| Target::TraitAlias
23142313
| Target::Expression
23152314
| Target::Statement
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: unstable feature `foo` is used without being enabled.
2+
--> $DIR/unstable_feature_bound_on_trait.rs:29:5
3+
|
4+
LL | Foo::bar();
5+
| ^^^^^^^^^^
6+
|
7+
= help: The feature can be enabled by marking the current item with `#[unstable_feature_bound(foo)]`
8+
note: required by a bound in `Bar::bar`
9+
--> $DIR/unstable_feature_bound_on_trait.rs:17:1
10+
|
11+
LL | #[unstable_feature_bound(foo)]
12+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Bar::bar`
13+
...
14+
LL | fn bar() {}
15+
| --- required by a bound in this associated function
16+
17+
error: aborting due to 1 previous error
18+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//@ revisions: pass fail
2+
//@[pass] check-pass
3+
4+
#![allow(internal_features)]
5+
#![feature(staged_api)]
6+
#![stable(feature = "a", since = "1.1.1" )]
7+
8+
/// Test the behaviour of marking a trait with #[unstable_feature_bound].
9+
/// In this testcase, even though the trait method `bar` and the `struct Foo` are
10+
/// both stable, #[unstable_feature_bound] is still needed at the call site of Foo::bar().
11+
12+
#[stable(feature = "a", since = "1.1.1" )]
13+
struct Foo;
14+
15+
#[unstable(feature = "foo", issue = "none" )]
16+
#[unstable_feature_bound(foo)]
17+
trait Bar {
18+
#[stable(feature = "a", since = "1.1.1" )]
19+
fn bar() {}
20+
}
21+
22+
#[unstable_feature_bound(foo)]
23+
impl Bar for Foo {
24+
}
25+
26+
#[cfg_attr(pass, unstable_feature_bound(foo))]
27+
fn moo() {
28+
Foo::bar();
29+
//[fail]~^ ERROR: unstable feature `foo` is used without being enabled.
30+
}
31+
32+
33+
fn main() {}

0 commit comments

Comments
 (0)