rust/compiler
Matthias Krüger 84c28041b4
Rollup merge of #93753 - jeremyBanks:main-conflict, r=petrochenkov
Complete removal of #[main] attribute from compiler

resolves #93786

---

The `#[main]` attribute was mostly removed from the language in #84217, but not completely. It is still recognized as a builtin attribute by the compiler, but it has no effect. However, this no-op attribute is no longer gated by `#[feature(main)]` (which no longer exists), so it's possible to include it in code *on stable* without any errors, which seems unintentional. For example, the following code is accepted ([playground link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&code=%23%5Bmain%5D%0Afn%20main()%20%7B%0A%20%20%20%20println!(%22hello%20world%22)%3B%0A%7D%0A)).

```rust
#[main]
fn main() {
    println!("hello world");
}
```

Aside from that oddity, the existence of this attribute causes code like the following to fail ([playground link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&code=use%20tokio%3A%3Amain%3B%0A%0A%23%5Bmain%5D%0Afn%20main()%20%7B%0A%20%20%20%20println!(%22hello%20world%22)%3B%0A%7D%0A)). According https://github.com/rust-lang/rust/pull/84062#issuecomment-825038275, the removal of `#[main]` was expected to eliminate this conflict (previously reported as #62127).

```rust
use tokio::main;

#[main]
fn main() {
    println!("hello world");
}
```

```
error[E0659]: `main` is ambiguous
 --> src/main.rs:3:3
  |
3 | #[main]
  |   ^^^^ ambiguous name
  |
  = note: ambiguous because of a name conflict with a builtin attribute
  = note: `main` could refer to a built-in attribute
```

[This error message can be confusing](https://stackoverflow.com/q/71024443/1114), as the mostly-removed `#[main]` attribute is not mentioned in any documentation.

Since the current availability of `#[main]` on stable seems unintentional, and to needlessly block use of the `main` identifier in the attribute namespace, this PR finishes removing the `#[main]` attribute as described in https://github.com/rust-lang/rust/issues/29634#issuecomment-274951753 by deleting it from `builtin_attrs.rs`, and adds two test cases to ensure that the attribute is no longer accepted and no longer conflicts with other attributes imported as `main`.
2022-02-09 23:29:57 +01:00
..
rustc
rustc_apfloat
rustc_arena
rustc_ast Add test for block doc comments horizontal trim 2022-02-07 17:07:53 +01:00
rustc_ast_lowering Rollup merge of #93746 - cjgillot:nodefii, r=nikomatsakis 2022-02-09 14:12:22 +09:00
rustc_ast_passes Auto merge of #93561 - Amanieu:more-unwind-abi, r=nagisa 2022-02-08 03:20:05 +00:00
rustc_ast_pretty
rustc_attr
rustc_borrowck Improve opaque type higher-ranked region error message under NLL 2022-02-08 12:35:42 -05:00
rustc_builtin_macros Rollup merge of #91950 - estebank:point-at-type-of-non-allocator, r=matthewjasper 2022-02-08 16:40:45 +01:00
rustc_codegen_cranelift
rustc_codegen_gcc #[used(linker)] attribute (https://github.com/dtolnay/linkme/issues/41) 2022-02-06 20:23:23 +01:00
rustc_codegen_llvm Rollup merge of #93503 - michaelwoerister:fix-vtable-holder-debuginfo-regression, r=wesleywiser 2022-02-09 23:29:56 +01:00
rustc_codegen_ssa Rollup merge of #93503 - michaelwoerister:fix-vtable-holder-debuginfo-regression, r=wesleywiser 2022-02-09 23:29:56 +01:00
rustc_const_eval Auto merge of #92007 - oli-obk:lazy_tait2, r=nikomatsakis 2022-02-07 23:40:26 +00:00
rustc_data_structures Auto merge of #92007 - oli-obk:lazy_tait2, r=nikomatsakis 2022-02-07 23:40:26 +00:00
rustc_driver Store rlink data in opaque binary format on disk 2022-02-05 15:17:54 -05:00
rustc_error_codes Rollup merge of #91939 - GKFX:feature-91866, r=cjgillot 2022-02-06 04:13:29 +01:00
rustc_errors
rustc_expand
rustc_feature Rollup merge of #93753 - jeremyBanks:main-conflict, r=petrochenkov 2022-02-09 23:29:57 +01:00
rustc_fs_util
rustc_graphviz
rustc_hir Rollup merge of #93746 - cjgillot:nodefii, r=nikomatsakis 2022-02-09 14:12:22 +09:00
rustc_hir_pretty Rollup merge of #93746 - cjgillot:nodefii, r=nikomatsakis 2022-02-09 14:12:22 +09:00
rustc_incremental
rustc_index
rustc_infer Auto merge of #92306 - Aaron1011:opaque-type-op, r=oli-obk 2022-02-09 09:41:48 +00:00
rustc_interface Auto merge of #93724 - Mark-Simulacrum:drop-query-stats, r=michaelwoerister 2022-02-09 15:53:10 +00:00
rustc_lexer
rustc_lint Auto merge of #92007 - oli-obk:lazy_tait2, r=nikomatsakis 2022-02-07 23:40:26 +00:00
rustc_lint_defs
rustc_llvm
rustc_log
rustc_macros
rustc_metadata Auto merge of #93561 - Amanieu:more-unwind-abi, r=nagisa 2022-02-08 03:20:05 +00:00
rustc_middle Rollup merge of #91504 - cynecx:used_retain, r=nikic 2022-02-09 23:29:56 +01:00
rustc_mir_build Auto merge of #92007 - oli-obk:lazy_tait2, r=nikomatsakis 2022-02-07 23:40:26 +00:00
rustc_mir_dataflow
rustc_mir_transform
rustc_monomorphize
rustc_parse
rustc_parse_format
rustc_passes Rollup merge of #91504 - cynecx:used_retain, r=nikic 2022-02-09 23:29:56 +01:00
rustc_plugin_impl
rustc_privacy
rustc_query_impl Auto merge of #93741 - Mark-Simulacrum:global-job-id, r=cjgillot 2022-02-09 18:54:30 +00:00
rustc_query_system Auto merge of #93741 - Mark-Simulacrum:global-job-id, r=cjgillot 2022-02-09 18:54:30 +00:00
rustc_resolve
rustc_save_analysis
rustc_serialize Drop json::from_reader 2022-02-05 15:07:10 -05:00
rustc_session Auto merge of #93724 - Mark-Simulacrum:drop-query-stats, r=michaelwoerister 2022-02-09 15:53:10 +00:00
rustc_span Rollup merge of #91504 - cynecx:used_retain, r=nikic 2022-02-09 23:29:56 +01:00
rustc_symbol_mangling
rustc_target Auto merge of #93561 - Amanieu:more-unwind-abi, r=nagisa 2022-02-08 03:20:05 +00:00
rustc_trait_selection Allow substitutions in rustc_on_unimplemented predicate 2022-02-09 09:35:42 -08:00
rustc_traits
rustc_ty_utils
rustc_type_ir
rustc_typeck Rollup merge of #91504 - cynecx:used_retain, r=nikic 2022-02-09 23:29:56 +01:00