It's safe driving. If a car emergency braking would cause you to go into the back of it you're driving dangerously.
same with suddenly stopping self-driving bus in lane dedicated ONLY for trams and buses where trams have priority anyway, tram is pretty much never at fault, because it has right of way
> If I have to slam the brakes on to avoid hitting a pedestrian
In that case you will not be at fault.
> in lane dedicated ONLY for trams and buses where trams have priority anyway
I’m not sure about Swedish road rules, but I don’t see any note about it being a dedicated lane