Skip to content

Commit 8a5d4a3

Browse files
committed
Auto merge of #133564 - lnicola:sync-from-ra, r=lnicola
Subtree update of `rust-analyzer` r? `@ghost`
2 parents 7e5d40a + 6db5e96 commit 8a5d4a3

25 files changed

+477
-211
lines changed

Cargo.lock

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 5 deletions
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" }

crates/hir-ty/src/infer/unify.rs

Lines changed: 26 additions & 10 deletions
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)

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

Lines changed: 21 additions & 0 deletions
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+
}

crates/ide-assists/src/assist_context.rs

Lines changed: 3 additions & 0 deletions
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
}

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

Lines changed: 10 additions & 6 deletions
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)