Skip to content

Commit fd34b00

Browse files
committed
Add tests
1 parent fb5308d commit fd34b00

26 files changed

+473
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#![allow(internal_features)]
2+
#![feature(staged_api)]
3+
#![stable(feature = "a", since = "1.1.1" )]
4+
5+
#[stable(feature = "a", since = "1.1.1" )]
6+
pub trait Foo {
7+
#[stable(feature = "a", since = "1.1.1" )]
8+
fn foo();
9+
}
10+
#[stable(feature = "a", since = "1.1.1" )]
11+
pub struct Bar;
12+
#[stable(feature = "a", since = "1.1.1" )]
13+
pub struct Moo;
14+
15+
#[unstable_feature_bound(feat_bar)]
16+
#[unstable(feature = "feat_bar", issue = "none" )]
17+
impl Foo for Bar {
18+
fn foo() {}
19+
}
20+
21+
#[unstable_feature_bound(feat_moo)]
22+
#[unstable(feature = "feat_moo", issue = "none" )]
23+
impl Foo for Moo {
24+
fn foo() {}
25+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![allow(internal_features)]
2+
#![feature(staged_api)]
3+
#![stable(feature = "a", since = "1.1.1" )]
4+
5+
/// Aux crate for unstable impl codegen test.
6+
7+
#[stable(feature = "a", since = "1.1.1" )]
8+
pub trait Trait {
9+
#[stable(feature = "a", since = "1.1.1" )]
10+
fn method(&self);
11+
}
12+
13+
#[unstable_feature_bound(foo)]
14+
#[unstable(feature = "foo", issue = "none" )]
15+
impl<T> Trait for T {
16+
fn method(&self) {
17+
println!("hi");
18+
}
19+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ aux-build:unstable_impl_codegen_aux1.rs
2+
#![feature(foo)]
3+
4+
extern crate unstable_impl_codegen_aux1 as aux;
5+
use aux::Trait;
6+
7+
/// Upstream crate for unstable impl codegen test
8+
/// that depends on aux crate in
9+
/// unstable_impl_codegen_aux1.rs
10+
11+
pub fn foo<T>(a:T) {
12+
a.method();
13+
}
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+
#[stable(feature = "a", since = "1.1.1" )]
7+
pub trait Trait {}
8+
9+
#[unstable_feature_bound(foo)]
10+
#[unstable(feature = "foo", issue = "none" )]
11+
impl <T> Trait for T {}
12+
13+
fn main() {
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ aux-build:unstable_feature.rs
2+
extern crate unstable_feature;
3+
use unstable_feature::{Foo, Bar, Moo};
4+
5+
// FIXME: both `feat_bar`` and `feat_moo` are needed to pass this test,
6+
// but the diagnostic only will point out `feat_bar`.
7+
8+
fn main() {
9+
Bar::foo();
10+
//~^ ERROR: type annotations needed: cannot satisfy `unstable feature: `feat_bar``
11+
Moo::foo();
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0284]: type annotations needed: cannot satisfy `unstable feature: `feat_bar``
2+
--> $DIR/unstable-feature-bound-two-error.rs:9:5
3+
|
4+
LL | Bar::foo();
5+
| ^^^ cannot satisfy `unstable feature: `feat_bar``
6+
|
7+
= note: required for `Bar` to implement `Foo`
8+
9+
error: aborting due to 1 previous error
10+
11+
For more information about this error, try `rustc --explain E0284`.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0284]: type annotations needed: cannot satisfy `unstable feature: `feat_moo``
2+
--> $DIR/unstable-feature-cross-crate-exact-symbol.rs:16:5
3+
|
4+
LL | Moo::foo();
5+
| ^^^ cannot satisfy `unstable feature: `feat_moo``
6+
|
7+
= note: required for `Moo` to implement `Foo`
8+
9+
error: aborting due to 1 previous error
10+
11+
For more information about this error, try `rustc --explain E0284`.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ aux-build:unstable_feature.rs
2+
//@ revisions: pass fail
3+
//@[pass] check-pass
4+
5+
#![cfg_attr(pass, feature(feat_bar, feat_moo))]
6+
#![cfg_attr(fail, feature(feat_bar))]
7+
8+
extern crate unstable_feature;
9+
use unstable_feature::{Foo, Bar, Moo};
10+
11+
/// To use impls gated by both `feat_foo` and `feat_moo`,
12+
/// both features must be enabled.
13+
14+
fn main() {
15+
Bar::foo();
16+
Moo::foo();
17+
//[fail]~^ ERROR: type annotations needed: cannot satisfy `unstable feature: `feat_moo``
18+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@ aux-build:unstable_feature.rs
2+
//@ check-pass
3+
#![feature(feat_bar, feat_moo)]
4+
extern crate unstable_feature;
5+
use unstable_feature::{Foo, Bar, Moo};
6+
7+
/// Bar::foo() should still be usable even if we enable multiple feature.
8+
9+
fn main() {
10+
Bar::foo();
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0284]: type annotations needed: cannot satisfy `unstable feature: `feat_bar``
2+
--> $DIR/unstable-feature-cross-crate-require-bound.rs:12:5
3+
|
4+
LL | Bar::foo();
5+
| ^^^ cannot satisfy `unstable feature: `feat_bar``
6+
|
7+
= note: required for `Bar` to implement `Foo`
8+
9+
error: aborting due to 1 previous error
10+
11+
For more information about this error, try `rustc --explain E0284`.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//@ aux-build:unstable_feature.rs
2+
//@ revisions: pass fail
3+
//@[pass] check-pass
4+
5+
#![cfg_attr(pass, feature(feat_bar))]
6+
extern crate unstable_feature;
7+
use unstable_feature::{Foo, Bar};
8+
9+
/// #[feature(..)] is required to use unstable impl.
10+
11+
fn main() {
12+
Bar::foo();
13+
//[fail]~^ ERROR: cannot satisfy `unstable feature: `feat_bar``
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0284]: type annotations needed: cannot satisfy `unstable feature: `feat_moo``
2+
--> $DIR/unstable-feature-exact-symbol.rs:37:5
3+
|
4+
LL | Bar::moo();
5+
| ^^^ cannot satisfy `unstable feature: `feat_moo``
6+
|
7+
note: required for `Bar` to implement `Moo`
8+
--> $DIR/unstable-feature-exact-symbol.rs:29:6
9+
|
10+
LL | #[unstable_feature_bound(feat_moo)]
11+
| ----------------------------------- unsatisfied trait bound introduced here
12+
LL | impl Moo for Bar {
13+
| ^^^ ^^^
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0284`.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//@ revisions: pass fail
2+
//@[pass] check-pass
3+
4+
#![allow(internal_features)]
5+
#![feature(staged_api)]
6+
#![allow(dead_code)]
7+
#![unstable(feature = "feat_foo", issue = "none" )]
8+
9+
/// In staged-api crate, impl that is marked as unstable with
10+
/// feature name `feat_moo` should not be accessible
11+
/// if only `feat_foo` is enabled.
12+
13+
pub trait Foo {
14+
fn foo();
15+
}
16+
17+
pub trait Moo {
18+
fn moo();
19+
}
20+
21+
pub struct Bar;
22+
23+
#[unstable_feature_bound(feat_foo)]
24+
impl Foo for Bar {
25+
fn foo() {}
26+
}
27+
28+
#[unstable_feature_bound(feat_moo)]
29+
impl Moo for Bar {
30+
fn moo() {}
31+
}
32+
33+
#[cfg_attr(fail, unstable_feature_bound(feat_foo))]
34+
#[cfg_attr(pass, unstable_feature_bound(feat_foo, feat_moo))]
35+
fn bar() {
36+
Bar::foo();
37+
Bar::moo();
38+
//[fail]~^ ERROR cannot satisfy `unstable feature: `feat_moo``
39+
}
40+
41+
fn main() {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0284]: type annotations needed: cannot satisfy `unstable feature: `feat_foo``
2+
--> $DIR/unstable-impl-assoc-type.rs:23:16
3+
|
4+
LL | type Assoc = Self;
5+
| ^^^^ cannot satisfy `unstable feature: `feat_foo``
6+
|
7+
note: required for `Foo` to implement `Bar`
8+
--> $DIR/unstable-impl-assoc-type.rs:19:6
9+
|
10+
LL | #[unstable_feature_bound(feat_foo)]
11+
| ----------------------------------- unsatisfied trait bound introduced here
12+
LL | impl Bar for Foo {}
13+
| ^^^ ^^^
14+
note: required by a bound in `Trait::Assoc`
15+
--> $DIR/unstable-impl-assoc-type.rs:13:17
16+
|
17+
LL | type Assoc: Bar;
18+
| ^^^ required by this bound in `Trait::Assoc`
19+
20+
error: aborting due to 1 previous error
21+
22+
For more information about this error, try `rustc --explain E0284`.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//@ revisions: pass fail
2+
//@[pass] check-pass
3+
4+
#![allow(internal_features)]
5+
#![feature(staged_api)]
6+
#![unstable(feature = "feat_foo", issue = "none" )]
7+
8+
/// Test that you can't leak unstable impls through item bounds on associated types.
9+
10+
trait Bar {}
11+
12+
trait Trait {
13+
type Assoc: Bar;
14+
}
15+
16+
struct Foo;
17+
18+
#[unstable_feature_bound(feat_foo)]
19+
impl Bar for Foo {}
20+
21+
#[cfg_attr(pass, unstable_feature_bound(feat_foo))]
22+
impl Trait for Foo {
23+
type Assoc = Self;
24+
//[fail]~^ ERROR: cannot satisfy `unstable feature: `feat_foo``
25+
}
26+
27+
fn main(){}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0284]: type annotations needed: cannot satisfy `unstable feature: `feat_foo``
2+
--> $DIR/unstable-impl-cannot-use-feature.rs:26:5
3+
|
4+
LL | Bar::foo();
5+
| ^^^ cannot satisfy `unstable feature: `feat_foo``
6+
|
7+
note: required for `Bar` to implement `Foo`
8+
--> $DIR/unstable-impl-cannot-use-feature.rs:20:6
9+
|
10+
LL | #[unstable_feature_bound(feat_foo)]
11+
| ----------------------------------- unsatisfied trait bound introduced here
12+
LL | impl Foo for Bar {
13+
| ^^^ ^^^
14+
15+
error: aborting due to 1 previous error
16+
17+
For more information about this error, try `rustc --explain E0284`.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//@ revisions: pass fail
2+
//@[pass] check-pass
3+
4+
#![allow(internal_features)]
5+
#![feature(staged_api)]
6+
#![allow(dead_code)]
7+
#![unstable(feature = "feat_foo", issue = "none" )]
8+
9+
#![cfg_attr(fail, feature(feat_foo))]
10+
11+
/// In staged-api crate, using an unstable impl requires
12+
/// #[unstable_feature_bound(..)], not #[feature(..)].
13+
14+
pub trait Foo {
15+
fn foo();
16+
}
17+
pub struct Bar;
18+
19+
#[unstable_feature_bound(feat_foo)]
20+
impl Foo for Bar {
21+
fn foo() {}
22+
}
23+
24+
#[cfg_attr(pass, unstable_feature_bound(feat_foo))]
25+
fn bar() {
26+
Bar::foo();
27+
//[fail]~^ ERROR: cannot satisfy `unstable feature: `feat_foo``
28+
}
29+
30+
fn main() {}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//@ check-pass
2+
3+
#![allow(internal_features)]
4+
#![feature(staged_api)]
5+
#![allow(dead_code)]
6+
#![unstable(feature = "feat_foo", issue = "none" )]
7+
8+
/// In staged-api crate, if feat_foo is only needed to use an impl,
9+
/// having both `feat_foo` and `feat_bar` will still make it pass.
10+
11+
pub trait Foo {
12+
fn foo();
13+
}
14+
pub struct Bar;
15+
16+
// Annotate the impl as unstable.
17+
#[unstable_feature_bound(feat_foo)]
18+
impl Foo for Bar {
19+
fn foo() {}
20+
}
21+
22+
#[unstable_feature_bound(feat_foo, feat_bar)]
23+
fn bar() {
24+
Bar::foo();
25+
}
26+
27+
fn main() {}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#![allow(internal_features)]
2+
#![feature(staged_api)]
3+
#![allow(dead_code)]
4+
#![unstable(feature = "feat_bar", issue = "none" )]
5+
6+
7+
/// Test the behaviour of multiple unstable_feature_bound attribute.
8+
9+
trait Foo {
10+
fn foo();
11+
}
12+
struct Bar;
13+
14+
#[unstable_feature_bound(feat_bar, feat_koo)]
15+
#[unstable_feature_bound(feat_foo, feat_moo)]
16+
impl Foo for Bar {
17+
fn foo(){}
18+
}
19+
20+
#[unstable_feature_bound(feat_bar, feat_koo)]
21+
#[unstable_feature_bound(feat_foo, feat_moo)]
22+
fn moo() {
23+
Bar::foo();
24+
}
25+
26+
#[unstable_feature_bound(feat_bar, feat_koo, feat_foo, feat_moo)]
27+
fn koo() {
28+
Bar::foo();
29+
}
30+
31+
#[unstable_feature_bound(feat_koo, feat_foo, feat_moo)]
32+
fn boo() {
33+
Bar::foo();
34+
//~^ ERROR: type annotations needed: cannot satisfy `unstable feature: `feat_bar``
35+
}
36+
37+
fn main() {}

0 commit comments

Comments
 (0)