Skip to content

Commit d22dcb9

Browse files
committed
Auto merge of rust-lang#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](rust-lang#29633 (comment)) and so far nobody spoke up in that issue with a usecase that would require keeping the attribute.* Closes rust-lang#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

Diff for: tests/ui/borrow_as_ptr_no_std.fixed

+2-11
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() {}

Diff for: tests/ui/borrow_as_ptr_no_std.rs

+2-11
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() {}

Diff for: tests/ui/borrow_as_ptr_no_std.stderr

+2-2
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)`

Diff for: tests/ui/box_default_no_std.rs

+2-11
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() {}

Diff for: tests/ui/crashes/ice-7410.rs

+2-11
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() {}

Diff for: tests/ui/crate_level_checks/no_std_main_recursion.rs

-32
This file was deleted.

Diff for: tests/ui/crate_level_checks/no_std_swap.fixed

+1-2
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

Diff for: tests/ui/crate_level_checks/no_std_swap.rs

+1-2
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

Diff for: tests/ui/crate_level_checks/no_std_swap.stderr

+1-1
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
... |

Diff for: tests/ui/def_id_nocore.rs

+1-1
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

Diff for: tests/ui/empty_loop_no_std.rs

+2-18
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,11 @@
22
//@ignore-target: apple
33

44
#![warn(clippy::empty_loop)]
5-
#![feature(lang_items, start, libc)]
5+
#![crate_type = "lib"]
66
#![no_std]
77

8-
use core::panic::PanicInfo;
9-
10-
#[start]
11-
fn main(argc: isize, argv: *const *const u8) -> isize {
8+
pub fn main(argc: isize, argv: *const *const u8) -> isize {
129
// This should trigger the lint
1310
loop {}
1411
//~^ ERROR: empty `loop {}` wastes CPU cycles
1512
}
16-
17-
#[panic_handler]
18-
fn panic(_info: &PanicInfo) -> ! {
19-
// This should NOT trigger the lint
20-
loop {}
21-
}
22-
23-
#[lang = "eh_personality"]
24-
extern "C" fn eh_personality() {
25-
// This should also trigger the lint
26-
loop {}
27-
//~^ ERROR: empty `loop {}` wastes CPU cycles
28-
}

Diff for: tests/ui/empty_loop_no_std.stderr

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: empty `loop {}` wastes CPU cycles
2-
--> tests/ui/empty_loop_no_std.rs:13:5
2+
--> tests/ui/empty_loop_no_std.rs:10:5
33
|
44
LL | loop {}
55
| ^^^^^^^
@@ -8,13 +8,5 @@ LL | loop {}
88
= note: `-D clippy::empty-loop` implied by `-D warnings`
99
= help: to override `-D warnings` add `#[allow(clippy::empty_loop)]`
1010

11-
error: empty `loop {}` wastes CPU cycles
12-
--> tests/ui/empty_loop_no_std.rs:26:5
13-
|
14-
LL | loop {}
15-
| ^^^^^^^
16-
|
17-
= help: you should either use `panic!()` or add a call pausing or sleeping the thread to the loop body
18-
19-
error: aborting due to 2 previous errors
11+
error: aborting due to 1 previous error
2012

Diff for: tests/ui/floating_point_arithmetic_nostd.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(lang_items, start)]
1+
#![crate_type = "lib"]
22
#![warn(clippy::imprecise_flops)]
33
#![warn(clippy::suboptimal_flops)]
44
#![no_std]
@@ -17,15 +17,6 @@ fn fake_abs1(num: f64) -> f64 {
1717
if num >= 0.0 { num } else { -num }
1818
}
1919

20-
#[start]
21-
fn main(_argc: isize, _argv: *const *const u8) -> isize {
20+
pub fn main(_argc: isize, _argv: *const *const u8) -> isize {
2221
0
2322
}
24-
25-
#[panic_handler]
26-
fn panic(_info: &core::panic::PanicInfo) -> ! {
27-
loop {}
28-
}
29-
30-
#[lang = "eh_personality"]
31-
extern "C" fn eh_personality() {}

Diff for: tests/ui/missing_const_for_fn/cant_be_const.rs

-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//@aux-build:../auxiliary/proc_macros.rs
77

88
#![warn(clippy::missing_const_for_fn)]
9-
#![feature(start)]
109
#![feature(type_alias_impl_trait)]
1110

1211
extern crate helper;
@@ -71,15 +70,6 @@ mod with_test_fn {
7170
}
7271
}
7372

74-
// Allowing on this function, because it would lint, which we don't want in this case.
75-
// if we have `#[start]` and `#[test]` check `is_entrypoint_fn(cx, def_id.to_def_id())` is stopped
76-
// working
77-
#[allow(clippy::missing_const_for_fn)]
78-
#[start]
79-
fn init(num: isize, something: *const *const u8) -> isize {
80-
1
81-
}
82-
8373
trait Foo {
8474
// This should not be suggested to be made const
8575
// (rustc doesn't allow const trait methods)

Diff for: tests/ui/missing_spin_loop_no_std.fixed

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
#![warn(clippy::missing_spin_loop)]
2-
#![feature(lang_items, start, libc)]
2+
#![crate_type = "lib"]
33
#![no_std]
44

55
use core::sync::atomic::{AtomicBool, Ordering};
66

7-
#[start]
8-
fn main(_argc: isize, _argv: *const *const u8) -> isize {
7+
pub fn main(_argc: isize, _argv: *const *const u8) -> isize {
98
// This should trigger the lint
109
let b = AtomicBool::new(true);
1110
// This should lint with `core::hint::spin_loop()`
1211
while b.load(Ordering::Acquire) { core::hint::spin_loop() }
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() {}

Diff for: tests/ui/missing_spin_loop_no_std.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
#![warn(clippy::missing_spin_loop)]
2-
#![feature(lang_items, start, libc)]
2+
#![crate_type = "lib"]
33
#![no_std]
44

55
use core::sync::atomic::{AtomicBool, Ordering};
66

7-
#[start]
8-
fn main(_argc: isize, _argv: *const *const u8) -> isize {
7+
pub fn main(_argc: isize, _argv: *const *const u8) -> isize {
98
// This should trigger the lint
109
let b = AtomicBool::new(true);
1110
// This should lint with `core::hint::spin_loop()`
1211
while b.load(Ordering::Acquire) {}
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() {}

Diff for: tests/ui/missing_spin_loop_no_std.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: busy-waiting loop should at least have a spin loop hint
2-
--> tests/ui/missing_spin_loop_no_std.rs:12:37
2+
--> tests/ui/missing_spin_loop_no_std.rs:11:37
33
|
44
LL | while b.load(Ordering::Acquire) {}
55
| ^^ help: try: `{ core::hint::spin_loop() }`

Diff for: tests/ui/result_unit_error_no_std.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#![feature(lang_items, start, libc)]
1+
#![feature(lang_items, libc)]
22
#![no_std]
3+
#![no_main]
34
#![warn(clippy::result_unit_err)]
45

56
#[clippy::msrv = "1.80"]
@@ -12,8 +13,8 @@ pub fn returns_unit_error_lint() -> Result<u32, ()> {
1213
Err(())
1314
}
1415

15-
#[start]
16-
fn main(_argc: isize, _argv: *const *const u8) -> isize {
16+
#[no_mangle]
17+
extern "C" fn main(_argc: core::ffi::c_int, _argv: *const *const u8) -> core::ffi::c_int {
1718
0
1819
}
1920

Diff for: tests/ui/result_unit_error_no_std.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this returns a `Result<_, ()>`
2-
--> tests/ui/result_unit_error_no_std.rs:11:1
2+
--> tests/ui/result_unit_error_no_std.rs:12:1
33
|
44
LL | pub fn returns_unit_error_lint() -> Result<u32, ()> {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Diff for: tests/ui/zero_ptr_no_std.fixed

+2-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
1-
#![feature(lang_items, start, libc)]
1+
#![crate_type = "lib"]
22
#![no_std]
33
#![deny(clippy::zero_ptr)]
44

5-
#[start]
6-
fn main(_argc: isize, _argv: *const *const u8) -> isize {
5+
pub fn main(_argc: isize, _argv: *const *const u8) -> isize {
76
let _ = core::ptr::null::<usize>();
87
let _ = core::ptr::null_mut::<f64>();
98
let _: *const u8 = core::ptr::null();
109
0
1110
}
12-
13-
#[panic_handler]
14-
fn panic(_info: &core::panic::PanicInfo) -> ! {
15-
loop {}
16-
}
17-
18-
#[lang = "eh_personality"]
19-
extern "C" fn eh_personality() {}

0 commit comments

Comments
 (0)