Skip to content

Commit c1cfab2

Browse files
committed
Auto merge of #133564 - lnicola:sync-from-ra, r=lnicola
Subtree update of `rust-analyzer` r? `@ghost`
2 parents f005c74 + 15e8a26 commit c1cfab2

25 files changed

+477
-211
lines changed

src/tools/rust-analyzer/Cargo.lock

+12-12
Original file line numberDiff line numberDiff line change
@@ -1492,9 +1492,9 @@ dependencies = [
14921492

14931493
[[package]]
14941494
name = "ra-ap-rustc_abi"
1495-
version = "0.76.0"
1495+
version = "0.80.0"
14961496
source = "registry+https://github.com/rust-lang/crates.io-index"
1497-
checksum = "709fde78db053c78c87776ec738677649f791645883f82ff145f68caf9f18e1a"
1497+
checksum = "613760a3071b25a67a8d7bc97b37c7fd4722562e9479137b83ae9cf8f8c1601a"
14981498
dependencies = [
14991499
"bitflags 2.6.0",
15001500
"ra-ap-rustc_index",
@@ -1503,9 +1503,9 @@ dependencies = [
15031503

15041504
[[package]]
15051505
name = "ra-ap-rustc_index"
1506-
version = "0.76.0"
1506+
version = "0.80.0"
15071507
source = "registry+https://github.com/rust-lang/crates.io-index"
1508-
checksum = "da115d496e5abd65e2dceb6883d7597593badfe23fea3439202b8da5a11ea250"
1508+
checksum = "5b2bc6b4ecede8ff28295041e22c2e66853f8e0125990c05135bad3c30bad12c"
15091509
dependencies = [
15101510
"arrayvec",
15111511
"ra-ap-rustc_index_macros",
@@ -1514,9 +1514,9 @@ dependencies = [
15141514

15151515
[[package]]
15161516
name = "ra-ap-rustc_index_macros"
1517-
version = "0.76.0"
1517+
version = "0.80.0"
15181518
source = "registry+https://github.com/rust-lang/crates.io-index"
1519-
checksum = "be86d06a75a8125c1ace197d5030e6e02721348d32e572baea35c891669ad1e2"
1519+
checksum = "2374a39fb2d92d0509178c2b442eadca3cc10e403ef9729a040c1855b08ff261"
15201520
dependencies = [
15211521
"proc-macro2",
15221522
"quote",
@@ -1525,29 +1525,29 @@ dependencies = [
15251525

15261526
[[package]]
15271527
name = "ra-ap-rustc_lexer"
1528-
version = "0.76.0"
1528+
version = "0.80.0"
15291529
source = "registry+https://github.com/rust-lang/crates.io-index"
1530-
checksum = "b64b46ae0d8f59acc32e64e0085532b831f0d6182d870a7cd86c046c2c46e722"
1530+
checksum = "5a2cf8e48b69af3ecc29ed3449892e8a999111d2f75212a78aa242e117cf1711"
15311531
dependencies = [
15321532
"unicode-properties",
15331533
"unicode-xid",
15341534
]
15351535

15361536
[[package]]
15371537
name = "ra-ap-rustc_parse_format"
1538-
version = "0.76.0"
1538+
version = "0.80.0"
15391539
source = "registry+https://github.com/rust-lang/crates.io-index"
1540-
checksum = "dbdaad19ddbd0ff46e947ca8dbb6ae678a112d3938669fb3ad6bfd244917e24b"
1540+
checksum = "8d6f59a22b559263c5c42747ae362cf5d4fb272293fa119a4623f8ec288f9656"
15411541
dependencies = [
15421542
"ra-ap-rustc_index",
15431543
"ra-ap-rustc_lexer",
15441544
]
15451545

15461546
[[package]]
15471547
name = "ra-ap-rustc_pattern_analysis"
1548-
version = "0.76.0"
1548+
version = "0.80.0"
15491549
source = "registry+https://github.com/rust-lang/crates.io-index"
1550-
checksum = "dc5761e37c78d98ede9f20f6b66526093d0be66aa256d5cbdf214495843ba74d"
1550+
checksum = "a7d0575b54ffe09bc5d2f158454bc05f0c30c01d9992310965f854be50ae22b8"
15511551
dependencies = [
15521552
"ra-ap-rustc_index",
15531553
"rustc-hash 2.0.0",

src/tools/rust-analyzer/Cargo.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ tt = { path = "./crates/tt", version = "0.0.0" }
8484
vfs-notify = { path = "./crates/vfs-notify", version = "0.0.0" }
8585
vfs = { path = "./crates/vfs", version = "0.0.0" }
8686

87-
ra-ap-rustc_lexer = { version = "0.76", default-features = false }
88-
ra-ap-rustc_parse_format = { version = "0.76", default-features = false }
89-
ra-ap-rustc_index = { version = "0.76", default-features = false }
90-
ra-ap-rustc_abi = { version = "0.76", default-features = false }
91-
ra-ap-rustc_pattern_analysis = { version = "0.76", default-features = false }
87+
ra-ap-rustc_lexer = { version = "0.80", default-features = false }
88+
ra-ap-rustc_parse_format = { version = "0.80", default-features = false }
89+
ra-ap-rustc_index = { version = "0.80", default-features = false }
90+
ra-ap-rustc_abi = { version = "0.80", default-features = false }
91+
ra-ap-rustc_pattern_analysis = { version = "0.80", default-features = false }
9292

9393
# local crates that aren't published to crates.io. These should not have versions.
9494
test-fixture = { path = "./crates/test-fixture" }

src/tools/rust-analyzer/crates/hir-ty/src/infer/unify.rs

+26-10
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,32 @@ impl<'a> InferenceTable<'a> {
916916

917917
/// Check if given type is `Sized` or not
918918
pub(crate) fn is_sized(&mut self, ty: &Ty) -> bool {
919+
let mut ty = ty.clone();
920+
{
921+
let mut structs = SmallVec::<[_; 8]>::new();
922+
// Must use a loop here and not recursion because otherwise users will conduct completely
923+
// artificial examples of structs that have themselves as the tail field and complain r-a crashes.
924+
while let Some((AdtId::StructId(id), subst)) = ty.as_adt() {
925+
let struct_data = self.db.struct_data(id);
926+
if let Some((last_field, _)) = struct_data.variant_data.fields().iter().next_back()
927+
{
928+
let last_field_ty = self.db.field_types(id.into())[last_field]
929+
.clone()
930+
.substitute(Interner, subst);
931+
if structs.contains(&ty) {
932+
// A struct recursively contains itself as a tail field somewhere.
933+
return true; // Don't overload the users with too many errors.
934+
}
935+
structs.push(ty);
936+
// Structs can have DST as its last field and such cases are not handled
937+
// as unsized by the chalk, so we do this manually.
938+
ty = last_field_ty;
939+
} else {
940+
break;
941+
};
942+
}
943+
}
944+
919945
// Early return for some obvious types
920946
if matches!(
921947
ty.kind(Interner),
@@ -930,16 +956,6 @@ impl<'a> InferenceTable<'a> {
930956
return true;
931957
}
932958

933-
if let Some((AdtId::StructId(id), subst)) = ty.as_adt() {
934-
let struct_data = self.db.struct_data(id);
935-
if let Some((last_field, _)) = struct_data.variant_data.fields().iter().last() {
936-
let last_field_ty =
937-
self.db.field_types(id.into())[last_field].clone().substitute(Interner, subst);
938-
// Structs can have DST as its last field and such cases are not handled
939-
// as unsized by the chalk, so we do this manually
940-
return self.is_sized(&last_field_ty);
941-
}
942-
}
943959
let Some(sized) = self
944960
.db
945961
.lang_item(self.trait_env.krate, LangItem::Sized)

src/tools/rust-analyzer/crates/hir-ty/src/tests/traits.rs

+21
Original file line numberDiff line numberDiff line change
@@ -4790,3 +4790,24 @@ fn allowed3(baz: impl Baz<Assoc = Qux<impl Foo>>) {}
47904790
"#]],
47914791
)
47924792
}
4793+
4794+
#[test]
4795+
fn recursive_tail_sized() {
4796+
check_infer(
4797+
r#"
4798+
struct WeirdFoo(WeirdBar);
4799+
struct WeirdBar(WeirdFoo);
4800+
4801+
fn bar(v: *const ()) {
4802+
let _ = v as *const WeirdFoo;
4803+
}
4804+
"#,
4805+
expect![[r#"
4806+
62..63 'v': *const ()
4807+
76..113 '{ ...Foo; }': ()
4808+
86..87 '_': *const WeirdFoo
4809+
90..91 'v': *const ()
4810+
90..110 'v as *...irdFoo': *const WeirdFoo
4811+
"#]],
4812+
);
4813+
}

src/tools/rust-analyzer/crates/ide-assists/src/assist_context.rs

+3
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ impl<'a> AssistContext<'a> {
116116
pub(crate) fn find_node_at_offset<N: AstNode>(&self) -> Option<N> {
117117
find_node_at_offset(self.source_file.syntax(), self.offset())
118118
}
119+
pub(crate) fn find_node_at_trimmed_offset<N: AstNode>(&self) -> Option<N> {
120+
find_node_at_offset(self.source_file.syntax(), self.trimmed_range.start())
121+
}
119122
pub(crate) fn find_node_at_range<N: AstNode>(&self) -> Option<N> {
120123
find_node_at_range(self.source_file.syntax(), self.trimmed_range)
121124
}

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

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use syntax::{
2-
ast::{self, edit::AstNodeEdit, make},
2+
ast::{self, edit_in_place::Indent, syntax_factory::SyntaxFactory},
33
AstNode,
44
};
55

@@ -39,12 +39,16 @@ pub(crate) fn add_braces(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<(
3939
},
4040
expr.syntax().text_range(),
4141
|builder| {
42-
let block_expr = AstNodeEdit::indent(
43-
&make::block_expr(None, Some(expr.clone())),
44-
AstNodeEdit::indent_level(&expr),
45-
);
42+
let make = SyntaxFactory::new();
43+
let mut editor = builder.make_editor(expr.syntax());
4644

47-
builder.replace(expr.syntax().text_range(), block_expr.syntax().text());
45+
let block_expr = make.block_expr(None, Some(expr.clone()));
46+
block_expr.indent(expr.indent_level());
47+
48+
editor.replace(expr.syntax(), block_expr.syntax());
49+
50+
editor.add_mappings(make.finish_with_mappings());
51+
builder.add_file_edits(ctx.file_id(), editor);
4852
},
4953
)
5054
}

0 commit comments

Comments
 (0)