Skip to content

Commit 5c3a0b1

Browse files
committed
Add tests checking that a number of feature gates are gating their features.
Namely: * `quote` * `link_args` * `link_llvm_intrinsics` * `thread_local` * `unsafe_destructor` Also updates test for `plugin_registrar` to make it clear that it is only testing the `plugin_registrar` feature gate. Cc rust-lang#22820.
1 parent 2574009 commit 5c3a0b1

File tree

6 files changed

+142
-2
lines changed

6 files changed

+142
-2
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that `quote`-related macro are gated by `quote` feature gate.
12+
13+
// (To sanity-check the code, uncomment this.)
14+
// #![feature(quote)]
15+
16+
// FIXME the error message that is current emitted seems pretty bad.
17+
18+
#![feature(rustc_private)]
19+
#![allow(dead_code, unused_imports, unused_variables)]
20+
21+
#[macro_use]
22+
extern crate syntax;
23+
24+
use syntax::ast;
25+
use syntax::codemap::Span;
26+
use syntax::parse;
27+
28+
struct ParseSess;
29+
30+
impl ParseSess {
31+
fn cfg(&self) -> ast::CrateConfig { loop { } }
32+
fn parse_sess<'a>(&'a self) -> &'a parse::ParseSess { loop { } }
33+
fn call_site(&self) -> Span { loop { } }
34+
fn ident_of(&self, st: &str) -> ast::Ident { loop { } }
35+
fn name_of(&self, st: &str) -> ast::Name { loop { } }
36+
}
37+
38+
pub fn main() {
39+
let ecx = &ParseSess;
40+
let x = quote_tokens!(ecx, 3); //~ ERROR macro undefined: 'quote_tokens!'
41+
let x = quote_expr!(ecx, 3); //~ ERROR macro undefined: 'quote_expr!'
42+
let x = quote_ty!(ecx, 3); //~ ERROR macro undefined: 'quote_ty!'
43+
let x = quote_method!(ecx, 3); //~ ERROR macro undefined: 'quote_method!'
44+
let x = quote_item!(ecx, 3); //~ ERROR macro undefined: 'quote_item!'
45+
let x = quote_pat!(ecx, 3); //~ ERROR macro undefined: 'quote_pat!'
46+
let x = quote_arm!(ecx, 3); //~ ERROR macro undefined: 'quote_arm!'
47+
let x = quote_stmt!(ecx, 3); //~ ERROR macro undefined: 'quote_stmt!'
48+
let x = quote_matcher!(ecx, 3); //~ ERROR macro undefined: 'quote_matcher!'
49+
let x = quote_attr!(ecx, 3); //~ ERROR macro undefined: 'quote_attr!'
50+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that `#[link_args]` attribute is gated by `link_args`
12+
// feature gate.
13+
14+
#[link_args = "aFdEfSeVEEE"]
15+
extern {}
16+
//~^ ERROR the `link_args` attribute is not portable across platforms
17+
//~| HELP add #![feature(link_args)] to the crate attributes to enable
18+
19+
fn main() { }
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
extern {
12+
#[link_name = "llvm.sqrt.f32"]
13+
fn sqrt(x: f32) -> f32;
14+
//~^ ERROR linking to LLVM intrinsics is experimental
15+
//~| HELP add #![feature(link_llvm_intrinsics)] to the crate attributes
16+
}
17+
18+
fn main(){
19+
}

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

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

11+
// Test that `#[plugin_registrar]` attribute is gated by `plugin_registrar`
12+
// feature gate.
13+
1114
// the registration function isn't typechecked yet
1215
#[plugin_registrar]
13-
pub fn registrar() {} //~ ERROR compiler plugins are experimental
14-
16+
pub fn registrar() {}
17+
//~^ ERROR compiler plugins are experimental
18+
//~| HELP add #![feature(plugin_registrar)] to the crate attributes to enable
1519
fn main() {}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that `#[thread_local]` attribute is gated by `thread_local`
12+
// feature gate.
13+
//
14+
// (Note that the `thread_local!` macro is explicitly *not* gated; it
15+
// is given permission to expand into this unstable attribute even
16+
// when the surrounding context does not have permission to use it.)
17+
18+
#[thread_local] //~ ERROR `#[thread_local]` is an experimental feature
19+
static FOO: i32 = 3;
20+
21+
pub fn main() {
22+
FOO.with(|x| {
23+
println!("x: {}", x);
24+
});
25+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that `#[unsafe_destructor]` attribute is gated by `unsafe_destructor`
12+
// feature gate.
13+
14+
struct D<'a>(&'a u32);
15+
16+
#[unsafe_destructor]
17+
impl<'a> Drop for D<'a> {
18+
//~^ ERROR `#[unsafe_destructor]` allows too many unsafe patterns
19+
fn drop(&mut self) { }
20+
}
21+
//~^ HELP: add #![feature(unsafe_destructor)] to the crate attributes to enable
22+
23+
pub fn main() { }

0 commit comments

Comments
 (0)