Skip to content

Commit 623a17d

Browse files
authored
Unrolled build for #144243
Rollup merge of #144243 - lnicola:sync-from-ra, r=lnicola Subtree update of `rust-analyzer` r? ```@ghost```
2 parents 3f9f20f + 8f67bcf commit 623a17d

File tree

14 files changed

+278
-28
lines changed

14 files changed

+278
-28
lines changed

src/tools/rust-analyzer/Cargo.lock

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,7 @@ dependencies = [
12681268
"expect-test",
12691269
"intern",
12701270
"parser",
1271-
"ra-ap-rustc_lexer",
1271+
"ra-ap-rustc_lexer 0.122.0",
12721272
"rustc-hash 2.1.1",
12731273
"smallvec",
12741274
"span",
@@ -1504,7 +1504,7 @@ dependencies = [
15041504
"drop_bomb",
15051505
"edition",
15061506
"expect-test",
1507-
"ra-ap-rustc_lexer",
1507+
"ra-ap-rustc_lexer 0.122.0",
15081508
"rustc-literal-escaper",
15091509
"stdx",
15101510
"tracing",
@@ -1614,7 +1614,7 @@ dependencies = [
16141614
"object",
16151615
"paths",
16161616
"proc-macro-test",
1617-
"ra-ap-rustc_lexer",
1617+
"ra-ap-rustc_lexer 0.122.0",
16181618
"span",
16191619
"syntax-bridge",
16201620
"tt",
@@ -1756,9 +1756,9 @@ dependencies = [
17561756

17571757
[[package]]
17581758
name = "ra-ap-rustc_abi"
1759-
version = "0.121.0"
1759+
version = "0.122.0"
17601760
source = "registry+https://github.com/rust-lang/crates.io-index"
1761-
checksum = "3ee51482d1c9d3e538acda8cce723db8eea1a81540544bf362bf4c3d841b2329"
1761+
checksum = "fb01e1fec578003c85481c1cad4ff8cd8195b07c2dc85ae3f716108507ae15d5"
17621762
dependencies = [
17631763
"bitflags 2.9.1",
17641764
"ra-ap-rustc_hashes",
@@ -1768,28 +1768,28 @@ dependencies = [
17681768

17691769
[[package]]
17701770
name = "ra-ap-rustc_hashes"
1771-
version = "0.121.0"
1771+
version = "0.122.0"
17721772
source = "registry+https://github.com/rust-lang/crates.io-index"
1773-
checksum = "19c8f1e0c28e24e1b4c55dc08058c6c9829df2204497d4034259f491d348c204"
1773+
checksum = "e0ec056e72a472ffef8761ce96ece6c626eb07368c09d0105b6df30d27d07673"
17741774
dependencies = [
17751775
"rustc-stable-hash",
17761776
]
17771777

17781778
[[package]]
17791779
name = "ra-ap-rustc_index"
1780-
version = "0.121.0"
1780+
version = "0.122.0"
17811781
source = "registry+https://github.com/rust-lang/crates.io-index"
1782-
checksum = "5f33f429cec6b92fa2c7243883279fb29dd233fdc3e94099aff32aa91aa87f50"
1782+
checksum = "0fcdd1001db0295e59052e9f53aeda588bbe81e362534f4687d41bd44777b5a7"
17831783
dependencies = [
17841784
"ra-ap-rustc_index_macros",
17851785
"smallvec",
17861786
]
17871787

17881788
[[package]]
17891789
name = "ra-ap-rustc_index_macros"
1790-
version = "0.121.0"
1790+
version = "0.122.0"
17911791
source = "registry+https://github.com/rust-lang/crates.io-index"
1792-
checksum = "b9b55910dbe1fe7ef34bdc1d1bcb41e99b377eb680ea58a1218d95d6b4152257"
1792+
checksum = "728d64dd98e25530b32e3f7c7c1e844e52722b269360daa1cdeba9dff9727a26"
17931793
dependencies = [
17941794
"proc-macro2",
17951795
"quote",
@@ -1807,21 +1807,32 @@ dependencies = [
18071807
"unicode-xid",
18081808
]
18091809

1810+
[[package]]
1811+
name = "ra-ap-rustc_lexer"
1812+
version = "0.122.0"
1813+
source = "registry+https://github.com/rust-lang/crates.io-index"
1814+
checksum = "415f0821f512608d825b3215489a6a6a2c18ed9f0045953d514e7ec23d4b90ab"
1815+
dependencies = [
1816+
"memchr",
1817+
"unicode-properties",
1818+
"unicode-xid",
1819+
]
1820+
18101821
[[package]]
18111822
name = "ra-ap-rustc_parse_format"
18121823
version = "0.121.0"
18131824
source = "registry+https://github.com/rust-lang/crates.io-index"
18141825
checksum = "81057891bc2063ad9e353f29462fbc47a0f5072560af34428ae9313aaa5e9d97"
18151826
dependencies = [
1816-
"ra-ap-rustc_lexer",
1827+
"ra-ap-rustc_lexer 0.121.0",
18171828
"rustc-literal-escaper",
18181829
]
18191830

18201831
[[package]]
18211832
name = "ra-ap-rustc_pattern_analysis"
1822-
version = "0.121.0"
1833+
version = "0.122.0"
18231834
source = "registry+https://github.com/rust-lang/crates.io-index"
1824-
checksum = "fe21a3542980d56d2435e96c2720773cac1c63fd4db666417e414729da192eb3"
1835+
checksum = "4657fcfdfe06e2a02ec8180d4e7c95aecf4811ba50367e363d1a2300b7623284"
18251836
dependencies = [
18261837
"ra-ap-rustc_index",
18271838
"rustc-hash 2.1.1",
@@ -2581,7 +2592,7 @@ version = "0.0.0"
25812592
dependencies = [
25822593
"arrayvec",
25832594
"intern",
2584-
"ra-ap-rustc_lexer",
2595+
"ra-ap-rustc_lexer 0.122.0",
25852596
"stdx",
25862597
"text-size",
25872598
]

src/tools/rust-analyzer/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ vfs-notify = { path = "./crates/vfs-notify", version = "0.0.0" }
8989
vfs = { path = "./crates/vfs", version = "0.0.0" }
9090
edition = { path = "./crates/edition", version = "0.0.0" }
9191

92-
ra-ap-rustc_lexer = { version = "0.121", default-features = false }
92+
ra-ap-rustc_lexer = { version = "0.122", default-features = false }
9393
ra-ap-rustc_parse_format = { version = "0.121", default-features = false }
94-
ra-ap-rustc_index = { version = "0.121", default-features = false }
95-
ra-ap-rustc_abi = { version = "0.121", default-features = false }
96-
ra-ap-rustc_pattern_analysis = { version = "0.121", default-features = false }
94+
ra-ap-rustc_index = { version = "0.122", default-features = false }
95+
ra-ap-rustc_abi = { version = "0.122", default-features = false }
96+
ra-ap-rustc_pattern_analysis = { version = "0.122", default-features = false }
9797

9898
# local crates that aren't published to crates.io. These should not have versions.
9999

src/tools/rust-analyzer/crates/cfg/src/cfg_expr.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ impl CfgExpr {
6868
next_cfg_expr(&mut tt.iter()).unwrap_or(CfgExpr::Invalid)
6969
}
7070

71+
#[cfg(feature = "tt")]
72+
pub fn parse_from_iter<S: Copy>(tt: &mut tt::iter::TtIter<'_, S>) -> CfgExpr {
73+
next_cfg_expr(tt).unwrap_or(CfgExpr::Invalid)
74+
}
75+
7176
/// Fold the cfg by querying all basic `Atom` and `KeyValue` predicates.
7277
pub fn fold(&self, query: &dyn Fn(&CfgAtom) -> bool) -> Option<bool> {
7378
match self {
@@ -96,7 +101,14 @@ fn next_cfg_expr<S: Copy>(it: &mut tt::iter::TtIter<'_, S>) -> Option<CfgExpr> {
96101
};
97102

98103
let ret = match it.peek() {
99-
Some(TtElement::Leaf(tt::Leaf::Punct(punct))) if punct.char == '=' => {
104+
Some(TtElement::Leaf(tt::Leaf::Punct(punct)))
105+
// Don't consume on e.g. `=>`.
106+
if punct.char == '='
107+
&& (punct.spacing == tt::Spacing::Alone
108+
|| it.remaining().flat_tokens().get(1).is_none_or(|peek2| {
109+
!matches!(peek2, tt::TokenTree::Leaf(tt::Leaf::Punct(_)))
110+
})) =>
111+
{
100112
match it.remaining().flat_tokens().get(1) {
101113
Some(tt::TokenTree::Leaf(tt::Leaf::Literal(literal))) => {
102114
it.next();

src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/builtin_fn_macro.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,3 +550,51 @@ fn main() { "\"hello\""; }
550550
"##]],
551551
);
552552
}
553+
554+
#[test]
555+
fn cfg_select() {
556+
check(
557+
r#"
558+
#[rustc_builtin_macro]
559+
pub macro cfg_select($($tt:tt)*) {}
560+
561+
cfg_select! {
562+
false => { fn false_1() {} }
563+
any(false, true) => { fn true_1() {} }
564+
}
565+
566+
cfg_select! {
567+
false => { fn false_2() {} }
568+
_ => { fn true_2() {} }
569+
}
570+
571+
cfg_select! {
572+
false => { fn false_3() {} }
573+
}
574+
575+
cfg_select! {
576+
false
577+
}
578+
579+
cfg_select! {
580+
false =>
581+
}
582+
583+
"#,
584+
expect![[r#"
585+
#[rustc_builtin_macro]
586+
pub macro cfg_select($($tt:tt)*) {}
587+
588+
fn true_1() {}
589+
590+
fn true_2() {}
591+
592+
/* error: none of the predicates in this `cfg_select` evaluated to true */
593+
594+
/* error: expected `=>` after cfg expression */
595+
596+
/* error: expected a token tree after `=>` */
597+
598+
"#]],
599+
);
600+
}

src/tools/rust-analyzer/crates/hir-expand/src/builtin/fn_macro.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ register_builtin! {
127127
(asm, Asm) => asm_expand,
128128
(global_asm, GlobalAsm) => global_asm_expand,
129129
(naked_asm, NakedAsm) => naked_asm_expand,
130+
(cfg_select, CfgSelect) => cfg_select_expand,
130131
(cfg, Cfg) => cfg_expand,
131132
(core_panic, CorePanic) => panic_expand,
132133
(std_panic, StdPanic) => panic_expand,
@@ -355,6 +356,71 @@ fn naked_asm_expand(
355356
ExpandResult::ok(expanded)
356357
}
357358

359+
fn cfg_select_expand(
360+
db: &dyn ExpandDatabase,
361+
id: MacroCallId,
362+
tt: &tt::TopSubtree,
363+
span: Span,
364+
) -> ExpandResult<tt::TopSubtree> {
365+
let loc = db.lookup_intern_macro_call(id);
366+
let cfg_options = loc.krate.cfg_options(db);
367+
368+
let mut iter = tt.iter();
369+
let mut expand_to = None;
370+
while let Some(next) = iter.peek() {
371+
let active = if let tt::TtElement::Leaf(tt::Leaf::Ident(ident)) = next
372+
&& ident.sym == sym::underscore
373+
{
374+
iter.next();
375+
true
376+
} else {
377+
cfg_options.check(&CfgExpr::parse_from_iter(&mut iter)) != Some(false)
378+
};
379+
match iter.expect_glued_punct() {
380+
Ok(it) if it.len() == 2 && it[0].char == '=' && it[1].char == '>' => {}
381+
_ => {
382+
let err_span = iter.peek().map(|it| it.first_span()).unwrap_or(span);
383+
return ExpandResult::new(
384+
tt::TopSubtree::empty(tt::DelimSpan::from_single(span)),
385+
ExpandError::other(err_span, "expected `=>` after cfg expression"),
386+
);
387+
}
388+
}
389+
let expand_to_if_active = match iter.next() {
390+
Some(tt::TtElement::Subtree(_, tt)) => tt.remaining(),
391+
_ => {
392+
let err_span = iter.peek().map(|it| it.first_span()).unwrap_or(span);
393+
return ExpandResult::new(
394+
tt::TopSubtree::empty(tt::DelimSpan::from_single(span)),
395+
ExpandError::other(err_span, "expected a token tree after `=>`"),
396+
);
397+
}
398+
};
399+
400+
if expand_to.is_none() && active {
401+
expand_to = Some(expand_to_if_active);
402+
}
403+
}
404+
match expand_to {
405+
Some(expand_to) => {
406+
let mut builder = tt::TopSubtreeBuilder::new(tt::Delimiter {
407+
kind: tt::DelimiterKind::Invisible,
408+
open: span,
409+
close: span,
410+
});
411+
builder.extend_with_tt(expand_to);
412+
ExpandResult::ok(builder.build())
413+
}
414+
None => ExpandResult::new(
415+
tt::TopSubtree::empty(tt::DelimSpan::from_single(span)),
416+
ExpandError::other(
417+
span,
418+
"none of the predicates in this `cfg_select` evaluated to true",
419+
),
420+
),
421+
}
422+
}
423+
358424
fn cfg_expand(
359425
db: &dyn ExpandDatabase,
360426
id: MacroCallId,

src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_deref.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use syntax::{
1010
use crate::{
1111
AssistId,
1212
assist_context::{AssistContext, Assists, SourceChangeBuilder},
13-
utils::generate_trait_impl_text,
13+
utils::generate_trait_impl_text_intransitive,
1414
};
1515

1616
// Assist: generate_deref
@@ -150,7 +150,7 @@ fn generate_edit(
150150
),
151151
};
152152
let strukt_adt = ast::Adt::Struct(strukt);
153-
let deref_impl = generate_trait_impl_text(
153+
let deref_impl = generate_trait_impl_text_intransitive(
154154
&strukt_adt,
155155
&trait_path.display(db, edition).to_string(),
156156
&impl_code,
@@ -227,6 +227,28 @@ impl core::ops::Deref for B {
227227
);
228228
}
229229

230+
#[test]
231+
fn test_generate_record_deref_with_generic() {
232+
check_assist(
233+
generate_deref,
234+
r#"
235+
//- minicore: deref
236+
struct A<T>($0T);
237+
"#,
238+
r#"
239+
struct A<T>(T);
240+
241+
impl<T> core::ops::Deref for A<T> {
242+
type Target = T;
243+
244+
fn deref(&self) -> &Self::Target {
245+
&self.0
246+
}
247+
}
248+
"#,
249+
);
250+
}
251+
230252
#[test]
231253
fn test_generate_record_deref_short_path() {
232254
check_assist(

src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_mut_trait_impl.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ fn get_trait_mut(apply_trait: &hir::Trait, famous: FamousDefs<'_, '_>) -> Option
134134
if trait_ == famous.core_borrow_Borrow().as_ref() {
135135
return Some("BorrowMut");
136136
}
137+
if trait_ == famous.core_ops_Deref().as_ref() {
138+
return Some("DerefMut");
139+
}
137140
None
138141
}
139142

@@ -142,6 +145,7 @@ fn process_method_name(name: ast::Name) -> Option<(ast::Name, &'static str)> {
142145
"index" => "index_mut",
143146
"as_ref" => "as_mut",
144147
"borrow" => "borrow_mut",
148+
"deref" => "deref_mut",
145149
_ => return None,
146150
};
147151
Some((name, new_name))
@@ -258,6 +262,39 @@ impl core::convert::AsRef<i32> for Foo {
258262
&self.0
259263
}
260264
}
265+
"#,
266+
);
267+
268+
check_assist(
269+
generate_mut_trait_impl,
270+
r#"
271+
//- minicore: deref
272+
struct Foo(i32);
273+
274+
impl core::ops::Deref$0 for Foo {
275+
type Target = i32;
276+
277+
fn deref(&self) -> &Self::Target {
278+
&self.0
279+
}
280+
}
281+
"#,
282+
r#"
283+
struct Foo(i32);
284+
285+
$0impl core::ops::DerefMut for Foo {
286+
fn deref_mut(&mut self) -> &mut Self::Target {
287+
&mut self.0
288+
}
289+
}
290+
291+
impl core::ops::Deref for Foo {
292+
type Target = i32;
293+
294+
fn deref(&self) -> &Self::Target {
295+
&self.0
296+
}
297+
}
261298
"#,
262299
);
263300
}

0 commit comments

Comments
 (0)