Skip to content

Commit e8d8a67

Browse files
authored
Merge pull request #22440 from github/rust-analyzer-update-tweaks
Rust: rust-analyzer update tweaks
2 parents 8156dc2 + aa4875c commit e8d8a67

3 files changed

Lines changed: 13 additions & 17 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,

rust/extractor/src/translate/format_args.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,21 @@ pub(crate) fn reconstruct(
5656
input: &tt::TopSubtree,
5757
call_site: Span,
5858
) -> Option<tt::TopSubtree> {
59-
let (writer, content) = split_arguments(wrap, input)?;
6059
let emitter = Emitter {
6160
call_site,
6261
format_args_parens: input.view().top_subtree().delimiter,
6362
};
6463

6564
let mut builder = tt::TopSubtreeBuilder::new(tt::Delimiter::invisible_spanned(call_site));
6665
match wrap {
67-
Wrap::Bare => emitter.push_format_args(&mut builder, content),
66+
Wrap::Bare => emitter.push_format_args(&mut builder, input.view().token_trees()),
6867
Wrap::Call(path) => {
6968
emitter.push_path(&mut builder, path);
70-
emitter.push_parenthesized_format_args(&mut builder, content);
69+
emitter.push_parenthesized_format_args(&mut builder, input.view().token_trees());
7170
}
7271
Wrap::WriteMethod => {
73-
builder.extend_with_tt(writer.expect("write! split always yields a writer"));
72+
let (writer, content) = split_arguments(input)?;
73+
builder.extend_with_tt(writer);
7474
builder.push(emitter.punct('.', tt::Spacing::Alone));
7575
builder.push(emitter.ident("write_fmt"));
7676
emitter.push_parenthesized_format_args(&mut builder, content);
@@ -82,12 +82,8 @@ pub(crate) fn reconstruct(
8282
/// Splits the macro argument list into the leading writer (for `write!`/`writeln!`,
8383
/// everything up to the first top-level comma) and the format arguments.
8484
fn split_arguments<'a>(
85-
wrap: Wrap,
8685
input: &'a tt::TopSubtree,
87-
) -> Option<(Option<tt::TokenTreesView<'a>>, tt::TokenTreesView<'a>)> {
88-
if wrap != Wrap::WriteMethod {
89-
return Some((None, input.view().token_trees()));
90-
}
86+
) -> Option<(tt::TokenTreesView<'a>, tt::TokenTreesView<'a>)> {
9187
let mut iter = input.view().iter();
9288
let start = iter.savepoint();
9389
let mut found_comma = false;
@@ -105,7 +101,7 @@ fn split_arguments<'a>(
105101
}
106102
let writer = iter.from_savepoint(start);
107103
iter.next(); // consume the comma
108-
Some((Some(writer), iter.remaining()))
104+
Some((writer, iter.remaining()))
109105
}
110106

111107
/// Emits the synthesized tokens, tagging them with the macro call site span.

0 commit comments

Comments
 (0)