Skip to content

syntax: Feature gate #[start] and #[main] #21257

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
Jan 20, 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
8 changes: 4 additions & 4 deletions src/doc/trpl/unsafe.md
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ in the same format as C:

```
#![no_std]
#![feature(lang_items)]
#![feature(lang_items, start)]

// Pull in the system libc library for what crt0.o likely requires
extern crate libc;
Expand Down Expand Up @@ -475,7 +475,7 @@ compiler's name mangling too:
```ignore
#![no_std]
#![no_main]
#![feature(lang_items)]
#![feature(lang_items, start)]

extern crate libc;

Expand Down Expand Up @@ -529,7 +529,7 @@ vectors provided from C, using idiomatic Rust practices.

```
#![no_std]
#![feature(lang_items)]
#![feature(lang_items, start)]

# extern crate libc;
extern crate core;
Expand Down Expand Up @@ -653,7 +653,7 @@ sugar for dynamic allocations via `malloc` and `free`:

```
#![no_std]
#![feature(lang_items, box_syntax)]
#![feature(lang_items, box_syntax, start)]

extern crate libc;

Expand Down
14 changes: 14 additions & 0 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
("while_let", Accepted),

("plugin", Active),
("start", Active),
("main", Active),

// A temporary feature gate used to enable parser extensions needed
// to bootstrap fix for #5723.
Expand Down Expand Up @@ -276,6 +278,18 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
self.gate_feature("plugin_registrar", i.span,
"compiler plugins are experimental and possibly buggy");
}
if attr::contains_name(&i.attrs[], "start") {
self.gate_feature("start", i.span,
"a #[start] function is an experimental \
feature whose signature may change \
over time");
}
if attr::contains_name(&i.attrs[], "main") {
self.gate_feature("main", i.span,
"declaration of a nonstandard #[main] \
function may change over time, for now \
a top-level `fn main()` is required");
}
}

ast::ItemStruct(..) => {
Expand Down
12 changes: 12 additions & 0 deletions src/test/compile-fail/feature-gate-main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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.

#[main]
fn foo() {} //~ ERROR: declaration of a nonstandard #[main] function may change over time
13 changes: 13 additions & 0 deletions src/test/compile-fail/feature-gate-start.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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.

#[start]
fn foo() {} //~ ERROR: a #[start] function is an experimental feature

2 changes: 2 additions & 0 deletions src/test/compile-fail/issue-9575.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(start)]

#[start]
fn start(argc: isize, argv: *const *const u8, crate_map: *const u8) -> isize {
//~^ ERROR incorrect number of function parameters
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/lang-item-missing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// error-pattern: requires `sized` lang_item

#![no_std]
#![feature(start)]

#[start]
fn start(argc: isize, argv: *const *const u8) -> isize {
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/lint-dead-code-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#![allow(unused_variables)]
#![deny(dead_code)]
#![feature(main, start)]

struct Foo;

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

#![feature(main)]

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

#![feature(main)]

#[main]
fn main1() {
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/privacy1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(lang_items)]
#![feature(lang_items, start)]
#![no_std] // makes debugging this test *a lot* easier (during resolve)

#[lang="sized"]
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/privacy2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(start)]
#![no_std] // makes debugging this test *a lot* easier (during resolve)

// Test to make sure that globs don't leak in regular `use` statements.
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/privacy3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(start)]
#![no_std] // makes debugging this test *a lot* easier (during resolve)

// Test to make sure that private items imported through globs remain private
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/privacy4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(lang_items)]
#![feature(lang_items, start)]
#![no_std] // makes debugging this test *a lot* easier (during resolve)

#[lang = "sized"] pub trait Sized {}
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/attr-main-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(main)]

pub fn main() {
panic!()
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/attr-main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(main)]

#[main]
fn foo() {
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/attr-start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(start)]

#[start]
fn start(_argc: int, _argv: *const *const u8) -> int {
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(main)]

#[main]
fn foo() {
}
2 changes: 1 addition & 1 deletion src/test/run-pass/intrinsic-alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(intrinsics)]
#![feature(intrinsics, main)]

mod rusti {
extern "rust-intrinsic" {
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/issue-16597-empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

// compile-flags:--test
// no-pretty-expanded

// This verifies that the test generation doesn't crash when we have
// no tests - for more information, see PR #16892.
1 change: 1 addition & 0 deletions src/test/run-pass/issue-20823.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

// compile-flags: --test
// no-pretty-expanded

#![deny(unstable)]

Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/lang-item-public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// ignore-windows #13361

#![no_std]
#![feature(lang_items)]
#![feature(lang_items, start)]

extern crate "lang-item-public" as lang_lib;

Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/native-print-no-runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(start)]

#[start]
pub fn main(_: int, _: *const *const u8) -> int {
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/running-with-no-runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(start)]

use std::ffi;
use std::io::process::{Command, ProcessOutput};
use std::os;
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/smallest-hello-world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// Smallest "hello world" with a libc runtime

#![no_std]
#![feature(intrinsics, lang_items)]
#![feature(intrinsics, lang_items, start)]

extern crate libc;

Expand Down
5 changes: 2 additions & 3 deletions src/test/run-pass/use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.


#![allow(unused_imports)]

#![feature(start)]
#![no_std]

extern crate std;
extern crate "std" as zed;


use std::str;
use zed::str as x;
mod baz {
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/vec-macro-no-std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(lang_items)]
#![feature(lang_items, start)]
#![no_std]

extern crate "std" as other;
Expand Down