Debian Codegraph @

debian/patches/annotate-snippets-0.12

raw
1 Description: Port to annotate-snippets 0.12
2 Author: Simon Quigley <[email protected]>
3 Origin: vendor
4 Forwarded: not-needed
5 Last-Update: 2026-08-18
6 ---
7 --- a/Cargo.toml
8 +++ b/Cargo.toml
9 @@ -88,7 +88,7 @@ name = "bindgen"
10 path = "lib.rs"
11
12 [dependencies.annotate-snippets]
13 -version = "0.11.4"
14 +version = "0.12"
15 optional = true
16
17 [dependencies.bitflags]
18 --- a/codegen/mod.rs
19 +++ b/codegen/mod.rs
20 @@ -4861,18 +4861,18 @@ fn unsupported_abi_diagnostic(
21 "Skipping {}function `{fn_name}` because the {error}",
22 if variadic { "variadic " } else { "" },
23 ),
24 - Level::Warning,
25 + Level::WARNING,
26 )
27 .add_annotation(
28 "No code will be generated for this function.",
29 - Level::Warning,
30 + Level::WARNING,
31 )
32 .add_annotation(
33 format!(
34 "The configured Rust version is {}.",
35 ctx.options().rust_target
36 ),
37 - Level::Note,
38 + Level::NOTE,
39 );
40
41 if let Some(loc) = location {
42 @@ -4908,9 +4908,9 @@ fn variadic_fn_diagnostic(
43
44 let mut diag = Diagnostic::default();
45
46 - diag.with_title(format!("Cannot generate wrapper for the static function `{fn_name}`."), Level::Warning)
47 - .add_annotation("The `--wrap-static-fns` feature does not support variadic functions.", Level::Note)
48 - .add_annotation("No code will be generated for this function.", Level::Note);
49 + diag.with_title(format!("Cannot generate wrapper for the static function `{fn_name}`."), Level::WARNING)
50 + .add_annotation("The `--wrap-static-fns` feature does not support variadic functions.", Level::NOTE)
51 + .add_annotation("No code will be generated for this function.", Level::NOTE);
52
53 if let Some(loc) = _location {
54 let (file, line, col, _) = loc.location();
55 --- a/diagnostics.rs
56 +++ b/diagnostics.rs
57 @@ -6,16 +6,16 @@ use std::fmt::Write;
58 use std::io::{self, BufRead, BufReader};
59 use std::{borrow::Cow, fs::File};
60
61 -use annotate_snippets::{Renderer, Snippet};
62 +use annotate_snippets::{Annotation, Group, Renderer, Snippet};
63
64 pub(crate) use annotate_snippets::Level;
65
66 /// A `bindgen` diagnostic.
67 #[derive(Default)]
68 pub(crate) struct Diagnostic<'a> {
69 - title: Option<(Cow<'a, str>, Level)>,
70 + title: Option<(Cow<'a, str>, Level<'static>)>,
71 slices: Vec<Slice<'a>>,
72 - footer: Vec<(Cow<'a, str>, Level)>,
73 + footer: Vec<(Cow<'a, str>, Level<'static>)>,
74 }
75
76 impl<'a> Diagnostic<'a> {
77 @@ -23,7 +23,7 @@ impl<'a> Diagnostic<'a> {
78 pub(crate) fn with_title(
79 &mut self,
80 title: impl Into<Cow<'a, str>>,
81 - level: Level,
82 + level: Level<'static>,
83 ) -> &mut Self {
84 self.title = Some((title.into(), level));
85 self
86 @@ -39,7 +39,7 @@ impl<'a> Diagnostic<'a> {
87 pub(crate) fn add_annotation(
88 &mut self,
89 msg: impl Into<Cow<'a, str>>,
90 - level: Level,
91 + level: Level<'static>,
92 ) -> &mut Self {
93 self.footer.push((msg.into(), level));
94 self
95 @@ -54,37 +54,32 @@ impl<'a> Diagnostic<'a> {
96 static INVOKED_BY_BUILD_SCRIPT: bool = std::env::var_os("CARGO_CFG_TARGET_ARCH").is_some();
97 }
98
99 - let mut footer = vec![];
100 - let mut slices = vec![];
101 - let snippet = if let Some((msg, level)) = &self.title {
102 - (*level).title(msg)
103 - } else {
104 + let Some((msg, level)) = &self.title else {
105 return;
106 };
107
108 - for (msg, level) in &self.footer {
109 - footer.push((*level).title(msg));
110 - }
111 -
112 - // add additional info that this is generated by bindgen
113 - // so as to not confuse with rustc warnings
114 - footer.push(
115 - Level::Info.title("This diagnostic was generated by bindgen."),
116 - );
117 + let mut group = Group::with_title(level.clone().primary_title(msg.as_ref()));
118
119 for slice in &self.slices {
120 if let Some(source) = &slice.source {
121 - let mut snippet = Snippet::source(source)
122 + let mut snippet = Snippet::<Annotation>::source(source.as_ref())
123 .line_start(slice.line.unwrap_or_default());
124 if let Some(origin) = &slice.filename {
125 - snippet = snippet.origin(origin);
126 + snippet = snippet.path(origin.as_str());
127 }
128 - slices.push(snippet);
129 + group = group.element(snippet);
130 }
131 }
132
133 + for (msg, level) in &self.footer {
134 + group = group.element(level.clone().message(msg.as_ref()));
135 + }
136 + // add additional info that this is generated by bindgen
137 + // so as to not confuse with rustc warnings
138 + group = group.element(Level::INFO.message("This diagnostic was generated by bindgen."));
139 +
140 let renderer = Renderer::styled();
141 - let dl = renderer.render(snippet.snippets(slices).footers(footer));
142 + let dl = renderer.render(std::slice::from_ref(&group));
143
144 if INVOKED_BY_BUILD_SCRIPT.with(Clone::clone) {
145 // This is just a hack which hides the `warning:` added by cargo at the beginning of
146 --- a/ir/context.rs
147 +++ b/ir/context.rs
148 @@ -3096,11 +3096,11 @@ fn unused_regex_diagnostic(item: &str, n
149 Diagnostic::default()
150 .with_title(
151 format!("Unused regular expression: `{item}`."),
152 - Level::Warning,
153 + Level::WARNING,
154 )
155 .add_annotation(
156 format!("This regular expression was passed to `{name}`."),
157 - Level::Note,
158 + Level::NOTE,
159 )
160 .display();
161 }
162 --- a/ir/var.rs
163 +++ b/ir/var.rs
164 @@ -515,9 +515,9 @@ fn duplicated_macro_diagnostic(
165 slice.with_source(source);
166
167 Diagnostic::default()
168 - .with_title("Duplicated macro definition.", Level::Warning)
169 + .with_title("Duplicated macro definition.", Level::WARNING)
170 .add_slice(slice)
171 - .add_annotation("This macro had a duplicate.", Level::Note)
172 + .add_annotation("This macro had a duplicate.", Level::NOTE)
173 .display();
174 }
175 }
176 --- a/lib.rs
177 +++ b/lib.rs
178 @@ -1102,10 +1102,10 @@ fn rustfmt_non_fatal_error_diagnostic(ms
179 use crate::diagnostics::{Diagnostic, Level};
180
181 Diagnostic::default()
182 - .with_title(msg, Level::Warning)
183 + .with_title(msg, Level::WARNING)
184 .add_annotation(
185 "The bindings will be generated but not formatted.",
186 - Level::Note,
187 + Level::NOTE,
188 )
189 .display();
190 }
191 --- a/regex_set.rs
192 +++ b/regex_set.rs
193 @@ -164,9 +164,9 @@ fn invalid_regex_warning(
194 let error = "error: ";
195 if line.starts_with(error) {
196 let (_, msg) = line.split_at(error.len());
197 - diagnostic.add_annotation(msg.to_owned(), Level::Error);
198 + diagnostic.add_annotation(msg.to_owned(), Level::ERROR);
199 } else {
200 - diagnostic.add_annotation(line.to_owned(), Level::Info);
201 + diagnostic.add_annotation(line.to_owned(), Level::INFO);
202 }
203 }
204 let mut slice = Slice::default();
205 @@ -175,25 +175,25 @@ fn invalid_regex_warning(
206
207 diagnostic.with_title(
208 "Error while parsing a regular expression.",
209 - Level::Warning,
210 + Level::WARNING,
211 );
212 } else {
213 - diagnostic.with_title(string, Level::Warning);
214 + diagnostic.with_title(string, Level::WARNING);
215 }
216 }
217 err => {
218 let err = err.to_string();
219 - diagnostic.with_title(err, Level::Warning);
220 + diagnostic.with_title(err, Level::WARNING);
221 }
222 }
223
224 diagnostic.add_annotation(
225 format!("This regular expression was passed via `{name}`."),
226 - Level::Note,
227 + Level::NOTE,
228 );
229
230 if set.items.iter().any(|item| item.as_ref() == "*") {
231 - diagnostic.add_annotation("Wildcard patterns \"*\" are no longer considered valid. Use \".*\" instead.", Level::Help);
232 + diagnostic.add_annotation("Wildcard patterns \"*\" are no longer considered valid. Use \".*\" instead.", Level::HELP);
233 }
234 diagnostic.display();
235 }