Skip to content

Subtree update of rust-analyzer #133564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3e3fd4a
Use snippet placeholders for generated match arms
Giga-Bowser Nov 1, 2024
bbfee60
Properly use final tabstop when adding missing match arms
Giga-Bowser Nov 5, 2024
c588849
feat: convert add_braces to SyntaxFactory SyntaxEditor abstraction
davidkurilla Nov 6, 2024
4216615
fix: fix immutable tree error
davidkurilla Nov 12, 2024
9085744
fix: fix indentation error
davidkurilla Nov 12, 2024
5458612
fix: remove unused imports
davidkurilla Nov 13, 2024
34dd288
style: cargo fmt
davidkurilla Nov 15, 2024
c627c1a
style: remove needless borrow
davidkurilla Nov 15, 2024
a96a093
feat: migrate `reorder_impl_items` assist to use `SyntaxFactory`
tareknaser Nov 17, 2024
b4a3168
Re-add rust-analyzer.cargo.sysrootQueryMetadata
darichey Nov 14, 2024
effe9ac
improve selection handling for `merge_match_arms`
cmrschwarz Nov 18, 2024
00a8fc1
Merge pull request #18459 from Giga-Bowser/match-placeholders
lnicola Nov 19, 2024
af318f7
Merge pull request #18529 from cmrschwarz/allow_leading_whitespace_in…
lnicola Nov 19, 2024
70a098e
Merge pull request #18521 from tareknaser/syntax_factory_reorder_impl…
davidbarsky Nov 19, 2024
297db65
Merge pull request #18485 from davidkurilla/feat-migrate-add_braces-t…
davidbarsky Nov 19, 2024
a3efe3b
Update request entry point file path in architecture.md
markmurphydev Nov 23, 2024
309c671
Merge pull request #18548 from markmurphydev/master
lnicola Nov 23, 2024
63b82dd
Fix missing rust-src message
lnicola Nov 24, 2024
b250e0f
Merge pull request #18552 from lnicola/rust-src-message
lnicola Nov 24, 2024
b4a23bb
Fix a stack overflow when computing the sizedness of a struct that in…
ChayimFriedman2 Nov 25, 2024
bbce06e
Merge pull request #18559 from ChayimFriedman2/recur-unsized
lnicola Nov 25, 2024
4e3354e
Merge pull request #18511 from darichey/sysroot-query-metadata
lnicola Nov 26, 2024
6e3cb4a
Preparing for merge from rust-lang/rust
lnicola Nov 28, 2024
c91f2a3
Merge from rust-lang/rust
lnicola Nov 28, 2024
1a435ed
Bump rustc crates
lnicola Nov 28, 2024
8cf30c2
Merge pull request #18566 from lnicola/sync-from-rust
lnicola Nov 28, 2024
15e8a26
Fix proc macro test
lnicola Nov 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/tools/rust-analyzer/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1492,9 +1492,9 @@ dependencies = [

[[package]]
name = "ra-ap-rustc_abi"
version = "0.76.0"
version = "0.80.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "709fde78db053c78c87776ec738677649f791645883f82ff145f68caf9f18e1a"
checksum = "613760a3071b25a67a8d7bc97b37c7fd4722562e9479137b83ae9cf8f8c1601a"
dependencies = [
"bitflags 2.6.0",
"ra-ap-rustc_index",
Expand All @@ -1503,9 +1503,9 @@ dependencies = [

[[package]]
name = "ra-ap-rustc_index"
version = "0.76.0"
version = "0.80.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da115d496e5abd65e2dceb6883d7597593badfe23fea3439202b8da5a11ea250"
checksum = "5b2bc6b4ecede8ff28295041e22c2e66853f8e0125990c05135bad3c30bad12c"
dependencies = [
"arrayvec",
"ra-ap-rustc_index_macros",
Expand All @@ -1514,9 +1514,9 @@ dependencies = [

[[package]]
name = "ra-ap-rustc_index_macros"
version = "0.76.0"
version = "0.80.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be86d06a75a8125c1ace197d5030e6e02721348d32e572baea35c891669ad1e2"
checksum = "2374a39fb2d92d0509178c2b442eadca3cc10e403ef9729a040c1855b08ff261"
dependencies = [
"proc-macro2",
"quote",
Expand All @@ -1525,29 +1525,29 @@ dependencies = [

[[package]]
name = "ra-ap-rustc_lexer"
version = "0.76.0"
version = "0.80.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b64b46ae0d8f59acc32e64e0085532b831f0d6182d870a7cd86c046c2c46e722"
checksum = "5a2cf8e48b69af3ecc29ed3449892e8a999111d2f75212a78aa242e117cf1711"
dependencies = [
"unicode-properties",
"unicode-xid",
]

[[package]]
name = "ra-ap-rustc_parse_format"
version = "0.76.0"
version = "0.80.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbdaad19ddbd0ff46e947ca8dbb6ae678a112d3938669fb3ad6bfd244917e24b"
checksum = "8d6f59a22b559263c5c42747ae362cf5d4fb272293fa119a4623f8ec288f9656"
dependencies = [
"ra-ap-rustc_index",
"ra-ap-rustc_lexer",
]

[[package]]
name = "ra-ap-rustc_pattern_analysis"
version = "0.76.0"
version = "0.80.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc5761e37c78d98ede9f20f6b66526093d0be66aa256d5cbdf214495843ba74d"
checksum = "a7d0575b54ffe09bc5d2f158454bc05f0c30c01d9992310965f854be50ae22b8"
dependencies = [
"ra-ap-rustc_index",
"rustc-hash 2.0.0",
Expand Down
10 changes: 5 additions & 5 deletions src/tools/rust-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ tt = { path = "./crates/tt", version = "0.0.0" }
vfs-notify = { path = "./crates/vfs-notify", version = "0.0.0" }
vfs = { path = "./crates/vfs", version = "0.0.0" }

ra-ap-rustc_lexer = { version = "0.76", default-features = false }
ra-ap-rustc_parse_format = { version = "0.76", default-features = false }
ra-ap-rustc_index = { version = "0.76", default-features = false }
ra-ap-rustc_abi = { version = "0.76", default-features = false }
ra-ap-rustc_pattern_analysis = { version = "0.76", default-features = false }
ra-ap-rustc_lexer = { version = "0.80", default-features = false }
ra-ap-rustc_parse_format = { version = "0.80", default-features = false }
ra-ap-rustc_index = { version = "0.80", default-features = false }
ra-ap-rustc_abi = { version = "0.80", default-features = false }
ra-ap-rustc_pattern_analysis = { version = "0.80", default-features = false }

# local crates that aren't published to crates.io. These should not have versions.
test-fixture = { path = "./crates/test-fixture" }
Expand Down
36 changes: 26 additions & 10 deletions src/tools/rust-analyzer/crates/hir-ty/src/infer/unify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,32 @@ impl<'a> InferenceTable<'a> {

/// Check if given type is `Sized` or not
pub(crate) fn is_sized(&mut self, ty: &Ty) -> bool {
let mut ty = ty.clone();
{
let mut structs = SmallVec::<[_; 8]>::new();
// Must use a loop here and not recursion because otherwise users will conduct completely
// artificial examples of structs that have themselves as the tail field and complain r-a crashes.
while let Some((AdtId::StructId(id), subst)) = ty.as_adt() {
let struct_data = self.db.struct_data(id);
if let Some((last_field, _)) = struct_data.variant_data.fields().iter().next_back()
{
let last_field_ty = self.db.field_types(id.into())[last_field]
.clone()
.substitute(Interner, subst);
if structs.contains(&ty) {
// A struct recursively contains itself as a tail field somewhere.
return true; // Don't overload the users with too many errors.
}
structs.push(ty);
// Structs can have DST as its last field and such cases are not handled
// as unsized by the chalk, so we do this manually.
ty = last_field_ty;
} else {
break;
};
}
}

// Early return for some obvious types
if matches!(
ty.kind(Interner),
Expand All @@ -930,16 +956,6 @@ impl<'a> InferenceTable<'a> {
return true;
}

if let Some((AdtId::StructId(id), subst)) = ty.as_adt() {
let struct_data = self.db.struct_data(id);
if let Some((last_field, _)) = struct_data.variant_data.fields().iter().last() {
let last_field_ty =
self.db.field_types(id.into())[last_field].clone().substitute(Interner, subst);
// Structs can have DST as its last field and such cases are not handled
// as unsized by the chalk, so we do this manually
return self.is_sized(&last_field_ty);
}
}
let Some(sized) = self
.db
.lang_item(self.trait_env.krate, LangItem::Sized)
Expand Down
21 changes: 21 additions & 0 deletions src/tools/rust-analyzer/crates/hir-ty/src/tests/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4790,3 +4790,24 @@ fn allowed3(baz: impl Baz<Assoc = Qux<impl Foo>>) {}
"#]],
)
}

#[test]
fn recursive_tail_sized() {
check_infer(
r#"
struct WeirdFoo(WeirdBar);
struct WeirdBar(WeirdFoo);

fn bar(v: *const ()) {
let _ = v as *const WeirdFoo;
}
"#,
expect![[r#"
62..63 'v': *const ()
76..113 '{ ...Foo; }': ()
86..87 '_': *const WeirdFoo
90..91 'v': *const ()
90..110 'v as *...irdFoo': *const WeirdFoo
"#]],
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ impl<'a> AssistContext<'a> {
pub(crate) fn find_node_at_offset<N: AstNode>(&self) -> Option<N> {
find_node_at_offset(self.source_file.syntax(), self.offset())
}
pub(crate) fn find_node_at_trimmed_offset<N: AstNode>(&self) -> Option<N> {
find_node_at_offset(self.source_file.syntax(), self.trimmed_range.start())
}
pub(crate) fn find_node_at_range<N: AstNode>(&self) -> Option<N> {
find_node_at_range(self.source_file.syntax(), self.trimmed_range)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use syntax::{
ast::{self, edit::AstNodeEdit, make},
ast::{self, edit_in_place::Indent, syntax_factory::SyntaxFactory},
AstNode,
};

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

builder.replace(expr.syntax().text_range(), block_expr.syntax().text());
let block_expr = make.block_expr(None, Some(expr.clone()));
block_expr.indent(expr.indent_level());

editor.replace(expr.syntax(), block_expr.syntax());

editor.add_mappings(make.finish_with_mappings());
builder.add_file_edits(ctx.file_id(), editor);
},
)
}
Expand Down
Loading
Loading