ridx_format/format/notes.rs
1/*
2 * rust-intelligence — Ultra-fast, zero-memory code intelligence for Rust
3 * Copyright (c) 2026 Alexander Panasenko
4 *
5 * Contact: alex@prod.codes
6 * Author: https://prod.codes/about/
7 * Project: https://github.com/alex09x/rust-intelligence
8 * SPDX-License-Identifier: MIT OR Apache-2.0
9 */
10
11//! Notes: short texts the compiler knows about a source span that hover shows as they are (format version 4).
12
13use super::Span;
14
15/// The generic arguments of a call, at the callee's name: `` `T` = `String`, `A` = `Global` ``.
16pub const NOTE_CALL_ARGS: u32 = 1;
17/// The memory layout of a type, field, variant or binding, at its name: `size = 8, align = 0x8, no Drop`.
18pub const NOTE_LAYOUT: u32 = 2;
19
20/// A note record: the text a span carries, by kind.
21#[repr(C)]
22#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
23pub struct NoteEntry {
24 /// Source span the note belongs to (a name).
25 pub span: Span,
26 /// Offset in the string pool of the note's text.
27 pub text_offset: u32,
28 /// `NOTE_CALL_ARGS` or `NOTE_LAYOUT`.
29 pub kind: u32,
30}
31
32impl NoteEntry {
33 #[inline]
34 pub fn new(span: Span, text_offset: u32, kind: u32) -> Self {
35 Self { span, text_offset, kind }
36 }
37
38 #[inline]
39 pub fn to_le(self) -> Self {
40 Self { span: self.span.to_le(), text_offset: self.text_offset.to_le(), kind: self.kind.to_le() }
41 }
42
43 #[inline]
44 pub fn span(&self) -> Span {
45 self.span.from_le()
46 }
47
48 #[inline]
49 pub fn text_offset(&self) -> u32 {
50 u32::from_le(self.text_offset)
51 }
52
53 #[inline]
54 pub fn kind(&self) -> u32 {
55 u32::from_le(self.kind)
56 }
57}