Skip to content

Book 4.1 should mention that shadowing does not destroy the original value. #33887

Closed
@MichaelNecio

Description

@MichaelNecio

In reading about shadowing I was curious if shadowing a binding within the same scope would cause a destructor to be called, which I did eventually find is not the case https://www.reddit.com/r/rust/comments/2eelew/unexpected_for_me_behavior/?ref=share&ref_source=link, but perhaps this should be mentioned in the book to prevent incorrect assumptions from being formed (it's happened at least once).

There is currently an example of a binding being shadowed in a new scope and then the old value being used again, but I don't think this is enough for people to make the connection that shadowing never destroys a value ( they could think that the compiler keeps track of whether or not a binding is used again in the same scope ).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions