Skip to content

Commit 6e87858

Browse files
committed
Fix a comment.
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.
1 parent a560810 commit 6e87858

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

compiler/rustc_parse/src/parser/attr_wrapper.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ impl ToAttrTokenStream for LazyAttrTokenStreamImpl {
137137
// `#[cfg(FALSE)] struct Foo { #[cfg(FALSE)] field: bool }`
138138
//
139139
// By starting processing from the replace range with the greatest
140-
// start position, we ensure that any replace range which encloses
141-
// another replace range will capture the *replaced* tokens for the inner
142-
// range, not the original tokens.
140+
// start position, we ensure that any (outer) replace range which
141+
// encloses another (inner) replace range will fully overwrite the
142+
// inner range's replacement.
143143
for (range, target) in replace_ranges.into_iter().rev() {
144144
assert!(!range.is_empty(), "Cannot replace an empty range: {range:?}");
145145

0 commit comments

Comments
 (0)