Skip to content

Commit 0e2dac8

Browse files
committed
Auto merge of #118592 - lnicola:sync-from-ra, r=lnicola
Subtree update of `rust-analyzer` r? `@ghost`
2 parents e281163 + 638ba5a commit 0e2dac8

File tree

34 files changed

+821
-170
lines changed

34 files changed

+821
-170
lines changed

Diff for: src/tools/rust-analyzer/Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -2000,9 +2000,9 @@ dependencies = [
20002000

20012001
[[package]]
20022002
name = "triomphe"
2003-
version = "0.1.8"
2003+
version = "0.1.10"
20042004
source = "registry+https://github.com/rust-lang/crates.io-index"
2005-
checksum = "f1ee9bd9239c339d714d657fac840c6d2a4f9c45f4f9ec7b0975113458be78db"
2005+
checksum = "d0c5a71827ac326072b6405552093e2ad2accd25a32fd78d4edc82d98c7f2409"
20062006

20072007
[[package]]
20082008
name = "tt"

Diff for: src/tools/rust-analyzer/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ text-size = "1.1.1"
116116
rayon = "1.8.0"
117117
serde = { version = "1.0.192", features = ["derive"] }
118118
serde_json = "1.0.108"
119-
triomphe = { version = "0.1.8", default-features = false, features = ["std"] }
119+
triomphe = { version = "0.1.10", default-features = false, features = ["std"] }
120120
# can't upgrade due to dashmap depending on 0.12.3 currently
121121
hashbrown = { version = "0.12.3", features = [
122122
"inline-more",

Diff for: src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs

+28-26
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ mod tests;
3838
use std::{
3939
fmt::{self, Debug},
4040
hash::{Hash, Hasher},
41-
marker::PhantomData,
4241
ops::Index,
4342
};
4443

@@ -340,34 +339,37 @@ pub trait ItemTreeNode: Clone {
340339
fn id_to_mod_item(id: FileItemTreeId<Self>) -> ModItem;
341340
}
342341

343-
pub struct FileItemTreeId<N: ItemTreeNode> {
344-
index: Idx<N>,
345-
_p: PhantomData<N>,
342+
pub struct FileItemTreeId<N: ItemTreeNode>(Idx<N>);
343+
344+
impl<N: ItemTreeNode> FileItemTreeId<N> {
345+
pub fn index(&self) -> Idx<N> {
346+
self.0
347+
}
346348
}
347349

348350
impl<N: ItemTreeNode> Clone for FileItemTreeId<N> {
349351
fn clone(&self) -> Self {
350-
Self { index: self.index, _p: PhantomData }
352+
Self(self.0)
351353
}
352354
}
353355
impl<N: ItemTreeNode> Copy for FileItemTreeId<N> {}
354356

355357
impl<N: ItemTreeNode> PartialEq for FileItemTreeId<N> {
356358
fn eq(&self, other: &FileItemTreeId<N>) -> bool {
357-
self.index == other.index
359+
self.0 == other.0
358360
}
359361
}
360362
impl<N: ItemTreeNode> Eq for FileItemTreeId<N> {}
361363

362364
impl<N: ItemTreeNode> Hash for FileItemTreeId<N> {
363365
fn hash<H: Hasher>(&self, state: &mut H) {
364-
self.index.hash(state)
366+
self.0.hash(state)
365367
}
366368
}
367369

368370
impl<N: ItemTreeNode> fmt::Debug for FileItemTreeId<N> {
369371
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
370-
self.index.fmt(f)
372+
self.0.fmt(f)
371373
}
372374
}
373375

@@ -548,7 +550,7 @@ impl Index<RawVisibilityId> for ItemTree {
548550
impl<N: ItemTreeNode> Index<FileItemTreeId<N>> for ItemTree {
549551
type Output = N;
550552
fn index(&self, id: FileItemTreeId<N>) -> &N {
551-
N::lookup(self, id.index)
553+
N::lookup(self, id.index())
552554
}
553555
}
554556

@@ -925,23 +927,23 @@ impl ModItem {
925927

926928
pub fn ast_id(&self, tree: &ItemTree) -> FileAstId<ast::Item> {
927929
match self {
928-
ModItem::Use(it) => tree[it.index].ast_id().upcast(),
929-
ModItem::ExternCrate(it) => tree[it.index].ast_id().upcast(),
930-
ModItem::ExternBlock(it) => tree[it.index].ast_id().upcast(),
931-
ModItem::Function(it) => tree[it.index].ast_id().upcast(),
932-
ModItem::Struct(it) => tree[it.index].ast_id().upcast(),
933-
ModItem::Union(it) => tree[it.index].ast_id().upcast(),
934-
ModItem::Enum(it) => tree[it.index].ast_id().upcast(),
935-
ModItem::Const(it) => tree[it.index].ast_id().upcast(),
936-
ModItem::Static(it) => tree[it.index].ast_id().upcast(),
937-
ModItem::Trait(it) => tree[it.index].ast_id().upcast(),
938-
ModItem::TraitAlias(it) => tree[it.index].ast_id().upcast(),
939-
ModItem::Impl(it) => tree[it.index].ast_id().upcast(),
940-
ModItem::TypeAlias(it) => tree[it.index].ast_id().upcast(),
941-
ModItem::Mod(it) => tree[it.index].ast_id().upcast(),
942-
ModItem::MacroCall(it) => tree[it.index].ast_id().upcast(),
943-
ModItem::MacroRules(it) => tree[it.index].ast_id().upcast(),
944-
ModItem::MacroDef(it) => tree[it.index].ast_id().upcast(),
930+
ModItem::Use(it) => tree[it.index()].ast_id().upcast(),
931+
ModItem::ExternCrate(it) => tree[it.index()].ast_id().upcast(),
932+
ModItem::ExternBlock(it) => tree[it.index()].ast_id().upcast(),
933+
ModItem::Function(it) => tree[it.index()].ast_id().upcast(),
934+
ModItem::Struct(it) => tree[it.index()].ast_id().upcast(),
935+
ModItem::Union(it) => tree[it.index()].ast_id().upcast(),
936+
ModItem::Enum(it) => tree[it.index()].ast_id().upcast(),
937+
ModItem::Const(it) => tree[it.index()].ast_id().upcast(),
938+
ModItem::Static(it) => tree[it.index()].ast_id().upcast(),
939+
ModItem::Trait(it) => tree[it.index()].ast_id().upcast(),
940+
ModItem::TraitAlias(it) => tree[it.index()].ast_id().upcast(),
941+
ModItem::Impl(it) => tree[it.index()].ast_id().upcast(),
942+
ModItem::TypeAlias(it) => tree[it.index()].ast_id().upcast(),
943+
ModItem::Mod(it) => tree[it.index()].ast_id().upcast(),
944+
ModItem::MacroCall(it) => tree[it.index()].ast_id().upcast(),
945+
ModItem::MacroRules(it) => tree[it.index()].ast_id().upcast(),
946+
ModItem::MacroDef(it) => tree[it.index()].ast_id().upcast(),
945947
}
946948
}
947949
}

Diff for: src/tools/rust-analyzer/crates/hir-def/src/item_tree/lower.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{
1313
use super::*;
1414

1515
fn id<N: ItemTreeNode>(index: Idx<N>) -> FileItemTreeId<N> {
16-
FileItemTreeId { index, _p: PhantomData }
16+
FileItemTreeId(index)
1717
}
1818

1919
pub(super) struct Ctx<'a> {

Diff for: src/tools/rust-analyzer/crates/hir-ty/src/infer.rs

+8-13
Original file line numberDiff line numberDiff line change
@@ -1152,20 +1152,15 @@ impl<'a> InferenceContext<'a> {
11521152
(ty, variant)
11531153
}
11541154
TypeNs::TypeAliasId(it) => {
1155-
let container = it.lookup(self.db.upcast()).container;
1156-
let parent_subst = match container {
1157-
ItemContainerId::TraitId(id) => {
1158-
let subst = TyBuilder::subst_for_def(self.db, id, None)
1159-
.fill_with_inference_vars(&mut self.table)
1160-
.build();
1161-
Some(subst)
1162-
}
1163-
// Type aliases do not exist in impls.
1164-
_ => None,
1155+
let resolved_seg = match unresolved {
1156+
None => path.segments().last().unwrap(),
1157+
Some(n) => path.segments().get(path.segments().len() - n - 1).unwrap(),
11651158
};
1166-
let ty = TyBuilder::def_ty(self.db, it.into(), parent_subst)
1167-
.fill_with_inference_vars(&mut self.table)
1168-
.build();
1159+
let substs =
1160+
ctx.substs_from_path_segment(resolved_seg, Some(it.into()), true, None);
1161+
let ty = self.db.ty(it.into());
1162+
let ty = self.insert_type_vars(ty.substitute(Interner, &substs));
1163+
11691164
self.resolve_variant_on_alias(ty, unresolved, mod_path)
11701165
}
11711166
TypeNs::AdtSelfType(_) => {

Diff for: src/tools/rust-analyzer/crates/hir-ty/src/lower.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ impl<'a> TyLoweringContext<'a> {
768768
}
769769
}
770770

771-
fn substs_from_path_segment(
771+
pub(super) fn substs_from_path_segment(
772772
&self,
773773
segment: PathSegment<'_>,
774774
def: Option<GenericDefId>,

Diff for: src/tools/rust-analyzer/crates/hir-ty/src/mir.rs

+14
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,10 @@ impl ProjectionStore {
269269
impl ProjectionId {
270270
pub const EMPTY: ProjectionId = ProjectionId(0);
271271

272+
pub fn is_empty(self) -> bool {
273+
self == ProjectionId::EMPTY
274+
}
275+
272276
pub fn lookup(self, store: &ProjectionStore) -> &[PlaceElem] {
273277
store.id_to_proj.get(&self).unwrap()
274278
}
@@ -1069,6 +1073,10 @@ pub struct MirBody {
10691073
}
10701074

10711075
impl MirBody {
1076+
pub fn local_to_binding_map(&self) -> ArenaMap<LocalId, BindingId> {
1077+
self.binding_locals.iter().map(|(it, y)| (*y, it)).collect()
1078+
}
1079+
10721080
fn walk_places(&mut self, mut f: impl FnMut(&mut Place, &mut ProjectionStore)) {
10731081
fn for_operand(
10741082
op: &mut Operand,
@@ -1188,3 +1196,9 @@ pub enum MirSpan {
11881196
}
11891197

11901198
impl_from!(ExprId, PatId for MirSpan);
1199+
1200+
impl From<&ExprId> for MirSpan {
1201+
fn from(value: &ExprId) -> Self {
1202+
(*value).into()
1203+
}
1204+
}

Diff for: src/tools/rust-analyzer/crates/hir-ty/src/mir/lower.rs

+34-20
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,14 @@ pub enum MirLowerError {
105105
/// A token to ensuring that each drop scope is popped at most once, thanks to the compiler that checks moves.
106106
struct DropScopeToken;
107107
impl DropScopeToken {
108-
fn pop_and_drop(self, ctx: &mut MirLowerCtx<'_>, current: BasicBlockId) -> BasicBlockId {
108+
fn pop_and_drop(
109+
self,
110+
ctx: &mut MirLowerCtx<'_>,
111+
current: BasicBlockId,
112+
span: MirSpan,
113+
) -> BasicBlockId {
109114
std::mem::forget(self);
110-
ctx.pop_drop_scope_internal(current)
115+
ctx.pop_drop_scope_internal(current, span)
111116
}
112117

113118
/// It is useful when we want a drop scope is syntaxically closed, but we don't want to execute any drop
@@ -582,7 +587,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
582587
self.lower_loop(current, place, *label, expr_id.into(), |this, begin| {
583588
let scope = this.push_drop_scope();
584589
if let Some((_, mut current)) = this.lower_expr_as_place(begin, *body, true)? {
585-
current = scope.pop_and_drop(this, current);
590+
current = scope.pop_and_drop(this, current, body.into());
586591
this.set_goto(current, begin, expr_id.into());
587592
} else {
588593
scope.pop_assume_dropped(this);
@@ -720,7 +725,8 @@ impl<'ctx> MirLowerCtx<'ctx> {
720725
.ok_or(MirLowerError::ContinueWithoutLoop)?,
721726
};
722727
let begin = loop_data.begin;
723-
current = self.drop_until_scope(loop_data.drop_scope_index, current);
728+
current =
729+
self.drop_until_scope(loop_data.drop_scope_index, current, expr_id.into());
724730
self.set_goto(current, begin, expr_id.into());
725731
Ok(None)
726732
}
@@ -759,7 +765,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
759765
self.current_loop_blocks.as_ref().unwrap().drop_scope_index,
760766
),
761767
};
762-
current = self.drop_until_scope(drop_scope, current);
768+
current = self.drop_until_scope(drop_scope, current, expr_id.into());
763769
self.set_goto(current, end, expr_id.into());
764770
Ok(None)
765771
}
@@ -773,7 +779,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
773779
return Ok(None);
774780
}
775781
}
776-
current = self.drop_until_scope(0, current);
782+
current = self.drop_until_scope(0, current, expr_id.into());
777783
self.set_terminator(current, TerminatorKind::Return, expr_id.into());
778784
Ok(None)
779785
}
@@ -1782,7 +1788,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
17821788
return Ok(None);
17831789
};
17841790
self.push_fake_read(c, p, expr.into());
1785-
current = scope2.pop_and_drop(self, c);
1791+
current = scope2.pop_and_drop(self, c, expr.into());
17861792
}
17871793
}
17881794
}
@@ -1793,7 +1799,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
17931799
};
17941800
current = c;
17951801
}
1796-
current = scope.pop_and_drop(self, current);
1802+
current = scope.pop_and_drop(self, current, span);
17971803
Ok(Some(current))
17981804
}
17991805

@@ -1873,9 +1879,14 @@ impl<'ctx> MirLowerCtx<'ctx> {
18731879
}
18741880
}
18751881

1876-
fn drop_until_scope(&mut self, scope_index: usize, mut current: BasicBlockId) -> BasicBlockId {
1882+
fn drop_until_scope(
1883+
&mut self,
1884+
scope_index: usize,
1885+
mut current: BasicBlockId,
1886+
span: MirSpan,
1887+
) -> BasicBlockId {
18771888
for scope in self.drop_scopes[scope_index..].to_vec().iter().rev() {
1878-
self.emit_drop_and_storage_dead_for_scope(scope, &mut current);
1889+
self.emit_drop_and_storage_dead_for_scope(scope, &mut current, span);
18791890
}
18801891
current
18811892
}
@@ -1891,17 +1902,22 @@ impl<'ctx> MirLowerCtx<'ctx> {
18911902
}
18921903

18931904
/// Don't call directly
1894-
fn pop_drop_scope_internal(&mut self, mut current: BasicBlockId) -> BasicBlockId {
1905+
fn pop_drop_scope_internal(
1906+
&mut self,
1907+
mut current: BasicBlockId,
1908+
span: MirSpan,
1909+
) -> BasicBlockId {
18951910
let scope = self.drop_scopes.pop().unwrap();
1896-
self.emit_drop_and_storage_dead_for_scope(&scope, &mut current);
1911+
self.emit_drop_and_storage_dead_for_scope(&scope, &mut current, span);
18971912
current
18981913
}
18991914

19001915
fn pop_drop_scope_assert_finished(
19011916
&mut self,
19021917
mut current: BasicBlockId,
1918+
span: MirSpan,
19031919
) -> Result<BasicBlockId> {
1904-
current = self.pop_drop_scope_internal(current);
1920+
current = self.pop_drop_scope_internal(current, span);
19051921
if !self.drop_scopes.is_empty() {
19061922
implementation_error!("Mismatched count between drop scope push and pops");
19071923
}
@@ -1912,20 +1928,18 @@ impl<'ctx> MirLowerCtx<'ctx> {
19121928
&mut self,
19131929
scope: &DropScope,
19141930
current: &mut Idx<BasicBlock>,
1931+
span: MirSpan,
19151932
) {
19161933
for &l in scope.locals.iter().rev() {
19171934
if !self.result.locals[l].ty.clone().is_copy(self.db, self.owner) {
19181935
let prev = std::mem::replace(current, self.new_basic_block());
19191936
self.set_terminator(
19201937
prev,
19211938
TerminatorKind::Drop { place: l.into(), target: *current, unwind: None },
1922-
MirSpan::Unknown,
1939+
span,
19231940
);
19241941
}
1925-
self.push_statement(
1926-
*current,
1927-
StatementKind::StorageDead(l).with_span(MirSpan::Unknown),
1928-
);
1942+
self.push_statement(*current, StatementKind::StorageDead(l).with_span(span));
19291943
}
19301944
}
19311945
}
@@ -2002,7 +2016,7 @@ pub fn mir_body_for_closure_query(
20022016
|_| true,
20032017
)?;
20042018
if let Some(current) = ctx.lower_expr_to_place(*root, return_slot().into(), current)? {
2005-
let current = ctx.pop_drop_scope_assert_finished(current)?;
2019+
let current = ctx.pop_drop_scope_assert_finished(current, root.into())?;
20062020
ctx.set_terminator(current, TerminatorKind::Return, (*root).into());
20072021
}
20082022
let mut upvar_map: FxHashMap<LocalId, Vec<(&CapturedItem, usize)>> = FxHashMap::default();
@@ -2146,7 +2160,7 @@ pub fn lower_to_mir(
21462160
ctx.lower_params_and_bindings([].into_iter(), binding_picker)?
21472161
};
21482162
if let Some(current) = ctx.lower_expr_to_place(root_expr, return_slot().into(), current)? {
2149-
let current = ctx.pop_drop_scope_assert_finished(current)?;
2163+
let current = ctx.pop_drop_scope_assert_finished(current, root_expr.into())?;
21502164
ctx.set_terminator(current, TerminatorKind::Return, root_expr.into());
21512165
}
21522166
Ok(ctx.result)

Diff for: src/tools/rust-analyzer/crates/hir-ty/src/mir/pretty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl<'a> MirPrettyCtx<'a> {
145145
let indent = mem::take(&mut self.indent);
146146
let mut ctx = MirPrettyCtx {
147147
body: &body,
148-
local_to_binding: body.binding_locals.iter().map(|(it, y)| (*y, it)).collect(),
148+
local_to_binding: body.local_to_binding_map(),
149149
result,
150150
indent,
151151
..*self
@@ -167,7 +167,7 @@ impl<'a> MirPrettyCtx<'a> {
167167
}
168168

169169
fn new(body: &'a MirBody, hir_body: &'a Body, db: &'a dyn HirDatabase) -> Self {
170-
let local_to_binding = body.binding_locals.iter().map(|(it, y)| (*y, it)).collect();
170+
let local_to_binding = body.local_to_binding_map();
171171
MirPrettyCtx {
172172
body,
173173
db,

0 commit comments

Comments
 (0)