Skip to content

Commit 21eb7d3

Browse files
committed
Add first batch of tests
1 parent 4df3db4 commit 21eb7d3

11 files changed

+203
-14
lines changed

tests/ui/internal/auxiliary/unstable_feature.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,21 @@ pub trait Foo {
1111
}
1212
#[stable(feature = "a", since = "1.1.1" )]
1313
pub struct Bar;
14+
#[stable(feature = "a", since = "1.1.1" )]
15+
pub struct Moo;
1416

1517
// Annotate the impl as unstable.
16-
#[unstable_feature_bound(feat_foo)]
17-
#[unstable(feature = "feat_foo", issue = "none" )]
18+
#[unstable_feature_bound(feat_bar)]
19+
#[unstable(feature = "feat_bar", issue = "none" )]
1820
impl Foo for Bar {
1921
fn foo() {}
2022
}
2123

22-
// Use the unstable impl inside std/core.
23-
#[unstable_feature_bound(feat_foo)]
24-
fn bar() {
25-
Bar::foo();
24+
25+
#[unstable_feature_bound(feat_moo)]
26+
#[unstable(feature = "feat_moo", issue = "none" )]
27+
impl Foo for Moo {
28+
fn foo() {}
2629
}
2730

2831
fn main() {
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: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
//@ aux-build:unstable_feature.rs
2-
2+
#![feature(feat_bar)]
33
extern crate unstable_feature;
4-
use unstable_feature::{Foo, Bar};
4+
use unstable_feature::{Foo, Bar, Moo};
5+
6+
/// Since only `feat_bar` is enabled, Bar::foo() should be usable and
7+
/// Moo::foo() should not be usable.
58
69
fn main() {
7-
Bar::foo(); //~ ERROR: type annotations needed: cannot satisfy `unstable feature: `feat_foo``
10+
Bar::foo();
11+
Moo::foo();
12+
//~^ ERROR: type annotations needed: cannot satisfy `unstable feature: `feat_moo``
813
}

tests/ui/internal/unstable-feature-bound.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error[E0284]: type annotations needed: cannot satisfy `unstable feature: `feat_foo``
2-
--> $DIR/unstable-feature-bound.rs:7:5
1+
error[E0284]: type annotations needed: cannot satisfy `unstable feature: `feat_moo``
2+
--> $DIR/unstable-feature-bound.rs:11:5
33
|
4-
LL | Bar::foo();
5-
| ^^^ cannot satisfy `unstable feature: `feat_foo``
4+
LL | Moo::foo();
5+
| ^^^ cannot satisfy `unstable feature: `feat_moo``
66
|
7-
= note: required for `Bar` to implement `Foo`
7+
= note: required for `Moo` to implement `Foo`
88

99
error: aborting due to 1 previous error
1010

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#![allow(internal_features)]
2+
#![feature(staged_api)]
3+
#![feature(impl_stability)]
4+
#![unstable(feature = "feat_foo", issue = "none" )]
5+
6+
/// FIXME: add a description here.
7+
8+
trait Bar {}
9+
10+
trait Trait {
11+
type Assoc: Bar;
12+
}
13+
14+
trait Moo {
15+
type Assoc: Bar;
16+
}
17+
18+
struct Foo;
19+
20+
#[unstable_feature_bound(feat_foo)]
21+
impl Bar for Foo {}
22+
23+
impl Trait for Foo {
24+
type Assoc = Self;
25+
//~^ ERROR: cannot satisfy `unstable feature: `feat_foo``
26+
}
27+
28+
// If the impl is annotated with #[unstable_feature_bound(..)],
29+
// then it should pass.
30+
#[unstable_feature_bound(feat_foo)]
31+
impl Moo for Foo {
32+
type Assoc = Self;
33+
}
34+
35+
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:24: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:21: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:11: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+
#![allow(internal_features)]
2+
#![feature(staged_api)]
3+
#![feature(impl_stability)]
4+
#![allow(dead_code)]
5+
#![feature(feat_foo)]
6+
#![unstable(feature = "feat_foo", issue = "none" )]
7+
8+
/// In staged-api crate, impl that is marked with #[unstable_feature_bound(..)]
9+
/// cannot be enabled with #[feature(..)]
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+
fn bar() {
23+
Bar::foo();
24+
//~^ 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:23: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:18: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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#![allow(internal_features)]
2+
#![feature(staged_api)]
3+
#![feature(impl_stability)]
4+
#![allow(dead_code)]
5+
#![unstable(feature = "feat_foo", issue = "none" )]
6+
7+
// This is testing:
8+
// 1. Using an unstable impl requires #[unstable_feature_bound(..)]
9+
// 2. If only feat_foo is needed to use an impl,
10+
// having both `feat_foo` and `feat_bar` will still make it pass.
11+
12+
pub trait Foo {
13+
fn foo();
14+
}
15+
pub struct Bar;
16+
17+
// Annotate the impl as unstable.
18+
#[unstable_feature_bound(feat_foo)]
19+
impl Foo for Bar {
20+
fn foo() {}
21+
}
22+
23+
fn bar() {
24+
Bar::foo();
25+
//~^ ERROR: cannot satisfy `unstable feature: `feat_foo``
26+
}
27+
28+
// With #[unstable_feature_bound(..)], this should pass.
29+
#[unstable_feature_bound(feat_foo)]
30+
fn bar2() {
31+
Bar::foo();
32+
}
33+
34+
// FIXME: maybe we should warn that feat_bar does not exist?
35+
#[unstable_feature_bound(feat_foo, feat_bar)]
36+
fn bar3() {
37+
Bar::foo();
38+
}
39+
40+
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-require-bound.rs:23: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-require-bound.rs:18: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`.

0 commit comments

Comments
 (0)