Skip to content

Commit

Permalink
Revert "Avoid nested replacement ranges" from rust-lang#129346.
Browse files Browse the repository at this point in the history
It caused a test regression in the `cfg_eval.rs` crate. (The bugfix
in rust-lang#129346 was in a different commit; this commit was just a code
simplification.)
  • Loading branch information
nnethercote committed Nov 4, 2024
1 parent e3a918e commit 7d1fe0d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
28 changes: 21 additions & 7 deletions compiler/rustc_parse/src/parser/attr_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,30 @@ impl ToAttrTokenStream for LazyAttrTokenStreamImpl {
node_replacements.array_windows()
{
assert!(
node_range.0.end <= next_node_range.0.start,
"Node ranges should be disjoint: ({:?}, {:?}) ({:?}, {:?})",
node_range.0.end <= next_node_range.0.start
|| node_range.0.end >= next_node_range.0.end,
"Node ranges should be disjoint or nested: ({:?}, {:?}) ({:?}, {:?})",
node_range,
tokens,
next_node_range,
next_tokens,
);
}

// Process the replace ranges.
for (node_range, target) in node_replacements.into_iter() {
// Process the replace ranges, starting from the highest start
// position and working our way back. If have tokens like:
//
// `#[cfg(FALSE)] struct Foo { #[cfg(FALSE)] field: bool }`
//
// Then we will generate replace ranges for both
// the `#[cfg(FALSE)] field: bool` and the entire
// `#[cfg(FALSE)] struct Foo { #[cfg(FALSE)] field: bool }`
//
// By starting processing from the replace range with the greatest
// start position, we ensure that any (outer) replace range which
// encloses another (inner) replace range will fully overwrite the
// inner range's replacement.
for (node_range, target) in node_replacements.into_iter().rev() {
assert!(
!node_range.0.is_empty(),
"Cannot replace an empty node range: {:?}",
Expand Down Expand Up @@ -383,9 +396,10 @@ impl<'a> Parser<'a> {
// from `ParserRange` form to `NodeRange` form. We will perform the actual
// replacement only when we convert the `LazyAttrTokenStream` to an
// `AttrTokenStream`.
self.capture_state
.parser_replacements
.drain(parser_replacements_start..parser_replacements_end)
self.capture_state.parser_replacements
[parser_replacements_start..parser_replacements_end]
.iter()
.cloned()
.chain(inner_attr_parser_replacements)
.map(|(parser_range, data)| {
(NodeRange::new(parser_range, collect_pos.start_pos), data)
Expand Down
2 changes: 1 addition & 1 deletion src/llvm-project
Submodule llvm-project updated 112 files
2 changes: 1 addition & 1 deletion src/tools/cargo
Submodule cargo updated 56 files
+149 −148 Cargo.lock
+2 −2 Cargo.toml
+34 −0 crates/cargo-test-support/src/compare.rs
+6 −6 crates/cargo-test-support/src/lib.rs
+2 −43 crates/cargo-util/src/paths.rs
+11 −5 crates/rustfix/tests/everything/dedup-suggestions.fixed.rs
+5 −323 crates/rustfix/tests/everything/dedup-suggestions.json
+11 −5 crates/rustfix/tests/everything/dedup-suggestions.rs
+1 −3 src/bin/cargo/commands/git_checkout.rs
+2 −5 src/bin/cargo/commands/read_manifest.rs
+4 −9 src/bin/cargo/commands/verify_project.rs
+5 −0 src/cargo/core/compiler/build_config.rs
+26 −64 src/cargo/core/compiler/custom_build.rs
+0 −758 src/cargo/core/compiler/fingerprint/dep_info.rs
+571 −14 src/cargo/core/compiler/fingerprint/mod.rs
+21 −30 src/cargo/core/compiler/job_queue/mod.rs
+0 −3 src/cargo/core/features.rs
+14 −39 src/cargo/core/package.rs
+7 −21 src/cargo/ops/registry/publish.rs
+1 −8 src/cargo/util/rustc.rs
+3 −9 src/cargo/util/workspace.rs
+0 −3 src/doc/book.toml
+58 −0 src/doc/man/cargo-verify-project.md
+3 −0 src/doc/man/cargo.md
+137 −0 src/doc/man/generated_txt/cargo-verify-project.txt
+3 −0 src/doc/man/generated_txt/cargo.txt
+1 −1 src/doc/src/SUMMARY.md
+154 −0 src/doc/src/commands/cargo-verify-project.md
+3 −0 src/doc/src/commands/cargo.md
+0 −10 src/doc/src/commands/deprecated-and-removed.md
+0 −1 src/doc/src/commands/index.md
+1 −0 src/doc/src/commands/manifest-commands.md
+2 −17 src/doc/src/reference/build-scripts.md
+1 −3 src/doc/src/reference/resolver.md
+5 −8 src/doc/src/reference/unstable.md
+8 −0 src/etc/_cargo
+2 −0 src/etc/cargo.bashcomp.sh
+178 −0 src/etc/man/cargo-verify-project.1
+4 −0 src/etc/man/cargo.1
+0 −60 tests/build-std/main.rs
+8 −17 tests/testsuite/artifact_dep.rs
+6 −244 tests/testsuite/build_script.rs
+12 −14 tests/testsuite/cargo/z_help/stdout.term.svg
+1 −1 tests/testsuite/cargo_command.rs
+2 −2 tests/testsuite/cargo_read_manifest/help/stdout.term.svg
+18 −18 tests/testsuite/cargo_verify_project/help/stdout.term.svg
+0 −80 tests/testsuite/directory.rs
+1 −2 tests/testsuite/doc.rs
+24 −30 tests/testsuite/fix.rs
+0 −4 tests/testsuite/mock-std/dep_test/Cargo.toml
+0 −1 tests/testsuite/mock-std/dep_test/src/lib.rs
+0 −1 tests/testsuite/mock-std/library/std/Cargo.toml
+0 −19 tests/testsuite/publish.rs
+28 −14 tests/testsuite/rust_version.rs
+0 −67 tests/testsuite/standard_lib.rs
+14 −25 tests/testsuite/warn_on_failure.rs

0 comments on commit 7d1fe0d

Please sign in to comment.