In a p-n junction, when the junction is formed, free electrons from the n-type region diffuse into the p-type region, and holes from the p-type region diffuse into the n-type region. This movement creates a region called the depletion region where no free charge carriers exist.
As a result of this diffusion, an electric field is set up across the depletion region, which opposes further diffusion of charge carriers. This creates a state of equilibrium where the drift current (due to the electric field) exactly cancels out the diffusion current. Hence, no net current flows through the junction under equilibrium.