diff options
Diffstat (limited to 'tests/ui/stability-attribute')
12 files changed, 193 insertions, 0 deletions
diff --git a/tests/ui/stability-attribute/auxiliary/const-stability-attribute-implies.rs b/tests/ui/stability-attribute/auxiliary/const-stability-attribute-implies.rs new file mode 100644 index 000000000..f78871b5a --- /dev/null +++ b/tests/ui/stability-attribute/auxiliary/const-stability-attribute-implies.rs @@ -0,0 +1,12 @@ +#![crate_type = "lib"] +#![feature(staged_api)] +#![stable(feature = "stability_attribute_implies", since = "1.0.0")] +#![rustc_const_stable(feature = "stability_attribute_implies", since = "1.0.0")] + +#[stable(feature = "stability_attribute_implies", since = "1.0.0")] +#[rustc_const_stable(feature = "const_foo", since = "1.62.0")] +pub const fn foo() {} + +#[stable(feature = "stability_attribute_implies", since = "1.0.0")] +#[rustc_const_unstable(feature = "const_foobar", issue = "1", implied_by = "const_foo")] +pub const fn foobar() {} diff --git a/tests/ui/stability-attribute/auxiliary/similar-unstable-method.rs b/tests/ui/stability-attribute/auxiliary/similar-unstable-method.rs new file mode 100644 index 000000000..8804186ee --- /dev/null +++ b/tests/ui/stability-attribute/auxiliary/similar-unstable-method.rs @@ -0,0 +1,13 @@ +#![feature(staged_api)] +#![stable(feature = "libfoo", since = "1.0.0")] + +#[unstable(feature = "foo", reason = "...", issue = "none")] +pub fn foo() {} + +#[stable(feature = "libfoo", since = "1.0.0")] +pub struct Foo; + +impl Foo { + #[unstable(feature = "foo", reason = "...", issue = "none")] + pub fn foo(&self) {} +} diff --git a/tests/ui/stability-attribute/const-stability-attribute-implies-missing.rs b/tests/ui/stability-attribute/const-stability-attribute-implies-missing.rs new file mode 100644 index 000000000..6d6d793c6 --- /dev/null +++ b/tests/ui/stability-attribute/const-stability-attribute-implies-missing.rs @@ -0,0 +1,16 @@ +#![crate_type = "lib"] +#![feature(staged_api)] +#![stable(feature = "stability_attribute_implies", since = "1.0.0")] +#![rustc_const_stable(feature = "stability_attribute_implies", since = "1.0.0")] + +// Tests that `implied_by = "const_bar"` results in an error being emitted if `const_bar` does not +// exist. + +#[stable(feature = "stability_attribute_implies", since = "1.0.0")] +#[rustc_const_unstable(feature = "const_foobar", issue = "1", implied_by = "const_bar")] +//~^ ERROR feature `const_bar` implying `const_foobar` does not exist +pub const fn foobar() -> u32 { + 0 +} + +const VAR: u32 = foobar(); diff --git a/tests/ui/stability-attribute/const-stability-attribute-implies-missing.stderr b/tests/ui/stability-attribute/const-stability-attribute-implies-missing.stderr new file mode 100644 index 000000000..6d8b01a54 --- /dev/null +++ b/tests/ui/stability-attribute/const-stability-attribute-implies-missing.stderr @@ -0,0 +1,8 @@ +error: feature `const_bar` implying `const_foobar` does not exist + --> $DIR/const-stability-attribute-implies-missing.rs:10:1 + | +LL | #[rustc_const_unstable(feature = "const_foobar", issue = "1", implied_by = "const_bar")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/tests/ui/stability-attribute/const-stability-attribute-implies-no-feature.rs b/tests/ui/stability-attribute/const-stability-attribute-implies-no-feature.rs new file mode 100644 index 000000000..47e8d2b36 --- /dev/null +++ b/tests/ui/stability-attribute/const-stability-attribute-implies-no-feature.rs @@ -0,0 +1,16 @@ +// aux-build:const-stability-attribute-implies.rs +#![crate_type = "lib"] + +// Tests that despite the `const_foobar` feature being implied by now-stable feature `const_foo`, +// if `const_foobar` isn't allowed in this crate then an error will be emitted. + +extern crate const_stability_attribute_implies; +use const_stability_attribute_implies::{foo, foobar}; + +pub const fn bar() -> u32 { + foo(); // no error - stable + foobar(); //~ ERROR `foobar` is not yet stable as a const fn + 0 +} + +pub const VAR: u32 = bar(); diff --git a/tests/ui/stability-attribute/const-stability-attribute-implies-no-feature.stderr b/tests/ui/stability-attribute/const-stability-attribute-implies-no-feature.stderr new file mode 100644 index 000000000..8ef5a364e --- /dev/null +++ b/tests/ui/stability-attribute/const-stability-attribute-implies-no-feature.stderr @@ -0,0 +1,10 @@ +error: `foobar` is not yet stable as a const fn + --> $DIR/const-stability-attribute-implies-no-feature.rs:12:5 + | +LL | foobar(); + | ^^^^^^^^ + | + = help: add `#![feature(const_foobar)]` to the crate attributes to enable + +error: aborting due to previous error + diff --git a/tests/ui/stability-attribute/const-stability-attribute-implies-using-stable.rs b/tests/ui/stability-attribute/const-stability-attribute-implies-using-stable.rs new file mode 100644 index 000000000..ffaa171d8 --- /dev/null +++ b/tests/ui/stability-attribute/const-stability-attribute-implies-using-stable.rs @@ -0,0 +1,19 @@ +// aux-build:const-stability-attribute-implies.rs +#![crate_type = "lib"] +#![deny(stable_features)] +#![feature(const_foo)] +//~^ ERROR the feature `const_foo` has been partially stabilized since 1.62.0 and is succeeded by the feature `const_foobar` + +// Tests that the use of `implied_by` in the `#[rustc_const_unstable]` attribute results in a +// diagnostic mentioning partial stabilization, and that given the implied unstable feature is +// unused (there is no `foobar` call), that the compiler suggests removing the flag. + +extern crate const_stability_attribute_implies; +use const_stability_attribute_implies::foo; + +pub const fn bar() -> u32 { + foo(); + 0 +} + +pub const VAR: u32 = bar(); diff --git a/tests/ui/stability-attribute/const-stability-attribute-implies-using-stable.stderr b/tests/ui/stability-attribute/const-stability-attribute-implies-using-stable.stderr new file mode 100644 index 000000000..f6a099cd2 --- /dev/null +++ b/tests/ui/stability-attribute/const-stability-attribute-implies-using-stable.stderr @@ -0,0 +1,22 @@ +error: the feature `const_foo` has been partially stabilized since 1.62.0 and is succeeded by the feature `const_foobar` + --> $DIR/const-stability-attribute-implies-using-stable.rs:4:12 + | +LL | #![feature(const_foo)] + | ^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/const-stability-attribute-implies-using-stable.rs:3:9 + | +LL | #![deny(stable_features)] + | ^^^^^^^^^^^^^^^ +help: if you are using features which are still unstable, change to using `const_foobar` + | +LL | #![feature(const_foobar)] + | ~~~~~~~~~~~~ +help: if you are using features which are now stable, remove this line + | +LL - #![feature(const_foo)] + | + +error: aborting due to previous error + diff --git a/tests/ui/stability-attribute/const-stability-attribute-implies-using-unstable.rs b/tests/ui/stability-attribute/const-stability-attribute-implies-using-unstable.rs new file mode 100644 index 000000000..2061c5c75 --- /dev/null +++ b/tests/ui/stability-attribute/const-stability-attribute-implies-using-unstable.rs @@ -0,0 +1,21 @@ +// aux-build:const-stability-attribute-implies.rs +#![crate_type = "lib"] +#![deny(stable_features)] +#![feature(const_foo)] +//~^ ERROR the feature `const_foo` has been partially stabilized since 1.62.0 and is succeeded by the feature `const_foobar` + +// Tests that the use of `implied_by` in the `#[rustc_const_unstable]` attribute results in a +// diagnostic mentioning partial stabilization and that given the implied unstable feature is +// used (there is a `const_foobar` call), that the compiler suggests changing to that feature and +// doesn't error about its use. + +extern crate const_stability_attribute_implies; +use const_stability_attribute_implies::{foo, foobar}; + +pub const fn bar() -> u32 { + foo(); + foobar(); // no error! + 0 +} + +pub const VAR: u32 = bar(); diff --git a/tests/ui/stability-attribute/const-stability-attribute-implies-using-unstable.stderr b/tests/ui/stability-attribute/const-stability-attribute-implies-using-unstable.stderr new file mode 100644 index 000000000..063856676 --- /dev/null +++ b/tests/ui/stability-attribute/const-stability-attribute-implies-using-unstable.stderr @@ -0,0 +1,22 @@ +error: the feature `const_foo` has been partially stabilized since 1.62.0 and is succeeded by the feature `const_foobar` + --> $DIR/const-stability-attribute-implies-using-unstable.rs:4:12 + | +LL | #![feature(const_foo)] + | ^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/const-stability-attribute-implies-using-unstable.rs:3:9 + | +LL | #![deny(stable_features)] + | ^^^^^^^^^^^^^^^ +help: if you are using features which are still unstable, change to using `const_foobar` + | +LL | #![feature(const_foobar)] + | ~~~~~~~~~~~~ +help: if you are using features which are now stable, remove this line + | +LL - #![feature(const_foo)] + | + +error: aborting due to previous error + diff --git a/tests/ui/stability-attribute/issue-109177.rs b/tests/ui/stability-attribute/issue-109177.rs new file mode 100644 index 000000000..6d052779c --- /dev/null +++ b/tests/ui/stability-attribute/issue-109177.rs @@ -0,0 +1,13 @@ +// aux-build: similar-unstable-method.rs + +extern crate similar_unstable_method; + +fn main() { + // FIXME: this function should not suggest the `foo` function. + similar_unstable_method::foo1(); + //~^ ERROR cannot find function `foo1` in crate `similar_unstable_method` [E0425] + + let foo = similar_unstable_method::Foo; + foo.foo1(); + //~^ ERROR no method named `foo1` found for struct `Foo` in the current scope [E0599] +} diff --git a/tests/ui/stability-attribute/issue-109177.stderr b/tests/ui/stability-attribute/issue-109177.stderr new file mode 100644 index 000000000..9c2ac591a --- /dev/null +++ b/tests/ui/stability-attribute/issue-109177.stderr @@ -0,0 +1,21 @@ +error[E0425]: cannot find function `foo1` in crate `similar_unstable_method` + --> $DIR/issue-109177.rs:7:30 + | +LL | similar_unstable_method::foo1(); + | ^^^^ help: a function with a similar name exists: `foo` + | + ::: $DIR/auxiliary/similar-unstable-method.rs:5:1 + | +LL | pub fn foo() {} + | ------------ similarly named function `foo` defined here + +error[E0599]: no method named `foo1` found for struct `Foo` in the current scope + --> $DIR/issue-109177.rs:11:9 + | +LL | foo.foo1(); + | ^^^^ method not found in `Foo` + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0425, E0599. +For more information about an error, try `rustc --explain E0425`. |