Variable shadowing -- strange wording in official Rust book

In the last four weeks I read 75% of the book, and I think it is quite good. As a non native speaker I had a few problems with some explanations. I think the most serious one is the use of the term "shadowed" as in

pub fn search_case_insensitive<'a>(
    query: &str,
    contents: &'a str,
) -> Vec<&'a str> {
    let query = query.to_lowercase();
    let mut results = Vec::new();

    for line in contents.lines() {
        if line.to_lowercase().contains(&query) {


" First, we lowercase the query string and store it in a shadowed variable with the same name."

My issue here is the phrase "shadowed" -- my feeling is, that it is used differently than in the other books I read before (C, C++, Wikipedia...). And it is used in the Rust book a few times in exactly this way, so I think is it not a typo. In my feeling as a non native speaker the explanation sentence should be

"First, we lowercase the query string and store it in a new variable which shadows the old variable with the same name."

GPT-4 seems to agree: Shadowing in Rust code.

Would it make sense to report tiny issues like this one to the GitHub issue tracker of the book, or may the authors have already retired or are not seriously interested in minor issues?

Best regards,

Stefan Salewski


I agree it's a shadowing variable and the one you can no longer use is shadowed.

I imagine a PR to correct this would be accepted.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.