Skip to content

Commit

Permalink
Auto merge of rust-lang#133564 - lnicola:sync-from-ra, r=lnicola
Browse files Browse the repository at this point in the history
Subtree update of `rust-analyzer`

r? `@ghost`
  • Loading branch information
bors committed Nov 28, 2024
2 parents f005c74 + 15e8a26 commit c1cfab2
Show file tree
Hide file tree
Showing 25 changed files with 477 additions and 211 deletions.
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

0 comments on commit c1cfab2

Please sign in to comment.