Skip to content

Commit d1fb25b

Browse files
committed
Use name instead of absolute path for diagnostics.
1 parent 1495acd commit d1fb25b

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

bindgen/codegen/mod.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -4638,12 +4638,13 @@ fn unsupported_abi_diagnostic(
46384638
..
46394639
}) = location.cloned()
46404640
{
4641-
let file_path = file.path();
4642-
if let Ok(Some(source)) = get_line(&file_path, line) {
4641+
if let Ok(Some(source)) = get_line(file.path(), line) {
46434642
let mut slice = Slice::default();
4644-
slice
4645-
.with_source(source)
4646-
.with_location(file_path, line, column);
4643+
slice.with_source(source).with_location(
4644+
file.name(),
4645+
line,
4646+
column,
4647+
);
46474648
diag.add_slice(slice);
46484649
}
46494650
}
@@ -4680,12 +4681,13 @@ fn variadic_fn_diagnostic(
46804681
..
46814682
}) = location.cloned()
46824683
{
4683-
let file_path = file.path();
4684-
if let Ok(Some(source)) = get_line(&file_path, line) {
4684+
if let Ok(Some(source)) = get_line(file.path(), line) {
46854685
let mut slice = Slice::default();
4686-
slice
4687-
.with_source(source)
4688-
.with_location(file_path, line, column);
4686+
slice.with_source(source).with_location(
4687+
file.name(),
4688+
line,
4689+
column,
4690+
);
46894691
diag.add_slice(slice);
46904692
}
46914693
}

bindgen/diagnostics.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<'a> Diagnostic<'a> {
110110
slices.push(ExtSlice {
111111
source: source.as_ref(),
112112
line_start: slice.line.unwrap_or_default(),
113-
origin: slice.filename.as_deref(),
113+
origin: slice.origin.as_deref(),
114114
annotations: vec![],
115115
fold: false,
116116
})
@@ -146,9 +146,9 @@ impl<'a> Diagnostic<'a> {
146146
/// A slice of source code.
147147
#[derive(Default)]
148148
pub(crate) struct Slice<'a> {
149-
source: Option<Cow<'a, str>>,
150-
filename: Option<String>,
151149
line: Option<usize>,
150+
origin: Option<String>,
151+
source: Option<Cow<'a, str>>,
152152
}
153153

154154
impl<'a> Slice<'a> {
@@ -162,15 +162,14 @@ impl<'a> Slice<'a> {
162162
}
163163

164164
/// Set the file, line and column.
165-
pub(crate) fn with_location<P: AsRef<Path>>(
165+
pub(crate) fn with_location(
166166
&mut self,
167-
path: P,
167+
file_name: &str,
168168
line: usize,
169-
col: usize,
169+
column: usize,
170170
) -> &mut Self {
171-
self.filename =
172-
Some(format!("{}:{}:{}", path.as_ref().display(), line, col));
173171
self.line = Some(line);
172+
self.origin = Some(format!("{file_name}:{line}:{column}"));
174173
self
175174
}
176175
}

bindgen/ir/var.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -512,11 +512,10 @@ fn duplicated_macro_diagnostic(
512512
file, line, column, ..
513513
} = location
514514
{
515-
let file_path = file.path();
516-
if let Ok(Some(code)) = get_line(&file_path, line) {
515+
if let Ok(Some(code)) = get_line(file.path(), line) {
517516
source = code.into();
518517
}
519-
slice.with_location(file_path, line, column);
518+
slice.with_location(file.name(), line, column);
520519
}
521520

522521
slice.with_source(source);

0 commit comments

Comments
 (0)