Skip to content

Commit d22dcb9

Browse files
committed
Auto merge of #134299 - RalfJung:remove-start, r=compiler-errors
remove support for the (unstable) #[start] attribute As explained by `@Noratrieb:` `#[start]` should be deleted. It's nothing but an accidentally leaked implementation detail that's a not very useful mix between "portable" entrypoint logic and bad abstraction. I think the way the stable user-facing entrypoint should work (and works today on stable) is pretty simple: - `std`-using cross-platform programs should use `fn main()`. the compiler, together with `std`, will then ensure that code ends up at `main` (by having a platform-specific entrypoint that gets directed through `lang_start` in `std` to `main` - but that's just an implementation detail) - `no_std` platform-specific programs should use `#![no_main]` and define their own platform-specific entrypoint symbol with `#[no_mangle]`, like `main`, `_start`, `WinMain` or `my_embedded_platform_wants_to_start_here`. most of them only support a single platform anyways, and need cfg for the different platform's ways of passing arguments or other things *anyways* `#[start]` is in a super weird position of being neither of those two. It tries to pretend that it's cross-platform, but its signature is a total lie. Those arguments are just stubbed out to zero on ~~Windows~~ wasm, for example. It also only handles the platform-specific entrypoints for a few platforms that are supported by `std`, like Windows or Unix-likes. `my_embedded_platform_wants_to_start_here` can't use it, and neither could a libc-less Linux program. So we have an attribute that only works in some cases anyways, that has a signature that's a total lie (and a signature that, as I might want to add, has changed recently, and that I definitely would not be comfortable giving *any* stability guarantees on), and where there's a pretty easy way to get things working without it in the first place. Note that this feature has **not** been RFCed in the first place. *This comment was posted [in May](#29633 (comment)) and so far nobody spoke up in that issue with a usecase that would require keeping the attribute.* Closes #29633 try-job: x86_64-gnu-nopt try-job: x86_64-msvc-1 try-job: x86_64-msvc-2 try-job: test-various
2 parents e7f1e42 + 759212c commit d22dcb9

22 files changed

+37
-185
lines changed

tests/ui/borrow_as_ptr_no_std.fixed

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
#![warn(clippy::borrow_as_ptr)]
2-
#![feature(lang_items, start, libc)]
32
#![no_std]
3+
#![crate_type = "lib"]
44

55
#[clippy::msrv = "1.75"]
6-
#[start]
7-
fn main(_argc: isize, _argv: *const *const u8) -> isize {
6+
pub fn main(_argc: isize, _argv: *const *const u8) -> isize {
87
let val = 1;
98
let _p = core::ptr::addr_of!(val);
109

1110
let mut val_mut = 1;
1211
let _p_mut = core::ptr::addr_of_mut!(val_mut);
1312
0
1413
}
15-
16-
#[panic_handler]
17-
fn panic(_info: &core::panic::PanicInfo) -> ! {
18-
loop {}
19-
}
20-
21-
#[lang = "eh_personality"]
22-
extern "C" fn eh_personality() {}

tests/ui/borrow_as_ptr_no_std.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
#![warn(clippy::borrow_as_ptr)]
2-
#![feature(lang_items, start, libc)]
32
#![no_std]
3+
#![crate_type = "lib"]
44

55
#[clippy::msrv = "1.75"]
6-
#[start]
7-
fn main(_argc: isize, _argv: *const *const u8) -> isize {
6+
pub fn main(_argc: isize, _argv: *const *const u8) -> isize {
87
let val = 1;
98
let _p = &val as *const i32;
109

1110
let mut val_mut = 1;
1211
let _p_mut = &mut val_mut as *mut i32;
1312
0
1413
}
15-
16-
#[panic_handler]
17-
fn panic(_info: &core::panic::PanicInfo) -> ! {
18-
loop {}
19-
}
20-
21-
#[lang = "eh_personality"]
22-
extern "C" fn eh_personality() {}

tests/ui/borrow_as_ptr_no_std.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: borrow as raw pointer
2-
--> tests/ui/borrow_as_ptr_no_std.rs:9:14
2+
--> tests/ui/borrow_as_ptr_no_std.rs:8:14
33
|
44
LL | let _p = &val as *const i32;
55
| ^^^^^^^^^^^^^^^^^^ help: try: `core::ptr::addr_of!(val)`
@@ -8,7 +8,7 @@ LL | let _p = &val as *const i32;
88
= help: to override `-D warnings` add `#[allow(clippy::borrow_as_ptr)]`
99

1010
error: borrow as raw pointer
11-
--> tests/ui/borrow_as_ptr_no_std.rs:12:18
11+
--> tests/ui/borrow_as_ptr_no_std.rs:11:18
1212
|
1313
LL | let _p_mut = &mut val_mut as *mut i32;
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `core::ptr::addr_of_mut!(val_mut)`

tests/ui/box_default_no_std.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#![feature(lang_items, start, libc)]
21
#![warn(clippy::box_default)]
32
#![no_std]
3+
#![crate_type = "lib"]
44

55
pub struct NotBox<T> {
66
_value: T,
@@ -18,16 +18,7 @@ impl<T: Default> Default for NotBox<T> {
1818
}
1919
}
2020

21-
#[start]
22-
fn main(_argc: isize, _argv: *const *const u8) -> isize {
21+
pub fn main(_argc: isize, _argv: *const *const u8) -> isize {
2322
let _p = NotBox::new(isize::default());
2423
0
2524
}
26-
27-
#[panic_handler]
28-
fn panic(_info: &core::panic::PanicInfo) -> ! {
29-
loop {}
30-
}
31-
32-
#[lang = "eh_personality"]
33-
extern "C" fn eh_personality() {}

tests/ui/crashes/ice-7410.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@compile-flags: -Clink-arg=-nostartfiles
22
//@ignore-target: apple windows
33

4-
#![feature(lang_items, start, libc)]
4+
#![crate_type = "lib"]
55
#![no_std]
66
#![allow(clippy::if_same_then_else)]
77
#![allow(clippy::redundant_pattern_matching)]
@@ -15,18 +15,9 @@ impl Drop for S {
1515
fn drop(&mut self) {}
1616
}
1717

18-
#[start]
19-
fn main(argc: isize, argv: *const *const u8) -> isize {
18+
pub fn main(argc: isize, argv: *const *const u8) -> isize {
2019
if let Some(_) = Some(S) {
2120
} else {
2221
}
2322
0
2423
}
25-
26-
#[panic_handler]
27-
fn panic(_info: &PanicInfo) -> ! {
28-
loop {}
29-
}
30-
31-
#[lang = "eh_personality"]
32-
extern "C" fn eh_personality() {}

tests/ui/crate_level_checks/no_std_main_recursion.rs

Lines changed: 0 additions & 32 deletions
This file was deleted.

tests/ui/crate_level_checks/no_std_swap.fixed

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#![no_std]
2-
#![feature(lang_items, start, libc)]
32
#![crate_type = "lib"]
43

54
use core::panic::PanicInfo;
65

76
#[warn(clippy::all)]
8-
fn main() {
7+
pub fn main() {
98
let mut a = 42;
109
let mut b = 1337;
1110

tests/ui/crate_level_checks/no_std_swap.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#![no_std]
2-
#![feature(lang_items, start, libc)]
32
#![crate_type = "lib"]
43

54
use core::panic::PanicInfo;
65

76
#[warn(clippy::all)]
8-
fn main() {
7+
pub fn main() {
98
let mut a = 42;
109
let mut b = 1337;
1110

tests/ui/crate_level_checks/no_std_swap.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this looks like you are trying to swap `a` and `b`
2-
--> tests/ui/crate_level_checks/no_std_swap.rs:12:5
2+
--> tests/ui/crate_level_checks/no_std_swap.rs:11:5
33
|
44
LL | / a = b;
55
... |

tests/ui/def_id_nocore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ignore-target: apple
22

3-
#![feature(no_core, lang_items, start)]
3+
#![feature(no_core, lang_items)]
44
#![no_core]
55
#![allow(clippy::missing_safety_doc)]
66

0 commit comments

Comments
 (0)