Skip to content

Commit

Permalink
Auto merge of #38914 - est31:tidy-gate-tests, r=nikomatsakis
Browse files Browse the repository at this point in the history
Make tidy check for lang gate tests

Add gate tests to the checks that tidy performs. Excerpt from the commit message of the main commit:

    Require compile-fail tests for new lang features

    Its non trivial to test lang feature gates, and people
    forget to add such tests. So we extend the features lint
    of the tidy tool to ensure that all new lang features
    contain a new compile-fail test.

    Of course, one could drop this requirement and just
    grep all tests in run-pass for #![feature(abc)] and
    then run this test again, removing the mention,
    requiring that it fails.

    But this only tests for the existence of a compilation
    failure. Manual tests ensure that also the correct lines
    spawn the error, and also test the actual error message.

    For library features, it makes no sense to require such
    a test, as here code is used that is generic for all
    library features.

The tidy lint extension now checks the compile-fail test suite for occurences of "gate-test-X" where X is a feature. Alternatively, it also accepts file names with the form "feature-gate-X.rs". If a lang feature is found that has no such check, we emit a tidy error.

I've applied the markings to all tests I could find in the test suite. I left a small (20 elements) whitelist of features that right now have no gate test, or where I couldn't find one. Once this PR gets merged, I'd like to close issue #22820 and open a new one on suggestion of @nikomatsakis to track the removal of all elements from that whitelist (already have a draft). Writing such a small test can be a good opportunity for a first contribution, so I won't touch it (let others have the fun xD).

cc @brson , @pnkfelix (they both discussed about this in the issue linked above).
  • Loading branch information
bors committed Jan 14, 2017
2 parents b13cc05 + c6f99b4 commit 6fe2371
Show file tree
Hide file tree
Showing 53 changed files with 225 additions and 20 deletions.
4 changes: 4 additions & 0 deletions COMPILER_TESTS.md
Expand Up @@ -45,6 +45,10 @@ whole, instead of just a few lines inside the test.
* `should-fail` indicates that the test should fail; used for "meta testing",
where we test the compiletest program itself to check that it will generate
errors in appropriate scenarios. This header is ignored for pretty-printer tests.
* `gate-test-X` where `X` is a feature marks the test as "gate test" for feature X.
Such tests are supposed to ensure that the compiler errors when usage of a gated
feature is attempted without the proper `#![feature(X)]` tag.
Each unstable lang feature is required to have a gate test.

## Revisions

Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/asm-gated.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-asm

fn main() {
unsafe {
asm!(""); //~ ERROR inline assembly is not stable enough
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/asm-gated2.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-asm

fn main() {
unsafe {
println!("{}", asm!("")); //~ ERROR inline assembly is not stable
Expand Down
Expand Up @@ -16,6 +16,8 @@
// using `rustc_attrs` feature. There is a separate compile-fail/ test
// ensuring that the attribute feature-gating works in this context.)

// gate-test-generic_param_attrs

#![feature(rustc_attrs)]
#![allow(dead_code)]

Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/check-static-values-constraints.rs
Expand Up @@ -10,6 +10,8 @@

// Verifies all possible restrictions for statics values.

// gate-test-drop_types_in_const

#![feature(box_syntax)]

use std::marker;
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/concat_idents-gate.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-concat_idents

const XY_1: i32 = 10;

fn main() {
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/concat_idents-gate2.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-concat_idents

const XY_1: i32 = 10;

fn main() {
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/const-fn-stability.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-const_fn

// Test use of const fn without feature gate.

const fn foo() -> usize { 0 } //~ ERROR const fn is unstable
Expand Down
4 changes: 4 additions & 0 deletions src/test/compile-fail/feature-gate-abi.rs
Expand Up @@ -8,6 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-intrinsics
// gate-test-platform_intrinsics
// gate-test-abi_vectorcall

// Functions
extern "rust-intrinsic" fn f1() {} //~ ERROR intrinsics are subject to change
extern "platform-intrinsic" fn f2() {} //~ ERROR platform intrinsics are experimental
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/feature-gate-advanced-slice-features.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-advanced_slice_patterns

#![feature(slice_patterns)]

fn main() {
Expand Down
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-allow_internal_unstable

macro_rules! bar {
() => {
// more layers don't help:
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/feature-gate-assoc-type-defaults.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-associated_type_defaults

trait Foo {
type Bar = u8; //~ ERROR associated type defaults are unstable
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/feature-gate-box-expr.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-box_syntax

// Check that `box EXPR` is feature-gated.
//
// See also feature-gate-placement-expr.rs
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/feature-gate-box-pat.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-box_patterns

fn main() {
let box x = Box::new('c'); //~ ERROR box pattern syntax is experimental
println!("x: {}", x);
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/feature-gate-dropck-ugeh.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-dropck_parametricity

// Ensure that attempts to use the unsafe attribute are feature-gated.

// Example adapted from RFC 1238 text (just left out the feature gate).
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/feature-gate-may-dangle.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-dropck_eyepatch

// Check that `may_dangle` is rejected if `dropck_eyepatch` feature gate is absent.

#![feature(generic_param_attrs)]
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/feature-gate-placement-expr.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-placement_in_syntax

// Check that `in PLACE { EXPR }` is feature-gated.
//
// See also feature-gate-box-expr.rs
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/gated-associated_consts.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-associated_consts

trait MyTrait {
const C: bool;
//~^ associated constants are experimental
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/gated-attr-literals.rs
Expand Up @@ -10,6 +10,8 @@

// Check that literals in attributes don't parse without the feature gate.

// gate-test-attr_literals

#![feature(rustc_attrs)]
#![allow(dead_code)]
#![allow(unused_variables)]
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/gated-box-syntax.rs
Expand Up @@ -10,6 +10,8 @@

// Test that the use of the box syntax is gated by `box_syntax` feature gate.

// gate-test-box_syntax

fn main() {
let x = box 3;
//~^ ERROR box expression syntax is experimental; you can call `Box::new` instead.
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/gated-concat_idents.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-concat_idents

fn main() {
concat_idents!(a, b); //~ ERROR `concat_idents` is not stable enough
}
2 changes: 2 additions & 0 deletions src/test/compile-fail/gated-link-args.rs
Expand Up @@ -11,6 +11,8 @@
// Test that `#[link_args]` attribute is gated by `link_args`
// feature gate.

// gate-test-link_args

#[link_args = "aFdEfSeVEEE"]
extern {}
//~^ ERROR the `link_args` attribute is not portable across platforms
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/gated-link-llvm-intrinsics.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-link_llvm_intrinsics

extern {
#[link_name = "llvm.sqrt.f32"]
fn sqrt(x: f32) -> f32;
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/gated-naked_functions.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-naked_functions

#[naked]
//~^ the `#[naked]` attribute is an experimental feature
fn naked() {}
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/gated-no-core.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-no_core

#![no_core] //~ ERROR no_core is experimental

fn main() {}
2 changes: 2 additions & 0 deletions src/test/compile-fail/gated-non-ascii-idents.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-non_ascii_idents

extern crate core as bäz; //~ ERROR non-ascii idents

use föö::bar; //~ ERROR non-ascii idents
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/gated-plugin_registrar.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-plugin_registrar

// Test that `#[plugin_registrar]` attribute is gated by `plugin_registrar`
// feature gate.

Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/gated-target_feature.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-target_feature

#[target_feature = "+sse2"]
//~^ the `#[target_feature]` attribute is an experimental feature
fn foo() {}
2 changes: 2 additions & 0 deletions src/test/compile-fail/gated-thread-local.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-thread_local

// Test that `#[thread_local]` attribute is gated by `thread_local`
// feature gate.
//
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/gated-trace_macros.rs
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-trace_macros

fn main() {
trace_macros!(true); //~ ERROR: `trace_macros` is not stable
Expand Down
3 changes: 3 additions & 0 deletions src/test/compile-fail/i128-feature-2.rs
Expand Up @@ -7,6 +7,9 @@
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-i128_type

fn test1() -> i128 { //~ ERROR 128-bit type is unstable
0
}
Expand Down
3 changes: 3 additions & 0 deletions src/test/compile-fail/i128-feature.rs
Expand Up @@ -7,6 +7,9 @@
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-i128_type

fn test2() {
0i128; //~ ERROR 128-bit integers are not stable
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/impl-trait/feature-gate.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-conservative_impl_trait

fn foo() -> impl Fn() { || {} }
//~^ ERROR `impl Trait` is experimental

Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/link-cfg-gated.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-link_cfg

#[link(name = "foo", cfg(foo))]
//~^ ERROR: is feature gated
extern {}
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/linkage1.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-linkage

extern {
#[linkage = "extern_weak"] static foo: isize;
//~^ ERROR: the `linkage` attribute is experimental and not portable
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/log-syntax-gate.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-log_syntax

fn main() {
log_syntax!() //~ ERROR `log_syntax!` is not stable enough
}
2 changes: 2 additions & 0 deletions src/test/compile-fail/log-syntax-gate2.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-log_syntax

fn main() {
println!("{}", log_syntax!()); //~ ERROR `log_syntax!` is not stable
}
2 changes: 2 additions & 0 deletions src/test/compile-fail/never-disabled.rs
Expand Up @@ -10,6 +10,8 @@

// Test that ! errors when used in illegal positions with feature(never_type) disabled

// gate-test-never_type

trait Foo {
type Wub;
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/no-core-gated.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-no_core

#![no_core] //~ ERROR no_core is experimental

fn main() {}
2 changes: 2 additions & 0 deletions src/test/compile-fail/numeric-fields-feature-gate.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-relaxed_adts

struct S(u8);

fn main() {
Expand Down
3 changes: 3 additions & 0 deletions src/test/compile-fail/panic-runtime/needs-gate.rs
Expand Up @@ -8,6 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-needs_panic_runtime
// gate-test-panic_runtime

#![panic_runtime] //~ ERROR: is an experimental feature
#![needs_panic_runtime] //~ ERROR: is an experimental feature

Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/privacy/restricted/feature-gate.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// gate-test-pub_restricted

pub(crate) //~ ERROR experimental
mod foo {}

Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/rfc1445/feature-gate.rs
Expand Up @@ -14,6 +14,8 @@

// revisions: with_gate no_gate

// gate-test-structural_match

#![allow(dead_code)]
#![deny(future_incompatible)]
#![feature(rustc_attrs)]
Expand Down

0 comments on commit 6fe2371

Please sign in to comment.