Skip to content

Commit 3e8bc61

Browse files
committed
Use name instead of absolute path for diagnostics.
1 parent ac3d37e commit 3e8bc61

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

bindgen/codegen/mod.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -4385,12 +4385,13 @@ fn unsupported_abi_diagnostic(
43854385
..
43864386
}) = location.cloned()
43874387
{
4388-
let file_path = file.path();
4389-
if let Ok(Some(source)) = get_line(&file_path, line) {
4388+
if let Ok(Some(source)) = get_line(file.path(), line) {
43904389
let mut slice = Slice::default();
4391-
slice
4392-
.with_source(source)
4393-
.with_location(file_path, line, column);
4390+
slice.with_source(source).with_location(
4391+
file.name(),
4392+
line,
4393+
column,
4394+
);
43944395
diag.add_slice(slice);
43954396
}
43964397
}
@@ -4427,12 +4428,13 @@ fn variadic_fn_diagnostic(
44274428
..
44284429
}) = location.cloned()
44294430
{
4430-
let file_path = file.path();
4431-
if let Ok(Some(source)) = get_line(&file_path, line) {
4431+
if let Ok(Some(source)) = get_line(file.path(), line) {
44324432
let mut slice = Slice::default();
4433-
slice
4434-
.with_source(source)
4435-
.with_location(file_path, line, column);
4433+
slice.with_source(source).with_location(
4434+
file.name(),
4435+
line,
4436+
column,
4437+
);
44364438
diag.add_slice(slice);
44374439
}
44384440
}

bindgen/diagnostics.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//!
33
//! The entry point of this module is the [`Diagnostic`] type.
44
5+
use std::fmt::Write;
56
use std::io::{self, BufRead, BufReader};
67
use std::path::Path;
78
use std::{borrow::Cow, fs::File};
@@ -110,7 +111,7 @@ impl<'a> Diagnostic<'a> {
110111
slices.push(ExtSlice {
111112
source: source.as_ref(),
112113
line_start: slice.line.unwrap_or_default(),
113-
origin: slice.filename.as_deref(),
114+
origin: slice.origin.as_deref(),
114115
annotations: vec![],
115116
fold: false,
116117
})
@@ -146,9 +147,9 @@ impl<'a> Diagnostic<'a> {
146147
/// A slice of source code.
147148
#[derive(Default)]
148149
pub(crate) struct Slice<'a> {
149-
source: Option<Cow<'a, str>>,
150-
filename: Option<String>,
151150
line: Option<usize>,
151+
origin: Option<String>,
152+
source: Option<Cow<'a, str>>,
152153
}
153154

154155
impl<'a> Slice<'a> {
@@ -162,15 +163,14 @@ impl<'a> Slice<'a> {
162163
}
163164

164165
/// Set the file, line and column.
165-
pub(crate) fn with_location<P: AsRef<Path>>(
166+
pub(crate) fn with_location(
166167
&mut self,
167-
path: P,
168+
file_name: &str,
168169
line: usize,
169-
col: usize,
170+
column: usize,
170171
) -> &mut Self {
171-
self.filename =
172-
Some(format!("{}:{}:{}", path.as_ref().display(), line, col));
173172
self.line = Some(line);
173+
self.origin = Some(format!("{file_name}:{line}:{column}"));
174174
self
175175
}
176176
}

bindgen/ir/var.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -474,11 +474,10 @@ fn duplicated_macro_diagnostic(
474474
file, line, column, ..
475475
} = location
476476
{
477-
let file_path = file.path();
478-
if let Ok(Some(code)) = get_line(&file_path, line) {
477+
if let Ok(Some(code)) = get_line(file.path(), line) {
479478
source = code.into();
480479
}
481-
slice.with_location(file_path, line, column);
480+
slice.with_location(file.name(), line, column);
482481
}
483482

484483
slice.with_source(source);

0 commit comments

Comments
 (0)