rust/proc-macro2/fallback.rs
Source file repositories/reference/linux-study-clean/rust/proc-macro2/fallback.rs
File Facts
- System
- Linux kernel
- Corpus path
rust/proc-macro2/fallback.rs- Extension
.rs- Size
- 34318 bytes
- Lines
- 1259
- Domain
- Rust Kernel Layer
- Bucket
- Rust API Membrane
- Inferred role
- Rust Kernel Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
Rust-side wrappers and abstractions around kernel C APIs, ownership contracts, allocation, synchronization, and module integration.
- Rust-side wrappers and abstractions around kernel C APIs, ownership contracts, allocation, synchronization, and module integration.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
struct FileInfostruct SourceMapfunction forcefunction unforcefunction push_token_from_proc_macrofunction push_negative_literalfunction dropfunction Somefunction Somefunction Somefunction lines_offsetsfunction pubfunction pubfunction validate_identfunction validate_ident_rawfunction Okfunction Somefunction letfunction pubfunction escape_utf8function Somefunction from_str_checked
Annotated Snippet
struct FileInfo {
source_text: String,
span: Span,
lines: Vec<usize>,
char_index_to_byte_offset: BTreeMap<usize, usize>,
}
#[cfg(all(span_locations, not(fuzzing)))]
impl FileInfo {
fn offset_line_column(&self, offset: usize) -> LineColumn {
assert!(self.span_within(Span {
lo: offset as u32,
hi: offset as u32,
}));
let offset = offset - self.span.lo as usize;
match self.lines.binary_search(&offset) {
Ok(found) => LineColumn {
line: found + 1,
column: 0,
},
Err(idx) => LineColumn {
line: idx,
column: offset - self.lines[idx - 1],
},
}
}
fn span_within(&self, span: Span) -> bool {
span.lo >= self.span.lo && span.hi <= self.span.hi
}
fn byte_range(&mut self, span: Span) -> Range<usize> {
let lo_char = (span.lo - self.span.lo) as usize;
// Look up offset of the largest already-computed char index that is
// less than or equal to the current requested one. We resume counting
// chars from that point.
let (&last_char_index, &last_byte_offset) = self
.char_index_to_byte_offset
.range(..=lo_char)
.next_back()
.unwrap_or((&0, &0));
let lo_byte = if last_char_index == lo_char {
last_byte_offset
} else {
let total_byte_offset = match self.source_text[last_byte_offset..]
.char_indices()
.nth(lo_char - last_char_index)
{
Some((additional_offset, _ch)) => last_byte_offset + additional_offset,
None => self.source_text.len(),
};
self.char_index_to_byte_offset
.insert(lo_char, total_byte_offset);
total_byte_offset
};
let trunc_lo = &self.source_text[lo_byte..];
let char_len = (span.hi - span.lo) as usize;
lo_byte..match trunc_lo.char_indices().nth(char_len) {
Some((offset, _ch)) => lo_byte + offset,
None => self.source_text.len(),
}
}
fn source_text(&mut self, span: Span) -> String {
let byte_range = self.byte_range(span);
self.source_text[byte_range].to_owned()
}
}
/// Computes the offsets of each line in the given source string
/// and the total number of characters
#[cfg(all(span_locations, not(fuzzing)))]
fn lines_offsets(s: &str) -> (usize, Vec<usize>) {
let mut lines = vec![0];
let mut total = 0;
for ch in s.chars() {
total += 1;
if ch == '\n' {
lines.push(total);
}
}
(total, lines)
}
#[cfg(all(span_locations, not(fuzzing)))]
Annotation
- Detected declarations: `struct FileInfo`, `struct SourceMap`, `function force`, `function unforce`, `function push_token_from_proc_macro`, `function push_negative_literal`, `function drop`, `function Some`, `function Some`, `function Some`.
- Atlas domain: Rust Kernel Layer / Rust API Membrane.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.