2,424 matches across 25 files for func main lang:Markdown lang:Markdown lang:Markdown
snippet_mode: auto · sorted by relevance
1▶The `main` function was defined with generic parameters.
2
3Erroneous code example:
· · ·
4
5```compile_fail,E0131
6▶fn main<T>() { // error: main function is not allowed to have generic parameters
7}
8```
· · ·
9
10▶It is not possible to define the `main` function with generic parameters.
11It must not take any arguments.
12
1▶It is not possible to define `main` with a where clause.
2
3Erroneous code example:
· · ·
4
5```compile_fail,E0646
6▶fn main() where i32: Copy { // error: main function is not allowed to have
7 // a where clause
8}
1▶No `main` function was found in a binary crate.
2
3To fix this error, add a `main` function:
· · ·
3▶To fix this error, add a `main` function:
4
5```
· · ·
6▶fn main() {
7 // Your program will start here.
8 println!("Hello world!");
1#### Note: this error code is no longer emitted by the compiler.
2
3▶More than one `main` function was found.
4
5Erroneous code example:
· · ·
6
7```compile_fail
8▶fn main() {
9 // ...
10}
· · ·
12// ...
13
14▶fn main() { // error!
15 // ...
16}
· · ·
18
19A binary can only have one entry point, and by default that entry point is the
20▶`main()` function. If there are multiple instances of this function, please
21rename one of them.
22
1▶The `main` function was incorrectly declared.
2
3Erroneous code example:
· · ·
4
5```compile_fail,E0580
6▶fn main(x: i32) { // error: main function has wrong type
7 println!("{}", x);
8}
· · ·
9```
10
11▶The `main` function prototype should never take arguments.
12Example:
13
· · ·
14```
15▶fn main() {
16 // your code
17}
1#### Note: this error code is no longer emitted by the compiler.
2
3▶More than one function was declared with the `#[main]` attribute.
4
5Erroneous code example:
· · ·
6
7```compile_fail
8▶#![feature(main)]
9
10#[main]
· · ·
10▶#[main]
11fn foo() {}
12
· · ·
13▶#[main]
14fn f() {} // error: multiple functions with a `#[main]` attribute
15```
· · ·
14▶fn f() {} // error: multiple functions with a `#[main]` attribute
15```
16
+ 4 more matches in this file
1▶A return statement was found outside of a function body.
2
3Erroneous code example:
· · ·
4
5```compile_fail,E0572
6▶const FOO: u32 = return 0; // error: return statement outside of function body
7
8fn main() {}
· · ·
· · ·
11To fix this issue, just remove the return keyword or move the expression into a
12▶function. Example:
13
14```
· · ·
19}
20
21▶fn main() {
22 some_fn();
23}
1▶A borrow of a thread-local variable was made inside a function which outlived
2the lifetime of the function.
3
· · ·
2▶the lifetime of the function.
3
4Erroneous code example:
· · ·
10static FOO: u8 = 3;
11
12▶fn main() {
13 let a = &FOO; // error: thread-local variable borrowed past end of function
14
· · ·
13▶ let a = &FOO; // error: thread-local variable borrowed past end of function
14
15 std::thread::spawn(move || {
5
6```compile_fail,E0799
7▶fn bad1() -> impl Sized + use<main> {}
8
9fn bad2(x: ()) -> impl Sized + use<x> {}
· · ·
10
11▶fn main() {}
12```
13
· · ·
14▶In the given examples, for `bad1`, the name `main` corresponds to a function
15rather than a type or const parameter. In `bad2`, the name `x` corresponds to
16a function argument rather than a type or const parameter.
· · ·
16▶a function argument rather than a type or const parameter.
17
18Only type and const parameters, including `Self`, may be captured by
1▶An unknown intrinsic function was declared.
2
3Erroneous code example:
· · ·
8
9#[rustc_intrinsic]
10▶unsafe fn foo(); // error: unrecognized intrinsic function: `foo`
11
12fn main() {
· · ·
12▶fn main() {
13 unsafe {
14 foo();
· · ·
17```
18
19▶Please check you didn't make a mistake in the function's name. All intrinsic
20functions are defined in `library/core/src/intrinsics` in the Rust source code.
21
· · ·
20▶functions are defined in `library/core/src/intrinsics` in the Rust source code.
21
4
5```compile_fail,E0752
6▶async fn main() -> Result<(), ()> { // error!
7 Ok(())
8}
· · ·
9```
10
11▶`fn main()` or the specified start function is not allowed to be `async`. Not
12having a correct async runtime library setup may cause this error. To fix it,
13declare the entry point without `async`:
· · ·
14
15```
16▶fn main() -> Result<(), ()> { // ok!
17 Ok(())
18}
1▶`impl Trait` is only allowed as a function return and argument type.
2
3Erroneous code example:
· · ·
4
5```compile_fail,E0562
6▶fn main() {
7 let count_to_ten: impl Iterator<Item=usize> = 0..10;
8 // error: `impl Trait` not allowed outside of function and inherent method
· · ·
8▶ // error: `impl Trait` not allowed outside of function and inherent method
9 // return types
10 for i in count_to_ten {
· · ·
14```
15
16▶Make sure `impl Trait` appears in a function signature.
17
18```
· · ·
21}
22
23▶fn main() {
24 for i in count_to_n(10) { // ok!
25 println!("{}", i);
4
5```compile_fail,E0585
6▶fn main() {
7 // The following doc comment will fail:
8 /// This is a useless doc comment!
· · ·
10```
11
12▶Documentation comments need to be followed by items, including functions,
13types, modules, etc. Examples:
14
· · ·
17struct Foo;
18
19▶/// I'm documenting the following function:
20fn foo() {}
21```
1#### Note: this error code is no longer emitted by the compiler.
2
3▶Too few type arguments were supplied for a function. For example:
4
5```compile_fail,E0107
· · ·
6fn foo<T, U>() {}
7
8▶fn main() {
9 foo::<f64>(); // error: wrong number of type arguments: expected 2, found 1
10}
· · ·
11```
12
13▶Note that if a function takes multiple type arguments but you want the compiler
14to infer some of them, you can use type placeholders:
15
· · ·
17fn foo<T, U>(x: T) {}
18
19▶fn main() {
20 let x: bool = true;
21 foo::<f64>(x); // error: wrong number of type arguments:
1#### Note: this error code is no longer emitted by the compiler.
2
3▶An intrinsic was declared without being a function.
4
5Erroneous code example:
· · ·
12 #[rustc_intrinsic]
13 pub static atomic_singlethreadfence_seqcst: unsafe fn();
14▶ // error: intrinsic must be a function
15}
16
· · ·
17▶fn main() { unsafe { atomic_singlethreadfence_seqcst(); } }
18```
19
· · ·
20▶An intrinsic is a function available for use in a given programming language
21whose implementation is handled specially by the compiler. In order to fix this
22error, just declare a function. Example:
· · ·
22▶error, just declare a function. Example:
23
24```ignore (no longer emitted)
+ 1 more matches in this file
1#### Note: this error code is no longer emitted by the compiler.
2
3▶The `ffi_pure` attribute was used on a non-foreign function.
4
5Erroneous code example:
· · ·
10#[unsafe(ffi_pure)] // error!
11pub fn foo() {}
12▶# fn main() {}
13```
14
· · ·
15▶The `ffi_pure` attribute can only be used on foreign functions which do not have
16side effects or infinite loops:
17
· · ·
23 pub fn strlen(s: *const i8) -> isize;
24}
25▶# fn main() {}
26```
27
1▶The `driver` crate is effectively the "main" function for the rust
2compiler. It orchestrates the compilation process and "knits together"
3the code from the other crates within rustc. This crate itself does
· · ·
4▶not contain any of the "main logic" of the compiler (though it does
5have some code related to pretty printing or other minor compiler
6options).
1#### Note: this error code is no longer emitted by the compiler.
2
3▶The `ffi_const` attribute was used on something other than a foreign function
4declaration.
5
· · ·
11#[unsafe(ffi_const)] // error!
12pub fn foo() {}
13▶# fn main() {}
14```
15
· · ·
16▶The `ffi_const` attribute can only be used on foreign function declarations
17which have no side effects except for their return value:
18
· · ·
24 pub fn strlen(s: *const i8) -> i32;
25}
26▶# fn main() {}
27```
28
9#![feature(cmse_nonsecure_entry)]
10
11▶pub extern "cmse-nonsecure-entry" fn entry_function() {}
12```
13
· · ·
14To fix this error, compile your code for a Rust target that supports the
15TrustZone-M extension. The current possible targets are:
16▶* `thumbv8m.main-none-eabi`
17* `thumbv8m.main-none-eabihf`
18* `thumbv8m.base-none-eabi`
· · ·
17▶* `thumbv8m.main-none-eabihf`
18* `thumbv8m.base-none-eabi`
19
1#### Note: this error code is no longer emitted by the compiler.
2
3▶Too many type arguments were supplied for a function. For example:
4
5```compile_fail,E0107
· · ·
6fn foo<T>() {}
7
8▶fn main() {
9 foo::<f64, bool>(); // error: wrong number of type arguments:
10 // expected 1, found 2
1#### Note: this error code is no longer emitted by the compiler.
2
3▶You used a function or type which doesn't fit the requirements for where it was
4used. Erroneous code examples:
5
· · ·
13// or:
14
15▶fn main() -> i32 { 0 }
16// error: main function expects type: `fn() {main}`: expected (), found i32
17
· · ·
16▶// error: main function expects type: `fn() {main}`: expected (), found i32
17
18// or:
· · ·
37```
38
39▶For the first code example, please check the function definition. Example:
40
41```
· · ·
47```
48
49▶The second case example is a bit particular: the main function must always
50have this definition:
51
+ 1 more matches in this file
6unsafe fn f() { return; } // This is the unsafe code
7
8▶fn main() {
9 f(); // error: call to unsafe function requires unsafe function or block
10}
· · ·
9▶ f(); // error: call to unsafe function requires unsafe function or block
10}
11```
· · ·
12
13▶Using unsafe functionality is potentially dangerous and disallowed by safety
14checks. Examples:
15
· · ·
16* Dereferencing raw pointers
17▶* Calling functions via FFI
18* Calling functions marked unsafe
19
· · ·
18▶* Calling functions marked unsafe
19
20These safety checks can be relaxed for a section of the code by wrapping the
+ 3 more matches in this file
9----
10
11▶The `unboxed_closures` feature allows you to write functions using the `"rust-call"` ABI,
12required for implementing the [`Fn*`] family of traits. `"rust-call"` functions must have
13exactly one (non self) argument, a tuple representing the argument list.
· · ·
12▶required for implementing the [`Fn*`] family of traits. `"rust-call"` functions must have
13exactly one (non self) argument, a tuple representing the argument list.
14
· · ·
22}
23
24▶fn main() {}
25```
26
17}
18
19▶fn main() {
20 crate::collider::foo(); // ERROR: `foo` is ambiguous
21}
· · ·
23
24This error generally appears when two items with the same name are imported into
25▶a module. Here, the `foo` functions are imported and reexported from the
26`collider` module and therefore, when we're using `collider::foo()`, both
27functions collide.
· · ·
27▶functions collide.
28
29To solve this error, the best solution is generally to keep the path before the
· · ·
44}
45
46▶fn main() {
47 crate::collider::moon::foo(); // ok!
48 crate::collider::earth::foo(); // ok!
4
5```compile_fail,E0764
6▶fn main() {
7 const OH_NO: &'static mut usize = &mut 1; // error!
8}
· · ·
9```
10
11▶Mutable references (`&mut`) can only be used in constant functions, not statics
12or constants. This limitation exists to prevent the creation of constants that
13have a mutable reference in their final value. If you had a constant of
· · ·
21references.
22
23▶Remember: you cannot use a function call inside a constant or static. However,
24you can totally use it in constant functions:
25
· · ·
24▶you can totally use it in constant functions:
25
26```
· · ·
32}
33
34▶fn main() {
35 const FOO: usize = foo(10); // ok!
36}
Search syntax
auth login | both terms (AND is implicit) |
auth OR login | either term |
NOT path:vendor | exclude matches |
"exact phrase" | quoted exact match |
/func\s+Test/ | regex |
handler~1 | fuzzy (Levenshtein 1) |
file:*_test.go | filename glob |
path:pkg/auth/** | full path glob |
lang:go | language filter |
Search any public repo from your terminal
This page calls POST /api/v1/code_search. Same tool, available over MCP for Claude/Cursor/Copilot.