Skip to content

Add tests checking that a number of feature gates are gating their features #23226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/test/compile-fail-fulldeps/gated-quote.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <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.

// Test that `quote`-related macro are gated by `quote` feature gate.

// (To sanity-check the code, uncomment this.)
// #![feature(quote)]

// FIXME the error message that is current emitted seems pretty bad.

#![feature(rustc_private)]
#![allow(dead_code, unused_imports, unused_variables)]

#[macro_use]
extern crate syntax;

use syntax::ast;
use syntax::codemap::Span;
use syntax::parse;

struct ParseSess;

impl ParseSess {
fn cfg(&self) -> ast::CrateConfig { loop { } }
fn parse_sess<'a>(&'a self) -> &'a parse::ParseSess { loop { } }
fn call_site(&self) -> Span { loop { } }
fn ident_of(&self, st: &str) -> ast::Ident { loop { } }
fn name_of(&self, st: &str) -> ast::Name { loop { } }
}

pub fn main() {
let ecx = &ParseSess;
let x = quote_tokens!(ecx, 3); //~ ERROR macro undefined: 'quote_tokens!'
let x = quote_expr!(ecx, 3); //~ ERROR macro undefined: 'quote_expr!'
let x = quote_ty!(ecx, 3); //~ ERROR macro undefined: 'quote_ty!'
let x = quote_method!(ecx, 3); //~ ERROR macro undefined: 'quote_method!'
let x = quote_item!(ecx, 3); //~ ERROR macro undefined: 'quote_item!'
let x = quote_pat!(ecx, 3); //~ ERROR macro undefined: 'quote_pat!'
let x = quote_arm!(ecx, 3); //~ ERROR macro undefined: 'quote_arm!'
let x = quote_stmt!(ecx, 3); //~ ERROR macro undefined: 'quote_stmt!'
let x = quote_matcher!(ecx, 3); //~ ERROR macro undefined: 'quote_matcher!'
let x = quote_attr!(ecx, 3); //~ ERROR macro undefined: 'quote_attr!'
}
19 changes: 19 additions & 0 deletions src/test/compile-fail/gated-link-args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <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.

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

#[link_args = "aFdEfSeVEEE"]
extern {}
//~^ ERROR the `link_args` attribute is not portable across platforms
//~| HELP add #![feature(link_args)] to the crate attributes to enable

fn main() { }
19 changes: 19 additions & 0 deletions src/test/compile-fail/gated-link-llvm-intrinsics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <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.

extern {
#[link_name = "llvm.sqrt.f32"]
fn sqrt(x: f32) -> f32;
//~^ ERROR linking to LLVM intrinsics is experimental
//~| HELP add #![feature(link_llvm_intrinsics)] to the crate attributes
}

fn main(){
}
8 changes: 6 additions & 2 deletions src/test/compile-fail/gated-plugin_registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

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

// the registration function isn't typechecked yet
#[plugin_registrar]
pub fn registrar() {} //~ ERROR compiler plugins are experimental

pub fn registrar() {}
//~^ ERROR compiler plugins are experimental
//~| HELP add #![feature(plugin_registrar)] to the crate attributes to enable
fn main() {}
25 changes: 25 additions & 0 deletions src/test/compile-fail/gated-thread-local.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <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.

// Test that `#[thread_local]` attribute is gated by `thread_local`
// feature gate.
//
// (Note that the `thread_local!` macro is explicitly *not* gated; it
// is given permission to expand into this unstable attribute even
// when the surrounding context does not have permission to use it.)

#[thread_local] //~ ERROR `#[thread_local]` is an experimental feature
static FOO: i32 = 3;

pub fn main() {
FOO.with(|x| {
println!("x: {}", x);
});
}
23 changes: 23 additions & 0 deletions src/test/compile-fail/gated-unsafe-destructor.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <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.

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

struct D<'a>(&'a u32);

#[unsafe_destructor]
impl<'a> Drop for D<'a> {
//~^ ERROR `#[unsafe_destructor]` allows too many unsafe patterns
fn drop(&mut self) { }
}
//~^ HELP: add #![feature(unsafe_destructor)] to the crate attributes to enable

pub fn main() { }