2,424 matches across 25 files for func main lang:Markdown lang:Markdown
snippet_mode: auto · sorted by relevance
compiler/rustc_error_codes/src/error_codes/E0131.md MARKDOWN 3 matches view file →
1The `main` function was defined with generic parameters.
2
3Erroneous code example:
· · ·
4
5```compile_fail,E0131
6fn main<T>() { // error: main function is not allowed to have generic parameters
7}
8```
· · ·
9
10It is not possible to define the `main` function with generic parameters.
11It must not take any arguments.
12
compiler/rustc_error_codes/src/error_codes/E0646.md MARKDOWN 2 matches view file →
1It is not possible to define `main` with a where clause.
2
3Erroneous code example:
· · ·
4
5```compile_fail,E0646
6fn main() where i32: Copy { // error: main function is not allowed to have
7 // a where clause
8}
compiler/rustc_error_codes/src/error_codes/E0601.md MARKDOWN 3 matches view file →
1No `main` function was found in a binary crate.
2
3To fix this error, add a `main` function:
· · ·
3To fix this error, add a `main` function:
4
5```
· · ·
6fn main() {
7 // Your program will start here.
8 println!("Hello world!");
compiler/rustc_error_codes/src/error_codes/E0136.md MARKDOWN 4 matches view file →
1#### Note: this error code is no longer emitted by the compiler.
2
3More than one `main` function was found.
4
5Erroneous code example:
· · ·
6
7```compile_fail
8fn main() {
9 // ...
10}
· · ·
12// ...
13
14fn 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
compiler/rustc_error_codes/src/error_codes/E0580.md MARKDOWN 4 matches view file →
1The `main` function was incorrectly declared.
2
3Erroneous code example:
· · ·
4
5```compile_fail,E0580
6fn main(x: i32) { // error: main function has wrong type
7 println!("{}", x);
8}
· · ·
9```
10
11The `main` function prototype should never take arguments.
12Example:
13
· · ·
14```
15fn main() {
16 // your code
17}
compiler/rustc_error_codes/src/error_codes/E0137.md MARKDOWN 9 matches · showing 5 view file →
1#### Note: this error code is no longer emitted by the compiler.
2
3More 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```
· · ·
14fn f() {} // error: multiple functions with a `#[main]` attribute
15```
16
+ 4 more matches in this file
compiler/rustc_error_codes/src/error_codes/E0572.md MARKDOWN 5 matches view file →
1A return statement was found outside of a function body.
2
3Erroneous code example:
· · ·
4
5```compile_fail,E0572
6const FOO: u32 = return 0; // error: return statement outside of function body
7
8fn main() {}
· · ·
8fn main() {}
9```
10
· · ·
11To fix this issue, just remove the return keyword or move the expression into a
12function. Example:
13
14```
· · ·
19}
20
21fn main() {
22 some_fn();
23}
compiler/rustc_error_codes/src/error_codes/E0712.md MARKDOWN 4 matches view file →
1A borrow of a thread-local variable was made inside a function which outlived
2the lifetime of the function.
3
· · ·
2the lifetime of the function.
3
4Erroneous code example:
· · ·
10static FOO: u8 = 3;
11
12fn 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 || {
compiler/rustc_error_codes/src/error_codes/E0799.md MARKDOWN 4 matches view file →
5
6```compile_fail,E0799
7fn bad1() -> impl Sized + use<main> {}
8
9fn bad2(x: ()) -> impl Sized + use<x> {}
· · ·
10
11fn main() {}
12```
13
· · ·
14In 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.
· · ·
16a function argument rather than a type or const parameter.
17
18Only type and const parameters, including `Self`, may be captured by
compiler/rustc_error_codes/src/error_codes/E0093.md MARKDOWN 5 matches view file →
1An unknown intrinsic function was declared.
2
3Erroneous code example:
· · ·
8
9#[rustc_intrinsic]
10unsafe fn foo(); // error: unrecognized intrinsic function: `foo`
11
12fn main() {
· · ·
12fn main() {
13 unsafe {
14 foo();
· · ·
17```
18
19Please 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
· · ·
20functions are defined in `library/core/src/intrinsics` in the Rust source code.
21
compiler/rustc_error_codes/src/error_codes/E0752.md MARKDOWN 3 matches view file →
4
5```compile_fail,E0752
6async 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```
16fn main() -> Result<(), ()> { // ok!
17 Ok(())
18}
compiler/rustc_error_codes/src/error_codes/E0562.md MARKDOWN 5 matches view file →
1`impl Trait` is only allowed as a function return and argument type.
2
3Erroneous code example:
· · ·
4
5```compile_fail,E0562
6fn 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
16Make sure `impl Trait` appears in a function signature.
17
18```
· · ·
21}
22
23fn main() {
24 for i in count_to_n(10) { // ok!
25 println!("{}", i);
compiler/rustc_error_codes/src/error_codes/E0585.md MARKDOWN 3 matches view file →
4
5```compile_fail,E0585
6fn main() {
7 // The following doc comment will fail:
8 /// This is a useless doc comment!
· · ·
10```
11
12Documentation 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```
compiler/rustc_error_codes/src/error_codes/E0089.md MARKDOWN 4 matches view file →
1#### Note: this error code is no longer emitted by the compiler.
2
3Too few type arguments were supplied for a function. For example:
4
5```compile_fail,E0107
· · ·
6fn foo<T, U>() {}
7
8fn main() {
9 foo::<f64>(); // error: wrong number of type arguments: expected 2, found 1
10}
· · ·
11```
12
13Note 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
19fn main() {
20 let x: bool = true;
21 foo::<f64>(x); // error: wrong number of type arguments:
compiler/rustc_error_codes/src/error_codes/E0622.md MARKDOWN 6 matches · showing 5 view file →
1#### Note: this error code is no longer emitted by the compiler.
2
3An 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
· · ·
17fn main() { unsafe { atomic_singlethreadfence_seqcst(); } }
18```
19
· · ·
20An 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:
· · ·
22error, just declare a function. Example:
23
24```ignore (no longer emitted)
+ 1 more matches in this file
compiler/rustc_error_codes/src/error_codes/E0755.md MARKDOWN 4 matches view file →
1#### Note: this error code is no longer emitted by the compiler.
2
3The `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
· · ·
15The `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
compiler/rustc_driver_impl/README.md MARKDOWN 2 matches view file →
1The `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
· · ·
4not contain any of the "main logic" of the compiler (though it does
5have some code related to pretty printing or other minor compiler
6options).
compiler/rustc_error_codes/src/error_codes/E0756.md MARKDOWN 4 matches view file →
1#### Note: this error code is no longer emitted by the compiler.
2
3The `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
· · ·
16The `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
compiler/rustc_error_codes/src/error_codes/E0775.md MARKDOWN 3 matches view file →
9#![feature(cmse_nonsecure_entry)]
10
11pub 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
compiler/rustc_error_codes/src/error_codes/E0087.md MARKDOWN 2 matches view file →
1#### Note: this error code is no longer emitted by the compiler.
2
3Too many type arguments were supplied for a function. For example:
4
5```compile_fail,E0107
· · ·
6fn foo<T>() {}
7
8fn main() {
9 foo::<f64, bool>(); // error: wrong number of type arguments:
10 // expected 1, found 2
compiler/rustc_error_codes/src/error_codes/E0211.md MARKDOWN 6 matches · showing 5 view file →
1#### Note: this error code is no longer emitted by the compiler.
2
3You used a function or type which doesn't fit the requirements for where it was
4used. Erroneous code examples:
5
· · ·
13// or:
14
15fn 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
39For the first code example, please check the function definition. Example:
40
41```
· · ·
47```
48
49The second case example is a bit particular: the main function must always
50have this definition:
51
+ 1 more matches in this file
compiler/rustc_error_codes/src/error_codes/E0133.md MARKDOWN 8 matches · showing 5 view file →
6unsafe fn f() { return; } // This is the unsafe code
7
8fn 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
13Using 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
src/doc/unstable-book/src/language-features/unboxed-closures.md MARKDOWN 3 matches view file →
9----
10
11The `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.
· · ·
12required 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
24fn main() {}
25```
26
compiler/rustc_error_codes/src/error_codes/E0659.md MARKDOWN 4 matches view file →
17}
18
19fn 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
25a 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.
· · ·
27functions collide.
28
29To solve this error, the best solution is generally to keep the path before the
· · ·
44}
45
46fn main() {
47 crate::collider::moon::foo(); // ok!
48 crate::collider::earth::foo(); // ok!
compiler/rustc_error_codes/src/error_codes/E0764.md MARKDOWN 5 matches view file →
4
5```compile_fail,E0764
6fn main() {
7 const OH_NO: &'static mut usize = &mut 1; // error!
8}
· · ·
9```
10
11Mutable 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
23Remember: you cannot use a function call inside a constant or static. However,
24you can totally use it in constant functions:
25
· · ·
24you can totally use it in constant functions:
25
26```
· · ·
32}
33
34fn main() {
35 const FOO: usize = foo(10); // ok!
36}
Search syntax
auth loginboth terms (AND is implicit)
auth OR logineither term
NOT path:vendorexclude matches
"exact phrase"quoted exact match
/func\s+Test/regex
handler~1fuzzy (Levenshtein 1)
file:*_test.gofilename glob
path:pkg/auth/**full path glob
lang:golanguage 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.