What is the purpose of this line?

I am making an editor script. In the documention of PopUpWindow I saw an example like this:

Rect buttonRect;
void OnGUI()
{
     
     GUILayout.Label("Editor window with Popup example", EditorStyles.boldLabel);
        if (GUILayout.Button("Popup Options", GUILayout.Width(200)))
        {
            PopupWindow.Show(buttonRect, new PopupExample());
        }
        // This line is the one I don't understand
        if (Event.current.type == EventType.Repaint) buttonRect = GUILayoutUtility.GetLastRect();
    }
}

So the line:

 if (Event.current.type == EventType.Repaint) buttonRect = GUILayoutUtility.GetLastRect();

Why is it being used? What is it doing?

OnGUI can be called multiple times per frame for things like layout, actual rendering, etc. That line is checking to see if OnGUI is being called to repaint and only setting buttonRect on that event. Refer to the EventType documentation for the meanings of the events.