Skip to content

Commit 38cb91e

Browse files
committed
syntax: Feature gate #[start] and #[main]
These two attributes are used to change the entry point into a Rust program, but for now they're being put behind feature gates until we have a chance to think about them a little more. The #[start] attribute specifically may have its signature changed. This is a breaking change to due the usage of these attributes generating errors by default now. If your crate is using these attributes, add this to your crate root: #![feature(start)] // if you're using the #[start] attribute #![feature(main)] // if you're using the #[main] attribute cc #20064
1 parent ee2bfae commit 38cb91e

26 files changed

+71
-13
lines changed

src/doc/trpl/unsafe.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ in the same format as C:
447447

448448
```
449449
#![no_std]
450-
#![feature(lang_items)]
450+
#![feature(lang_items, start)]
451451
452452
// Pull in the system libc library for what crt0.o likely requires
453453
extern crate libc;
@@ -475,7 +475,7 @@ compiler's name mangling too:
475475
```ignore
476476
#![no_std]
477477
#![no_main]
478-
#![feature(lang_items)]
478+
#![feature(lang_items, start)]
479479
480480
extern crate libc;
481481
@@ -529,7 +529,7 @@ vectors provided from C, using idiomatic Rust practices.
529529

530530
```
531531
#![no_std]
532-
#![feature(lang_items)]
532+
#![feature(lang_items, start)]
533533
534534
# extern crate libc;
535535
extern crate core;
@@ -653,7 +653,7 @@ sugar for dynamic allocations via `malloc` and `free`:
653653

654654
```
655655
#![no_std]
656-
#![feature(lang_items, box_syntax)]
656+
#![feature(lang_items, box_syntax, start)]
657657
658658
extern crate libc;
659659

src/libsyntax/feature_gate.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
7777
("while_let", Accepted),
7878

7979
("plugin", Active),
80+
("start", Active),
81+
("main", Active),
8082

8183
// A temporary feature gate used to enable parser extensions needed
8284
// to bootstrap fix for #5723.
@@ -276,6 +278,18 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
276278
self.gate_feature("plugin_registrar", i.span,
277279
"compiler plugins are experimental and possibly buggy");
278280
}
281+
if attr::contains_name(&i.attrs[], "start") {
282+
self.gate_feature("start", i.span,
283+
"a #[start] function is an experimental \
284+
feature whose signature may change \
285+
over time");
286+
}
287+
if attr::contains_name(&i.attrs[], "main") {
288+
self.gate_feature("main", i.span,
289+
"declaration of a nonstandard #[main] \
290+
function may change over time, for now \
291+
a top-level `fn main()` is required");
292+
}
279293
}
280294

281295
ast::ItemStruct(..) => {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
#[main]
12+
fn foo() {} //~ ERROR: declaration of a nonstandard #[main] function may change over time
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
#[start]
12+
fn foo() {} //~ ERROR: a #[start] function is an experimental feature
13+

src/test/compile-fail/issue-9575.rs

Lines changed: 2 additions & 0 deletions
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+
#![feature(start)]
12+
1113
#[start]
1214
fn start(argc: isize, argv: *const *const u8, crate_map: *const u8) -> isize {
1315
//~^ ERROR incorrect number of function parameters

src/test/compile-fail/lang-item-missing.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// error-pattern: requires `sized` lang_item
1515

1616
#![no_std]
17+
#![feature(start)]
1718

1819
#[start]
1920
fn start(argc: isize, argv: *const *const u8) -> isize {

src/test/compile-fail/lint-dead-code-2.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#![allow(unused_variables)]
1212
#![deny(dead_code)]
13+
#![feature(main, start)]
1314

1415
struct Foo;
1516

src/test/compile-fail/multiple-main-2.rs

Lines changed: 2 additions & 0 deletions
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+
#![feature(main)]
12+
1113
#[main]
1214
fn bar() {
1315
}

src/test/compile-fail/multiple-main-3.rs

Lines changed: 2 additions & 0 deletions
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+
#![feature(main)]
12+
1113
#[main]
1214
fn main1() {
1315
}

src/test/compile-fail/privacy1.rs

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

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

1414
#[lang="sized"]

0 commit comments

Comments
 (0)