Skip to content

Commit aa4875c

Browse files
committed
Rust: Make the path in Translator a PathBuf
1 parent f2505df commit aa4875c

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

rust/extractor/src/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,11 @@ impl<'a> Extractor<'a> {
6464

6565
let before_extract = Instant::now();
6666
let line_index = LineIndex::new(text.as_ref());
67-
let display_path = file.to_string_lossy();
6867
let mut trap = self.traps.create("source", file);
6968
let label = trap.emit_file(file);
7069
let mut translator = translate::Translator::new(
7170
trap,
72-
display_path.as_ref(),
71+
file,
7372
label,
7473
line_index,
7574
semantics_info.as_ref().ok(),
@@ -98,7 +97,7 @@ impl<'a> Extractor<'a> {
9897
translator.trap.commit().unwrap_or_else(|err| {
9998
error!(
10099
"Failed to write trap file for: {}: {}",
101-
display_path,
100+
file.display(),
102101
err.to_string()
103102
)
104103
});

rust/extractor/src/translate/base.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use ra_ap_syntax::{
2121
use ra_ap_syntax_bridge::{
2222
DocCommentDesugarMode, syntax_node_to_token_tree, token_tree_to_syntax_node,
2323
};
24+
use std::path::{Path, PathBuf};
2425

2526
impl Emission<ast::Item> for Translator<'_> {
2627
fn pre_emit(&mut self, node: &ast::Item) -> Option<Label<generated::Item>> {
@@ -125,7 +126,7 @@ pub enum SourceKind {
125126

126127
pub struct Translator<'db> {
127128
pub trap: TrapFile,
128-
path: String,
129+
path: PathBuf,
129130
label: Label<generated::File>,
130131
line_index: LineIndex,
131132
file_id: Option<EditionedFileId>,
@@ -147,15 +148,15 @@ const DIAGNOSTIC_LIMIT_PER_FILE: usize = 100;
147148
impl<'db> Translator<'db> {
148149
pub fn new(
149150
trap: TrapFile,
150-
path: &str,
151+
path: &Path,
151152
label: Label<generated::File>,
152153
line_index: LineIndex,
153154
semantic_info: Option<&FileSemanticInformation<'db>>,
154155
source_kind: SourceKind,
155156
) -> Translator<'db> {
156157
Translator {
157158
trap,
158-
path: path.to_owned(),
159+
path: path.to_path_buf(),
159160
label,
160161
line_index,
161162
file_id: semantic_info.map(|i| i.file_id),
@@ -293,7 +294,7 @@ impl<'db> Translator<'db> {
293294
dispatch_to_tracing!(
294295
severity,
295296
"{}:{}:{}: {}",
296-
self.path,
297+
self.path.display(),
297298
start.line + 1,
298299
start.col + 1,
299300
&full_message,

0 commit comments

Comments
 (0)