Skip to content

Chapter 3.3 Error in function declaration explanation #3003

Closed
rust-lang/rust
#96933

Description

  • I have checked the latest main branch to see if this has already been fixed
  • I have searched existing issues and pull requests for duplicates

URL to the section(s) of the book with this problem:

https://doc.rust-lang.org/book/ch03-03-how-functions-work.html

Description of the problem:

The current wording states:

Rust doesn’t care where you define your functions, only that they’re defined somewhere.

Which motivated me to try e.g. which does work:

fn main() {                                                                      
    a_function();                                                                
                                                                                 
    fn a_function() {                                                            
        println!("Hello, World!");                                               
    }                                                                            
} 

But something like:

fn main() {                                                                      
    a_function();                                                                
                                                                                 
    {                                                                            
        fn a_function() {                                                        
            println!("Hello, World!");                                           
        }                                                                        
    }                                                                            
} 

Doesn't compile because the function is not found in the scope.

I think this is a contradiction with the documentation.

Suggested fix:

Change the wording to maybe:

Rust doesn’t care where you define your functions, only that they’re defined somewhere in scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions