Remove unnecessary range replacements by nnethercote · Pull Request #128224 · rust-lang/rust (original) (raw)

Imagine you have replace ranges (2..20,X) and (5..15,Y), and these tokens:

a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x

If we replace (5..15,Y) first, then (2..20,X) we get this sequence

a,b,c,d,e,Y,_,_,_,_,_,_,_,_,_,p,q,r,s,t,u,v,w,x
a,b,X,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,u,v,w,x

which is what we want.

If we do it in the other order, we get this:

a,b,X,_,_,_,_,_,_,_,_,_,_,_,_,p,q,r,s,t,u,v,w,x
a,b,X,_,_,Y,_,_,_,_,_,_,_,_,_,_,_,_,_,_,u,v,w,x

which is wrong. So it's true that we need the .rev() but the comment is wrong about why.