Skip to content

Commit 3e343e7

Browse files
committed
adding commands to run and debug selected tests
1 parent cccc7ca commit 3e343e7

File tree

21 files changed

+278
-228
lines changed

21 files changed

+278
-228
lines changed

Cargo.lock

+98-178
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ text-size = "1.1.1"
116116
rayon = "1.8.0"
117117
serde = { version = "1.0.192", features = ["derive"] }
118118
serde_json = "1.0.108"
119-
triomphe = { version = "0.1.8", default-features = false, features = ["std"] }
119+
triomphe = { version = "0.1.10", default-features = false, features = ["std"] }
120120
# can't upgrade due to dashmap depending on 0.12.3 currently
121121
hashbrown = { version = "0.12.3", features = [
122122
"inline-more",

crates/base-db/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ rust-version.workspace = true
1212
doctest = false
1313

1414
[dependencies]
15-
salsa = "0.17.0-pre.2"
15+
rust-analyzer-salsa = "0.17.0-pre.3"
1616
rustc-hash = "1.1.0"
1717

1818
triomphe.workspace = true

crates/hir-ty/Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ oorandom = "11.1.3"
2323
tracing.workspace = true
2424
rustc-hash = "1.1.0"
2525
scoped-tls = "1.0.0"
26-
chalk-solve = { version = "0.94.0", default-features = false }
27-
chalk-ir = "0.94.0"
28-
chalk-recursive = { version = "0.94.0", default-features = false }
29-
chalk-derive = "0.94.0"
26+
chalk-solve = { version = "0.95.0", default-features = false }
27+
chalk-ir = "0.95.0"
28+
chalk-recursive = { version = "0.95.0", default-features = false }
29+
chalk-derive = "0.95.0"
3030
la-arena.workspace = true
3131
once_cell = "1.17.0"
3232
triomphe.workspace = true

crates/hir-ty/src/infer.rs

+8-13
Original file line numberDiff line numberDiff line change
@@ -1152,20 +1152,15 @@ impl<'a> InferenceContext<'a> {
11521152
(ty, variant)
11531153
}
11541154
TypeNs::TypeAliasId(it) => {
1155-
let container = it.lookup(self.db.upcast()).container;
1156-
let parent_subst = match container {
1157-
ItemContainerId::TraitId(id) => {
1158-
let subst = TyBuilder::subst_for_def(self.db, id, None)
1159-
.fill_with_inference_vars(&mut self.table)
1160-
.build();
1161-
Some(subst)
1162-
}
1163-
// Type aliases do not exist in impls.
1164-
_ => None,
1155+
let resolved_seg = match unresolved {
1156+
None => path.segments().last().unwrap(),
1157+
Some(n) => path.segments().get(path.segments().len() - n - 1).unwrap(),
11651158
};
1166-
let ty = TyBuilder::def_ty(self.db, it.into(), parent_subst)
1167-
.fill_with_inference_vars(&mut self.table)
1168-
.build();
1159+
let substs =
1160+
ctx.substs_from_path_segment(resolved_seg, Some(it.into()), true, None);
1161+
let ty = self.db.ty(it.into());
1162+
let ty = self.insert_type_vars(ty.substitute(Interner, &substs));
1163+
11691164
self.resolve_variant_on_alias(ty, unresolved, mod_path)
11701165
}
11711166
TypeNs::AdtSelfType(_) => {

crates/hir-ty/src/lower.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ impl<'a> TyLoweringContext<'a> {
768768
}
769769
}
770770

771-
fn substs_from_path_segment(
771+
pub(super) fn substs_from_path_segment(
772772
&self,
773773
segment: PathSegment<'_>,
774774
def: Option<GenericDefId>,

crates/hir-ty/src/tests/patterns.rs

+24
Original file line numberDiff line numberDiff line change
@@ -1129,3 +1129,27 @@ fn foo() {
11291129
"#,
11301130
);
11311131
}
1132+
1133+
#[test]
1134+
fn generic_alias() {
1135+
check_types(
1136+
r#"
1137+
type Wrap<T> = T;
1138+
1139+
enum X {
1140+
A { cool: u32, stuff: u32 },
1141+
B,
1142+
}
1143+
1144+
fn main() {
1145+
let wrapped = Wrap::<X>::A {
1146+
cool: 100,
1147+
stuff: 100,
1148+
};
1149+
1150+
if let Wrap::<X>::A { cool, ..} = &wrapped {}
1151+
//^^^^ &u32
1152+
}
1153+
"#,
1154+
);
1155+
}

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

+27-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use syntax::{ast, AstNode};
1+
use syntax::{ast, AstNode, SyntaxKind, T};
22

33
use crate::{AssistContext, AssistId, AssistKind, Assists};
44

@@ -39,7 +39,19 @@ pub(crate) fn remove_parentheses(acc: &mut Assists, ctx: &AssistContext<'_>) ->
3939
AssistId("remove_parentheses", AssistKind::Refactor),
4040
"Remove redundant parentheses",
4141
target,
42-
|builder| builder.replace_ast(parens.into(), expr),
42+
|builder| {
43+
let prev_token = parens.syntax().first_token().and_then(|it| it.prev_token());
44+
let need_to_add_ws = match prev_token {
45+
Some(it) => {
46+
let tokens = vec![T![&], T![!], T!['('], T!['['], T!['{']];
47+
it.kind() != SyntaxKind::WHITESPACE && !tokens.contains(&it.kind())
48+
}
49+
None => false,
50+
};
51+
let expr = if need_to_add_ws { format!(" {}", expr) } else { expr.to_string() };
52+
53+
builder.replace(parens.syntax().text_range(), expr)
54+
},
4355
)
4456
}
4557

@@ -49,6 +61,15 @@ mod tests {
4961

5062
use super::*;
5163

64+
#[test]
65+
fn remove_parens_space() {
66+
check_assist(
67+
remove_parentheses,
68+
r#"fn f() { match$0(true) {} }"#,
69+
r#"fn f() { match true {} }"#,
70+
);
71+
}
72+
5273
#[test]
5374
fn remove_parens_simple() {
5475
check_assist(remove_parentheses, r#"fn f() { $0(2) + 2; }"#, r#"fn f() { 2 + 2; }"#);
@@ -94,8 +115,8 @@ mod tests {
94115
check_assist(remove_parentheses, r#"fn f() { f(($02 + 2)); }"#, r#"fn f() { f(2 + 2); }"#);
95116
check_assist(
96117
remove_parentheses,
97-
r#"fn f() { (1<2)&&$0(3>4); }"#,
98-
r#"fn f() { (1<2)&&3>4; }"#,
118+
r#"fn f() { (1<2) &&$0(3>4); }"#,
119+
r#"fn f() { (1<2) && 3>4; }"#,
99120
);
100121
}
101122

@@ -164,8 +185,8 @@ mod tests {
164185
fn remove_parens_weird_places() {
165186
check_assist(
166187
remove_parentheses,
167-
r#"fn f() { match () { _=>$0(()) } }"#,
168-
r#"fn f() { match () { _=>() } }"#,
188+
r#"fn f() { match () { _ =>$0(()) } }"#,
189+
r#"fn f() { match () { _ => () } }"#,
169190
);
170191

171192
check_assist(

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub(crate) fn toggle_ignore(acc: &mut Assists, ctx: &AssistContext<'_>) -> Optio
5555
}
5656

5757
fn has_ignore_attribute(fn_def: &ast::Fn) -> Option<ast::Attr> {
58-
fn_def.attrs().find(|attr| attr.path().map(|it| it.syntax().text() == "ignore") == Some(true))
58+
fn_def.attrs().find(|attr| attr.path().is_some_and(|it| it.syntax().text() == "ignore"))
5959
}
6060

6161
#[cfg(test)]

crates/ide-completion/src/item.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ use crate::{
2626
pub struct CompletionItem {
2727
/// Label in the completion pop up which identifies completion.
2828
pub label: SmolStr,
29+
/// Additional label details in the completion pop up that are
30+
/// displayed and aligned on the right side after the label.
31+
pub label_detail: Option<SmolStr>,
32+
2933
/// Range of identifier that is being completed.
3034
///
3135
/// It should be used primarily for UI, but we also use this to convert
@@ -425,13 +429,14 @@ impl Builder {
425429
pub(crate) fn build(self, db: &RootDatabase) -> CompletionItem {
426430
let _p = profile::span("item::Builder::build");
427431

428-
let mut label = self.label;
432+
let label = self.label;
433+
let mut label_detail = None;
429434
let mut lookup = self.lookup.unwrap_or_else(|| label.clone());
430435
let insert_text = self.insert_text.unwrap_or_else(|| label.to_string());
431436

432437
if !self.doc_aliases.is_empty() {
433438
let doc_aliases = self.doc_aliases.iter().join(", ");
434-
label = SmolStr::from(format!("{label} (alias {doc_aliases})"));
439+
label_detail.replace(SmolStr::from(format!(" (alias {doc_aliases})")));
435440
let lookup_doc_aliases = self
436441
.doc_aliases
437442
.iter()
@@ -454,10 +459,17 @@ impl Builder {
454459
if let [import_edit] = &*self.imports_to_add {
455460
// snippets can have multiple imports, but normal completions only have up to one
456461
if let Some(original_path) = import_edit.original_path.as_ref() {
457-
label = SmolStr::from(format!("{label} (use {})", original_path.display(db)));
462+
label_detail.replace(SmolStr::from(format!(
463+
"{} (use {})",
464+
label_detail.as_deref().unwrap_or_default(),
465+
original_path.display(db)
466+
)));
458467
}
459468
} else if let Some(trait_name) = self.trait_name {
460-
label = SmolStr::from(format!("{label} (as {trait_name})"));
469+
label_detail.replace(SmolStr::from(format!(
470+
"{} (as {trait_name})",
471+
label_detail.as_deref().unwrap_or_default(),
472+
)));
461473
}
462474

463475
let text_edit = match self.text_edit {
@@ -479,6 +491,7 @@ impl Builder {
479491
CompletionItem {
480492
source_range: self.source_range,
481493
label,
494+
label_detail,
482495
text_edit,
483496
is_snippet: self.is_snippet,
484497
detail: self.detail,

crates/ide-completion/src/render.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,11 @@ mod tests {
557557

558558
let tag = it.kind.tag();
559559
let relevance = display_relevance(it.relevance);
560-
items.push(format!("{tag} {} {relevance}\n", it.label));
560+
items.push(format!(
561+
"{tag} {}{} {relevance}\n",
562+
it.label,
563+
it.label_detail.clone().unwrap_or_default(),
564+
));
561565

562566
if let Some((label, _indel, relevance)) = it.ref_match() {
563567
let relevance = display_relevance(relevance);

crates/ide-completion/src/tests.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,29 @@ fn render_completion_list(completions: Vec<CompletionItem>) -> String {
150150
fn monospace_width(s: &str) -> usize {
151151
s.chars().count()
152152
}
153-
let label_width =
154-
completions.iter().map(|it| monospace_width(&it.label)).max().unwrap_or_default().min(22);
153+
let label_width = completions
154+
.iter()
155+
.map(|it| {
156+
monospace_width(&it.label)
157+
+ monospace_width(it.label_detail.as_deref().unwrap_or_default())
158+
})
159+
.max()
160+
.unwrap_or_default()
161+
.min(22);
155162
completions
156163
.into_iter()
157164
.map(|it| {
158165
let tag = it.kind.tag();
159166
let var_name = format!("{tag} {}", it.label);
160167
let mut buf = var_name;
168+
if let Some(ref label_detail) = it.label_detail {
169+
format_to!(buf, "{label_detail}");
170+
}
161171
if let Some(detail) = it.detail {
162-
let width = label_width.saturating_sub(monospace_width(&it.label));
172+
let width = label_width.saturating_sub(
173+
monospace_width(&it.label)
174+
+ monospace_width(&it.label_detail.unwrap_or_default()),
175+
);
163176
format_to!(buf, "{:width$} {}", "", detail, width = width);
164177
}
165178
if it.deprecated {

crates/ide-completion/src/tests/pattern.rs

+29
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,35 @@ fn outer(Foo { bar$0 }: Foo) {}
354354
)
355355
}
356356

357+
#[test]
358+
fn completes_in_record_field_pat_with_generic_type_alias() {
359+
check_empty(
360+
r#"
361+
type Wrap<T> = T;
362+
363+
enum X {
364+
A { cool: u32, stuff: u32 },
365+
B,
366+
}
367+
368+
fn main() {
369+
let wrapped = Wrap::<X>::A {
370+
cool: 100,
371+
stuff: 100,
372+
};
373+
374+
if let Wrap::<X>::A { $0 } = &wrapped {};
375+
}
376+
"#,
377+
expect![[r#"
378+
fd cool u32
379+
fd stuff u32
380+
kw mut
381+
kw ref
382+
"#]],
383+
)
384+
}
385+
357386
#[test]
358387
fn completes_in_fn_param() {
359388
check_empty(

crates/ide/src/extend_selection.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ fn try_extend_selection(
108108

109109
let node = shallowest_node(&node);
110110

111-
if node.parent().map(|n| list_kinds.contains(&n.kind())) == Some(true) {
111+
if node.parent().is_some_and(|n| list_kinds.contains(&n.kind())) {
112112
if let Some(range) = extend_list_item(&node) {
113113
return Some(range);
114114
}

crates/rust-analyzer/src/lsp/to_proto.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,11 @@ fn completion_item(
301301

302302
if config.completion_label_details_support() {
303303
lsp_item.label_details = Some(lsp_types::CompletionItemLabelDetails {
304-
detail: None,
304+
detail: item.label_detail.as_ref().map(ToString::to_string),
305305
description: lsp_item.detail.clone(),
306306
});
307+
} else if let Some(label_detail) = item.label_detail {
308+
lsp_item.label.push_str(label_detail.as_str());
307309
}
308310

309311
set_score(&mut lsp_item, max_relevance, item.relevance);

crates/rust-analyzer/src/reload.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use ide_db::{
2222
base_db::{salsa::Durability, CrateGraph, ProcMacroPaths, ProcMacros},
2323
FxHashMap,
2424
};
25+
use itertools::Itertools;
2526
use load_cargo::{load_proc_macro, ProjectFolders};
2627
use proc_macro_api::ProcMacroServer;
2728
use project_model::{ProjectWorkspace, WorkspaceBuildScripts};
@@ -227,16 +228,12 @@ impl GlobalState {
227228
let mut i = 0;
228229
while i < workspaces.len() {
229230
if let Ok(w) = &workspaces[i] {
230-
let dupes: Vec<_> = workspaces
231+
let dupes: Vec<_> = workspaces[i + 1..]
231232
.iter()
232-
.enumerate()
233-
.skip(i + 1)
234-
.filter_map(|(i, it)| {
235-
it.as_ref().ok().filter(|ws| ws.eq_ignore_build_data(w)).map(|_| i)
236-
})
233+
.positions(|it| it.as_ref().is_ok_and(|ws| ws.eq_ignore_build_data(w)))
237234
.collect();
238235
dupes.into_iter().rev().for_each(|d| {
239-
_ = workspaces.remove(d);
236+
_ = workspaces.remove(d + i + 1);
240237
});
241238
}
242239
i += 1;

crates/rust-analyzer/tests/slow-tests/tidy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ fn check_trailing_ws(path: &Path, text: &str) {
316316
return;
317317
}
318318
for (line_number, line) in text.lines().enumerate() {
319-
if line.chars().last().map(char::is_whitespace) == Some(true) {
319+
if line.chars().last().is_some_and(char::is_whitespace) {
320320
panic!("Trailing whitespace in {} at line {}", path.display(), line_number + 1)
321321
}
322322
}

crates/rustc-dependencies/Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ authors.workspace = true
1111
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1212

1313
[dependencies]
14-
ra-ap-rustc_lexer = { version = "0.19.0" }
15-
ra-ap-rustc_parse_format = { version = "0.14.0", default-features = false }
16-
ra-ap-rustc_index = { version = "0.19.0", default-features = false }
17-
ra-ap-rustc_abi = { version = "0.19.0", default-features = false }
14+
ra-ap-rustc_lexer = { version = "0.20.0" }
15+
ra-ap-rustc_parse_format = { version = "0.20.0", default-features = false }
16+
ra-ap-rustc_index = { version = "0.20.0", default-features = false }
17+
ra-ap-rustc_abi = { version = "0.20.0", default-features = false }
1818

1919
[features]
2020
in-rust-tree = []

editors/code/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,11 @@
498498
"default": true,
499499
"type": "boolean"
500500
},
501+
"rust-analyzer.showRequestFailedErrorNotification": {
502+
"markdownDescription": "Whether to show error notifications for failing requests.",
503+
"default": true,
504+
"type": "boolean"
505+
},
501506
"rust-analyzer.showDependenciesExplorer": {
502507
"markdownDescription": "Whether to show the dependencies view.",
503508
"default": true,

0 commit comments

Comments
 (0)