@@ -20,6 +20,50 @@ use core::fmt::{self, Debug};
20
20
/// gigabytes). After a wraparound, `Span` methods such as `source_text()` can
21
21
/// return wrong data.
22
22
///
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
+ ///
23
67
/// # Panics
24
68
///
25
69
/// This function is not applicable to and will panic if called from a
0 commit comments