Skip to content

Commit 6fe2371

Browse files
committed
Auto merge of #38914 - est31:tidy-gate-tests, r=nikomatsakis
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).
2 parents b13cc05 + c6f99b4 commit 6fe2371

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+225
-20
lines changed

COMPILER_TESTS.md

+4

src/test/compile-fail/asm-gated.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-asm
12+
1113
fn main() {
1214
unsafe {
1315
asm!(""); //~ ERROR inline assembly is not stable enough

src/test/compile-fail/asm-gated2.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-asm
12+
1113
fn main() {
1214
unsafe {
1315
println!("{}", asm!("")); //~ ERROR inline assembly is not stable

src/test/compile-fail/attr-on-generic-formals-wo-feature-gate.rs

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
// using `rustc_attrs` feature. There is a separate compile-fail/ test
1717
// ensuring that the attribute feature-gating works in this context.)
1818

19+
// gate-test-generic_param_attrs
20+
1921
#![feature(rustc_attrs)]
2022
#![allow(dead_code)]
2123

src/test/compile-fail/check-static-values-constraints.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
// Verifies all possible restrictions for statics values.
1212

13+
// gate-test-drop_types_in_const
14+
1315
#![feature(box_syntax)]
1416

1517
use std::marker;

src/test/compile-fail/concat_idents-gate.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-concat_idents
12+
1113
const XY_1: i32 = 10;
1214

1315
fn main() {

src/test/compile-fail/concat_idents-gate2.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-concat_idents
12+
1113
const XY_1: i32 = 10;
1214

1315
fn main() {

src/test/compile-fail/const-fn-stability.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-const_fn
12+
1113
// Test use of const fn without feature gate.
1214

1315
const fn foo() -> usize { 0 } //~ ERROR const fn is unstable

src/test/compile-fail/feature-gate-abi.rs

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-intrinsics
12+
// gate-test-platform_intrinsics
13+
// gate-test-abi_vectorcall
14+
1115
// Functions
1216
extern "rust-intrinsic" fn f1() {} //~ ERROR intrinsics are subject to change
1317
extern "platform-intrinsic" fn f2() {} //~ ERROR platform intrinsics are experimental

src/test/compile-fail/feature-gate-advanced-slice-features.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-advanced_slice_patterns
12+
1113
#![feature(slice_patterns)]
1214

1315
fn main() {

src/test/compile-fail/feature-gate-allow-internal-unstable-nested-macro.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-allow_internal_unstable
12+
1113
macro_rules! bar {
1214
() => {
1315
// more layers don't help:

src/test/compile-fail/feature-gate-assoc-type-defaults.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-associated_type_defaults
12+
1113
trait Foo {
1214
type Bar = u8; //~ ERROR associated type defaults are unstable
1315
}

src/test/compile-fail/feature-gate-box-expr.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-box_syntax
12+
1113
// Check that `box EXPR` is feature-gated.
1214
//
1315
// See also feature-gate-placement-expr.rs

src/test/compile-fail/feature-gate-box-pat.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-box_patterns
12+
1113
fn main() {
1214
let box x = Box::new('c'); //~ ERROR box pattern syntax is experimental
1315
println!("x: {}", x);

src/test/compile-fail/feature-gate-dropck-ugeh.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-dropck_parametricity
12+
1113
// Ensure that attempts to use the unsafe attribute are feature-gated.
1214

1315
// Example adapted from RFC 1238 text (just left out the feature gate).

src/test/compile-fail/feature-gate-may-dangle.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-dropck_eyepatch
12+
1113
// Check that `may_dangle` is rejected if `dropck_eyepatch` feature gate is absent.
1214

1315
#![feature(generic_param_attrs)]

src/test/compile-fail/feature-gate-placement-expr.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-placement_in_syntax
12+
1113
// Check that `in PLACE { EXPR }` is feature-gated.
1214
//
1315
// See also feature-gate-box-expr.rs

src/test/compile-fail/gated-associated_consts.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-associated_consts
12+
1113
trait MyTrait {
1214
const C: bool;
1315
//~^ associated constants are experimental

src/test/compile-fail/gated-attr-literals.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

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

13+
// gate-test-attr_literals
14+
1315
#![feature(rustc_attrs)]
1416
#![allow(dead_code)]
1517
#![allow(unused_variables)]

src/test/compile-fail/gated-box-syntax.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

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

13+
// gate-test-box_syntax
14+
1315
fn main() {
1416
let x = box 3;
1517
//~^ ERROR box expression syntax is experimental; you can call `Box::new` instead.

src/test/compile-fail/gated-concat_idents.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-concat_idents
12+
1113
fn main() {
1214
concat_idents!(a, b); //~ ERROR `concat_idents` is not stable enough
1315
}

src/test/compile-fail/gated-link-args.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
// Test that `#[link_args]` attribute is gated by `link_args`
1212
// feature gate.
1313

14+
// gate-test-link_args
15+
1416
#[link_args = "aFdEfSeVEEE"]
1517
extern {}
1618
//~^ ERROR the `link_args` attribute is not portable across platforms

src/test/compile-fail/gated-link-llvm-intrinsics.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-link_llvm_intrinsics
12+
1113
extern {
1214
#[link_name = "llvm.sqrt.f32"]
1315
fn sqrt(x: f32) -> f32;

src/test/compile-fail/gated-naked_functions.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-naked_functions
12+
1113
#[naked]
1214
//~^ the `#[naked]` attribute is an experimental feature
1315
fn naked() {}

src/test/compile-fail/gated-no-core.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-no_core
12+
1113
#![no_core] //~ ERROR no_core is experimental
1214

1315
fn main() {}

src/test/compile-fail/gated-non-ascii-idents.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-non_ascii_idents
12+
1113
extern crate core as bäz; //~ ERROR non-ascii idents
1214

1315
use föö::bar; //~ ERROR non-ascii idents

src/test/compile-fail/gated-plugin_registrar.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-plugin_registrar
12+
1113
// Test that `#[plugin_registrar]` attribute is gated by `plugin_registrar`
1214
// feature gate.
1315

src/test/compile-fail/gated-target_feature.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-target_feature
12+
1113
#[target_feature = "+sse2"]
1214
//~^ the `#[target_feature]` attribute is an experimental feature
1315
fn foo() {}

src/test/compile-fail/gated-thread-local.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-thread_local
12+
1113
// Test that `#[thread_local]` attribute is gated by `thread_local`
1214
// feature gate.
1315
//

src/test/compile-fail/gated-trace_macros.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-trace_macros
1112

1213
fn main() {
1314
trace_macros!(true); //~ ERROR: `trace_macros` is not stable

src/test/compile-fail/i128-feature-2.rs

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
10+
11+
// gate-test-i128_type
12+
1013
fn test1() -> i128 { //~ ERROR 128-bit type is unstable
1114
0
1215
}

src/test/compile-fail/i128-feature.rs

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
10+
11+
// gate-test-i128_type
12+
1013
fn test2() {
1114
0i128; //~ ERROR 128-bit integers are not stable
1215
}

src/test/compile-fail/impl-trait/feature-gate.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-conservative_impl_trait
12+
1113
fn foo() -> impl Fn() { || {} }
1214
//~^ ERROR `impl Trait` is experimental
1315

src/test/compile-fail/link-cfg-gated.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-link_cfg
12+
1113
#[link(name = "foo", cfg(foo))]
1214
//~^ ERROR: is feature gated
1315
extern {}

src/test/compile-fail/linkage1.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-linkage
12+
1113
extern {
1214
#[linkage = "extern_weak"] static foo: isize;
1315
//~^ ERROR: the `linkage` attribute is experimental and not portable

src/test/compile-fail/log-syntax-gate.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-log_syntax
12+
1113
fn main() {
1214
log_syntax!() //~ ERROR `log_syntax!` is not stable enough
1315
}

src/test/compile-fail/log-syntax-gate2.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-log_syntax
12+
1113
fn main() {
1214
println!("{}", log_syntax!()); //~ ERROR `log_syntax!` is not stable
1315
}

src/test/compile-fail/never-disabled.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

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

13+
// gate-test-never_type
14+
1315
trait Foo {
1416
type Wub;
1517
}

src/test/compile-fail/no-core-gated.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-no_core
12+
1113
#![no_core] //~ ERROR no_core is experimental
1214

1315
fn main() {}

src/test/compile-fail/numeric-fields-feature-gate.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-relaxed_adts
12+
1113
struct S(u8);
1214

1315
fn main() {

src/test/compile-fail/panic-runtime/needs-gate.rs

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-needs_panic_runtime
12+
// gate-test-panic_runtime
13+
1114
#![panic_runtime] //~ ERROR: is an experimental feature
1215
#![needs_panic_runtime] //~ ERROR: is an experimental feature
1316

src/test/compile-fail/privacy/restricted/feature-gate.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// gate-test-pub_restricted
12+
1113
pub(crate) //~ ERROR experimental
1214
mod foo {}
1315

src/test/compile-fail/rfc1445/feature-gate.rs

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
// revisions: with_gate no_gate
1616

17+
// gate-test-structural_match
18+
1719
#![allow(dead_code)]
1820
#![deny(future_incompatible)]
1921
#![feature(rustc_attrs)]

0 commit comments

Comments
 (0)