Theres an implicit assumption that the actions being offered an “undo” are semi-important/permanent.
In other words, if you delete an email and it goes to the trash folder: good use of toast + undo
If you empty the trash, and there is nowhere the user can go to unempty it: bad use of toast + undo
Its also useful as a sleight of hand eg when cancelling an action you havent yet taken (which actually is generally what a toast + undo actually is). The best example of this being toast + undo for an email send