Skip to content

Commit e375a89

Browse files
committed
Auto merge of #21257 - alexcrichton:issue-20064, r=pnkfelix
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
2 parents 65b61ff + 38cb91e commit e375a89

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
@@ -78,6 +78,8 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
7878
("while_let", Accepted),
7979

8080
("plugin", Active),
81+
("start", Active),
82+
("main", Active),
8183

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

284298
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)