Skip to content

Commit 69fee37

Browse files
authored
Merge pull request dtolnay#440 from dtolnay/example
Add example code for invalidate_current_thread_spans
2 parents 43011bf + 66a3ef0 commit 69fee37

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
strategy:
2525
fail-fast: false
2626
matrix:
27-
rust: [1.56.0, stable, beta]
27+
rust: [1.63.0, stable, beta]
2828
timeout-minutes: 45
2929
steps:
3030
- uses: actions/checkout@v4
@@ -78,6 +78,29 @@ jobs:
7878
env:
7979
RUSTFLAGS: -Z allow-features= --cfg procmacro2_backtrace ${{env.RUSTFLAGS}}
8080

81+
msrv:
82+
name: Rust 1.56.0
83+
needs: pre_ci
84+
if: needs.pre_ci.outputs.continue
85+
runs-on: ubuntu-latest
86+
timeout-minutes: 45
87+
steps:
88+
- uses: actions/checkout@v4
89+
- uses: dtolnay/[email protected]
90+
with:
91+
components: rust-src
92+
- run: cargo check
93+
- run: cargo check --no-default-features
94+
- run: cargo check --features span-locations
95+
- name: RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo check
96+
run: cargo check
97+
env:
98+
RUSTFLAGS: --cfg procmacro2_semver_exempt ${{env.RUSTFLAGS}}
99+
- name: RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo check --no-default-features
100+
run: cargo check --no-default-features
101+
env:
102+
RUSTFLAGS: --cfg procmacro2_semver_exempt ${{env.RUSTFLAGS}}
103+
81104
minimal:
82105
name: Minimal versions
83106
needs: pre_ci

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ features = ["span-locations"]
2424
unicode-ident = "1.0"
2525

2626
[dev-dependencies]
27+
flate2 = "1.0"
2728
quote = { version = "1.0", default_features = false }
29+
rayon = "1.0"
2830
rustversion = "1"
31+
tar = "0.4"
2932

3033
[features]
3134
proc-macro = []

src/extra.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,50 @@ use core::fmt::{self, Debug};
2020
/// gigabytes). After a wraparound, `Span` methods such as `source_text()` can
2121
/// return wrong data.
2222
///
23+
/// # Example
24+
///
25+
/// As of late 2023, there is 200 GB of Rust code published on crates.io.
26+
/// Looking at just the newest version of every crate, it is 16 GB of code. So a
27+
/// workload that involves parsing it all would overflow a 32-bit source
28+
/// location unless spans are being invalidated.
29+
///
30+
/// ```
31+
/// use flate2::read::GzDecoder;
32+
/// use std::ffi::OsStr;
33+
/// use std::io::{BufReader, Read};
34+
/// use std::str::FromStr;
35+
/// use tar::Archive;
36+
///
37+
/// rayon::scope(|s| {
38+
/// for krate in every_version_of_every_crate() {
39+
/// s.spawn(move |_| {
40+
/// proc_macro2::extra::invalidate_current_thread_spans();
41+
///
42+
/// let reader = BufReader::new(krate);
43+
/// let tar = GzDecoder::new(reader);
44+
/// let mut archive = Archive::new(tar);
45+
/// for entry in archive.entries().unwrap() {
46+
/// let mut entry = entry.unwrap();
47+
/// let path = entry.path().unwrap();
48+
/// if path.extension() != Some(OsStr::new("rs")) {
49+
/// continue;
50+
/// }
51+
/// let mut content = String::new();
52+
/// entry.read_to_string(&mut content).unwrap();
53+
/// match proc_macro2::TokenStream::from_str(&content) {
54+
/// Ok(tokens) => {/* ... */},
55+
/// Err(_) => continue,
56+
/// }
57+
/// }
58+
/// });
59+
/// }
60+
/// });
61+
/// #
62+
/// # fn every_version_of_every_crate() -> Vec<std::fs::File> {
63+
/// # Vec::new()
64+
/// # }
65+
/// ```
66+
///
2367
/// # Panics
2468
///
2569
/// This function is not applicable to and will panic if called from a

0 commit comments

Comments
 (0)