If the number of channels differ, the additional conv and batchnorm layers in shortcut will make sure that you can add the residual connection back to out.
On the other hand, if the channels match already, x will be directly added to out, since an empty nn.Sequential module will act as an identity:
seq = nn.Sequential()
x = torch.randn(1, 3, 24, 24)
out = seq(x)
print((out == x).all())
> tensor(True)

The torchvision implementation 2 uses a similar approach, but will skip the downsample layer, if it’s not needed.