Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a4c139b

Browse files
committedJan 20, 2025·
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
2 parents 9f4d9dc + 019763d commit a4c139b

File tree

176 files changed

+549
-1266
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

176 files changed

+549
-1266
lines changed
 

Diff for: ‎compiler/rustc_ast/src/entry.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ pub enum EntryPointType {
1818
/// fn main() {}
1919
/// ```
2020
RustcMainAttr,
21-
/// This is a function with the `#[start]` attribute.
22-
/// ```ignore (clashes with test entrypoint)
23-
/// #[start]
24-
/// fn main() {}
25-
/// ```
26-
Start,
2721
/// This function is **not** an entrypoint but simply named `main` (not at the root).
2822
/// This is only used for diagnostics.
2923
/// ```
@@ -40,9 +34,7 @@ pub fn entry_point_type(
4034
at_root: bool,
4135
name: Option<Symbol>,
4236
) -> EntryPointType {
43-
if attr::contains_name(attrs, sym::start) {
44-
EntryPointType::Start
45-
} else if attr::contains_name(attrs, sym::rustc_main) {
37+
if attr::contains_name(attrs, sym::rustc_main) {
4638
EntryPointType::RustcMainAttr
4739
} else if let Some(name) = name
4840
&& name == sym::main

Diff for: ‎compiler/rustc_ast_passes/src/feature_gate.rs

-12
Original file line numberDiff line numberDiff line change
@@ -230,18 +230,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
230230
}
231231
}
232232

233-
ast::ItemKind::Fn(..) => {
234-
if attr::contains_name(&i.attrs, sym::start) {
235-
gate!(
236-
&self,
237-
start,
238-
i.span,
239-
"`#[start]` functions are experimental and their signature may change \
240-
over time"
241-
);
242-
}
243-
}
244-
245233
ast::ItemKind::Struct(..) | ast::ItemKind::Enum(..) | ast::ItemKind::Union(..) => {
246234
for attr in attr::filter_by_name(&i.attrs, sym::repr) {
247235
for item in attr.meta_item_list().unwrap_or_else(ThinVec::new) {

0 commit comments

Comments
 (0)
Please sign in to comment.