Skip to content

Commit 5c4c126

Browse files
committed
Auto merge of rust-lang#16704 - Veykril:stuff, r=Veykril
internal: Simplify
2 parents 6cb576a + ed7e9aa commit 5c4c126

File tree

11 files changed

+122
-125
lines changed

11 files changed

+122
-125
lines changed

crates/flycheck/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ impl CommandHandle {
494494
let (sender, receiver) = unbounded();
495495
let actor = CargoActor::new(sender, stdout, stderr);
496496
let thread = stdx::thread::Builder::new(stdx::thread::ThreadIntent::Worker)
497-
.name("CargoHandle".to_owned())
497+
.name("CommandHandle".to_owned())
498498
.spawn(move || actor.run())
499499
.expect("failed to spawn thread");
500500
Ok(CommandHandle { program, arguments, current_dir, child, thread, receiver })

crates/ide-assists/src/handlers/destructure_struct_binding.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use hir::{self, HasVisibility};
1+
use hir::HasVisibility;
22
use ide_db::{
33
assists::{AssistId, AssistKind},
44
defs::Definition,

crates/ide-db/src/prime_caches.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ pub fn parallel_prime_caches(
8282

8383
stdx::thread::Builder::new(stdx::thread::ThreadIntent::Worker)
8484
.allow_leak(true)
85+
.name("PrimeCaches".to_owned())
8586
.spawn(move || Cancelled::catch(|| worker(db)))
8687
.expect("failed to spawn thread");
8788
}

crates/proc-macro-srv/src/server.rs

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -54,33 +54,33 @@ fn spacing_to_external(spacing: Spacing) -> proc_macro::Spacing {
5454
}
5555
}
5656

57-
struct LiteralFormatter<S>(bridge::Literal<S, Symbol>);
58-
59-
impl<S> LiteralFormatter<S> {
60-
/// Invokes the callback with a `&[&str]` consisting of each part of the
61-
/// literal's representation. This is done to allow the `ToString` and
62-
/// `Display` implementations to borrow references to symbol values, and
63-
/// both be optimized to reduce overhead.
64-
fn with_stringify_parts<R>(
65-
&self,
66-
interner: SymbolInternerRef,
67-
f: impl FnOnce(&[&str]) -> R,
68-
) -> R {
69-
/// Returns a string containing exactly `num` '#' characters.
70-
/// Uses a 256-character source string literal which is always safe to
71-
/// index with a `u8` index.
72-
fn get_hashes_str(num: u8) -> &'static str {
73-
const HASHES: &str = "\
57+
/// Invokes the callback with a `&[&str]` consisting of each part of the
58+
/// literal's representation. This is done to allow the `ToString` and
59+
/// `Display` implementations to borrow references to symbol values, and
60+
/// both be optimized to reduce overhead.
61+
fn literal_with_stringify_parts<S, R>(
62+
literal: &bridge::Literal<S, Symbol>,
63+
interner: SymbolInternerRef,
64+
f: impl FnOnce(&[&str]) -> R,
65+
) -> R {
66+
/// Returns a string containing exactly `num` '#' characters.
67+
/// Uses a 256-character source string literal which is always safe to
68+
/// index with a `u8` index.
69+
fn get_hashes_str(num: u8) -> &'static str {
70+
const HASHES: &str = "\
7471
################################################################\
7572
################################################################\
7673
################################################################\
7774
################################################################\
7875
";
79-
const _: () = assert!(HASHES.len() == 256);
80-
&HASHES[..num as usize]
81-
}
76+
const _: () = assert!(HASHES.len() == 256);
77+
&HASHES[..num as usize]
78+
}
8279

83-
self.with_symbol_and_suffix(interner, |symbol, suffix| match self.0.kind {
80+
{
81+
let symbol = &*literal.symbol.text(interner);
82+
let suffix = &*literal.suffix.map(|s| s.text(interner)).unwrap_or_default();
83+
match literal.kind {
8484
bridge::LitKind::Byte => f(&["b'", symbol, "'", suffix]),
8585
bridge::LitKind::Char => f(&["'", symbol, "'", suffix]),
8686
bridge::LitKind::Str => f(&["\"", symbol, "\"", suffix]),
@@ -101,16 +101,6 @@ impl<S> LiteralFormatter<S> {
101101
bridge::LitKind::Integer | bridge::LitKind::Float | bridge::LitKind::ErrWithGuar => {
102102
f(&[symbol, suffix])
103103
}
104-
})
105-
}
106-
107-
fn with_symbol_and_suffix<R>(
108-
&self,
109-
interner: SymbolInternerRef,
110-
f: impl FnOnce(&str, &str) -> R,
111-
) -> R {
112-
let symbol = self.0.symbol.text(interner);
113-
let suffix = self.0.suffix.map(|s| s.text(interner)).unwrap_or_default();
114-
f(symbol.as_str(), suffix.as_str())
104+
}
115105
}
116106
}

crates/proc-macro-srv/src/server/rust_analyzer_span.rs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use proc_macro::bridge::{self, server};
1515
use span::{Span, FIXUP_ERASED_FILE_AST_ID_MARKER};
1616

1717
use crate::server::{
18-
delim_to_external, delim_to_internal, token_stream::TokenStreamBuilder, LiteralFormatter,
19-
Symbol, SymbolInternerRef, SYMBOL_INTERNER,
18+
delim_to_external, delim_to_internal, literal_with_stringify_parts,
19+
token_stream::TokenStreamBuilder, Symbol, SymbolInternerRef, SYMBOL_INTERNER,
2020
};
2121
mod tt {
2222
pub use ::tt::*;
@@ -180,12 +180,11 @@ impl server::TokenStream for RaSpanServer {
180180
}
181181

182182
bridge::TokenTree::Literal(literal) => {
183-
let literal = LiteralFormatter(literal);
184-
let text = literal.with_stringify_parts(self.interner, |parts| {
183+
let text = literal_with_stringify_parts(&literal, self.interner, |parts| {
185184
::tt::SmolStr::from_iter(parts.iter().copied())
186185
});
187186

188-
let literal = tt::Literal { text, span: literal.0.span };
187+
let literal = tt::Literal { text, span: literal.span };
189188
let leaf: tt::Leaf = tt::Leaf::from(literal);
190189
let tree = tt::TokenTree::from(leaf);
191190
Self::TokenStream::from_iter(iter::once(tree))
@@ -251,10 +250,17 @@ impl server::TokenStream for RaSpanServer {
251250
.into_iter()
252251
.map(|tree| match tree {
253252
tt::TokenTree::Leaf(tt::Leaf::Ident(ident)) => {
254-
bridge::TokenTree::Ident(bridge::Ident {
255-
sym: Symbol::intern(self.interner, ident.text.trim_start_matches("r#")),
256-
is_raw: ident.text.starts_with("r#"),
257-
span: ident.span,
253+
bridge::TokenTree::Ident(match ident.text.strip_prefix("r#") {
254+
Some(text) => bridge::Ident {
255+
sym: Symbol::intern(self.interner, text),
256+
is_raw: true,
257+
span: ident.span,
258+
},
259+
None => bridge::Ident {
260+
sym: Symbol::intern(self.interner, &ident.text),
261+
is_raw: false,
262+
span: ident.span,
263+
},
258264
})
259265
}
260266
tt::TokenTree::Leaf(tt::Leaf::Literal(lit)) => {
@@ -285,11 +291,12 @@ impl server::TokenStream for RaSpanServer {
285291
}
286292

287293
impl server::SourceFile for RaSpanServer {
288-
// FIXME these are all stubs
289294
fn eq(&mut self, _file1: &Self::SourceFile, _file2: &Self::SourceFile) -> bool {
295+
// FIXME
290296
true
291297
}
292298
fn path(&mut self, _file: &Self::SourceFile) -> String {
299+
// FIXME
293300
String::new()
294301
}
295302
fn is_real(&mut self, _file: &Self::SourceFile) -> bool {
@@ -306,11 +313,15 @@ impl server::Span for RaSpanServer {
306313
SourceFile {}
307314
}
308315
fn save_span(&mut self, _span: Self::Span) -> usize {
309-
// FIXME stub, requires builtin quote! implementation
316+
// FIXME, quote is incompatible with third-party tools
317+
// This is called by the quote proc-macro which is expanded when the proc-macro is compiled
318+
// As such, r-a will never observe this
310319
0
311320
}
312321
fn recover_proc_macro_span(&mut self, _id: usize) -> Self::Span {
313-
// FIXME stub, requires builtin quote! implementation
322+
// FIXME, quote is incompatible with third-party tools
323+
// This is called by the expansion of quote!, r-a will observe this, but we don't have
324+
// access to the spans that were encoded
314325
self.call_site
315326
}
316327
/// Recent feature, not yet in the proc_macro

crates/proc-macro-srv/src/server/token_id.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use std::{
88
use proc_macro::bridge::{self, server};
99

1010
use crate::server::{
11-
delim_to_external, delim_to_internal, token_stream::TokenStreamBuilder, LiteralFormatter,
12-
Symbol, SymbolInternerRef, SYMBOL_INTERNER,
11+
delim_to_external, delim_to_internal, literal_with_stringify_parts,
12+
token_stream::TokenStreamBuilder, Symbol, SymbolInternerRef, SYMBOL_INTERNER,
1313
};
1414
mod tt {
1515
pub use proc_macro_api::msg::TokenId;
@@ -171,12 +171,12 @@ impl server::TokenStream for TokenIdServer {
171171
}
172172

173173
bridge::TokenTree::Literal(literal) => {
174-
let literal = LiteralFormatter(literal);
175-
let text = literal.with_stringify_parts(self.interner, |parts| {
174+
let text = literal_with_stringify_parts(&literal, self.interner, |parts| {
176175
::tt::SmolStr::from_iter(parts.iter().copied())
177176
});
178177

179-
let literal = tt::Literal { text, span: literal.0.span };
178+
let literal = tt::Literal { text, span: literal.span };
179+
180180
let leaf = tt::Leaf::from(literal);
181181
let tree = TokenTree::from(leaf);
182182
Self::TokenStream::from_iter(iter::once(tree))

crates/rust-analyzer/src/config.rs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ config_data! {
152152
// FIXME(@poliorcetics): move to multiple targets here too, but this will need more work
153153
// than `checkOnSave_target`
154154
cargo_target: Option<String> = "null",
155+
/// Optional path to a rust-analyzer specific target directory.
156+
/// This prevents rust-analyzer's `cargo check` and initial build-script and proc-macro
157+
/// building from locking the `Cargo.lock` at the expense of duplicating build artifacts.
158+
///
159+
/// Set to `true` to use a subdirectory of the existing target directory or
160+
/// set to a path relative to the workspace to use that path.
161+
cargo_targetDir | rust_analyzerTargetDir: Option<TargetDirectory> = "null",
155162
/// Unsets the implicit `#[cfg(test)]` for the specified crates.
156163
cargo_unsetTest: Vec<String> = "[\"core\"]",
157164

@@ -518,14 +525,6 @@ config_data! {
518525
/// tests or binaries. For example, it may be `--release`.
519526
runnables_extraArgs: Vec<String> = "[]",
520527

521-
/// Optional path to a rust-analyzer specific target directory.
522-
/// This prevents rust-analyzer's `cargo check` from locking the `Cargo.lock`
523-
/// at the expense of duplicating build artifacts.
524-
///
525-
/// Set to `true` to use a subdirectory of the existing target directory or
526-
/// set to a path relative to the workspace to use that path.
527-
rust_analyzerTargetDir: Option<TargetDirectory> = "null",
528-
529528
/// Path to the Cargo.toml of the rust compiler workspace, for usage in rustc_private
530529
/// projects, or "discover" to try to automatically find it if the `rustc-dev` component
531530
/// is installed.
@@ -1401,14 +1400,12 @@ impl Config {
14011400
}
14021401
}
14031402

1404-
// FIXME: This should be an AbsolutePathBuf
14051403
fn target_dir_from_config(&self) -> Option<PathBuf> {
1406-
self.data.rust_analyzerTargetDir.as_ref().and_then(|target_dir| match target_dir {
1407-
TargetDirectory::UseSubdirectory(yes) if *yes => {
1408-
Some(PathBuf::from("target/rust-analyzer"))
1409-
}
1410-
TargetDirectory::UseSubdirectory(_) => None,
1411-
TargetDirectory::Directory(dir) => Some(dir.clone()),
1404+
self.data.cargo_targetDir.as_ref().and_then(|target_dir| match target_dir {
1405+
TargetDirectory::UseSubdirectory(true) => Some(PathBuf::from("target/rust-analyzer")),
1406+
TargetDirectory::UseSubdirectory(false) => None,
1407+
TargetDirectory::Directory(dir) if dir.is_relative() => Some(dir.clone()),
1408+
TargetDirectory::Directory(_) => None,
14121409
})
14131410
}
14141411

@@ -2745,7 +2742,7 @@ mod tests {
27452742
"rust": { "analyzerTargetDir": null }
27462743
}))
27472744
.unwrap();
2748-
assert_eq!(config.data.rust_analyzerTargetDir, None);
2745+
assert_eq!(config.data.cargo_targetDir, None);
27492746
assert!(
27502747
matches!(config.flycheck(), FlycheckConfig::CargoCommand { target_dir, .. } if target_dir.is_none())
27512748
);
@@ -2764,10 +2761,7 @@ mod tests {
27642761
"rust": { "analyzerTargetDir": true }
27652762
}))
27662763
.unwrap();
2767-
assert_eq!(
2768-
config.data.rust_analyzerTargetDir,
2769-
Some(TargetDirectory::UseSubdirectory(true))
2770-
);
2764+
assert_eq!(config.data.cargo_targetDir, Some(TargetDirectory::UseSubdirectory(true)));
27712765
assert!(
27722766
matches!(config.flycheck(), FlycheckConfig::CargoCommand { target_dir, .. } if target_dir == Some(PathBuf::from("target/rust-analyzer")))
27732767
);
@@ -2787,7 +2781,7 @@ mod tests {
27872781
}))
27882782
.unwrap();
27892783
assert_eq!(
2790-
config.data.rust_analyzerTargetDir,
2784+
config.data.cargo_targetDir,
27912785
Some(TargetDirectory::Directory(PathBuf::from("other_folder")))
27922786
);
27932787
assert!(

crates/rust-analyzer/src/handlers/notification.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,13 @@ pub(crate) fn handle_did_change_text_document(
9090
let _p = tracing::span!(tracing::Level::INFO, "handle_did_change_text_document").entered();
9191

9292
if let Ok(path) = from_proto::vfs_path(&params.text_document.uri) {
93-
let data = match state.mem_docs.get_mut(&path) {
94-
Some(doc) => {
95-
// The version passed in DidChangeTextDocument is the version after all edits are applied
96-
// so we should apply it before the vfs is notified.
97-
doc.version = params.text_document.version;
98-
&mut doc.data
99-
}
100-
None => {
101-
tracing::error!("unexpected DidChangeTextDocument: {}", path);
102-
return Ok(());
103-
}
93+
let Some(DocumentData { version, data }) = state.mem_docs.get_mut(&path) else {
94+
tracing::error!(?path, "unexpected DidChangeTextDocument");
95+
return Ok(());
10496
};
97+
// The version passed in DidChangeTextDocument is the version after all edits are applied
98+
// so we should apply it before the vfs is notified.
99+
*version = params.text_document.version;
105100

106101
let new_contents = apply_document_changes(
107102
state.config.position_encoding(),

docs/user/generated_config.adoc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ This option does not take effect until rust-analyzer is restarted.
144144
--
145145
Compilation target override (target triple).
146146
--
147+
[[rust-analyzer.cargo.targetDir]]rust-analyzer.cargo.targetDir (default: `null`)::
148+
+
149+
--
150+
Optional path to a rust-analyzer specific target directory.
151+
This prevents rust-analyzer's `cargo check` and initial build-script and proc-macro
152+
building from locking the `Cargo.lock` at the expense of duplicating build artifacts.
153+
154+
Set to `true` to use a subdirectory of the existing target directory or
155+
set to a path relative to the workspace to use that path.
156+
--
147157
[[rust-analyzer.cargo.unsetTest]]rust-analyzer.cargo.unsetTest (default: `["core"]`)::
148158
+
149159
--
@@ -814,16 +824,6 @@ Command to be executed instead of 'cargo' for runnables.
814824
Additional arguments to be passed to cargo for runnables such as
815825
tests or binaries. For example, it may be `--release`.
816826
--
817-
[[rust-analyzer.rust.analyzerTargetDir]]rust-analyzer.rust.analyzerTargetDir (default: `null`)::
818-
+
819-
--
820-
Optional path to a rust-analyzer specific target directory.
821-
This prevents rust-analyzer's `cargo check` from locking the `Cargo.lock`
822-
at the expense of duplicating build artifacts.
823-
824-
Set to `true` to use a subdirectory of the existing target directory or
825-
set to a path relative to the workspace to use that path.
826-
--
827827
[[rust-analyzer.rustc.source]]rust-analyzer.rustc.source (default: `null`)::
828828
+
829829
--

editors/code/package.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,21 @@
671671
"string"
672672
]
673673
},
674+
"rust-analyzer.cargo.targetDir": {
675+
"markdownDescription": "Optional path to a rust-analyzer specific target directory.\nThis prevents rust-analyzer's `cargo check` and initial build-script and proc-macro\nbuilding from locking the `Cargo.lock` at the expense of duplicating build artifacts.\n\nSet to `true` to use a subdirectory of the existing target directory or\nset to a path relative to the workspace to use that path.",
676+
"default": null,
677+
"anyOf": [
678+
{
679+
"type": "null"
680+
},
681+
{
682+
"type": "boolean"
683+
},
684+
{
685+
"type": "string"
686+
}
687+
]
688+
},
674689
"rust-analyzer.cargo.unsetTest": {
675690
"markdownDescription": "Unsets the implicit `#[cfg(test)]` for the specified crates.",
676691
"default": [
@@ -1543,21 +1558,6 @@
15431558
"type": "string"
15441559
}
15451560
},
1546-
"rust-analyzer.rust.analyzerTargetDir": {
1547-
"markdownDescription": "Optional path to a rust-analyzer specific target directory.\nThis prevents rust-analyzer's `cargo check` from locking the `Cargo.lock`\nat the expense of duplicating build artifacts.\n\nSet to `true` to use a subdirectory of the existing target directory or\nset to a path relative to the workspace to use that path.",
1548-
"default": null,
1549-
"anyOf": [
1550-
{
1551-
"type": "null"
1552-
},
1553-
{
1554-
"type": "boolean"
1555-
},
1556-
{
1557-
"type": "string"
1558-
}
1559-
]
1560-
},
15611561
"rust-analyzer.rustc.source": {
15621562
"markdownDescription": "Path to the Cargo.toml of the rust compiler workspace, for usage in rustc_private\nprojects, or \"discover\" to try to automatically find it if the `rustc-dev` component\nis installed.\n\nAny project which uses rust-analyzer with the rustcPrivate\ncrates must set `[package.metadata.rust-analyzer] rustc_private=true` to use it.\n\nThis option does not take effect until rust-analyzer is restarted.",
15631563
"default": null,

0 commit comments

Comments
 (0)